Class: Ibex::Frontend::TokenAdapter
- Inherits:
-
Object
- Object
- Ibex::Frontend::TokenAdapter
show all
- Defined in:
- lib/ibex/frontend/token_adapter.rb,
lib/ibex/frontend/token_adapter/rule_state.rb,
lib/ibex/frontend/token_adapter/declaration_state.rb,
lib/ibex/frontend/token_adapter/delimiter_tracker.rb,
lib/ibex/frontend/token_adapter/declaration_lexer_state.rb,
lib/ibex/frontend/token_adapter/declaration_document_state.rb,
sig/ibex/frontend/token_adapter.rbs,
sig/ibex/frontend/token_adapter/rule_state.rbs,
sig/ibex/frontend/token_adapter/declaration_state.rbs,
sig/ibex/frontend/token_adapter/delimiter_tracker.rbs,
sig/ibex/frontend/token_adapter/declaration_lexer_state.rbs,
sig/ibex/frontend/token_adapter/declaration_document_state.rbs
Overview
Delivers lexer tokens through declaration and rule context classifiers.
Defined Under Namespace
Modules: DeclarationDocumentState, DeclarationLexerState
Classes: DeclarationState, DelimiterTracker, RuleState
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(tokens, extended: false) ⇒ TokenAdapter
Returns a new instance of TokenAdapter.
19
20
21
22
23
24
|
# File 'lib/ibex/frontend/token_adapter.rb', line 19
def initialize(tokens, extended: false)
@tokens = tokens
@index = 0
@declarations = DeclarationState.new(extended: extended)
@classifier = @declarations
end
|
Instance Attribute Details
#eof_token ⇒ Token?
7
8
9
|
# File 'lib/ibex/frontend/token_adapter.rb', line 7
def eof_token
@eof_token
end
|
#last_token ⇒ Token?
8
9
10
|
# File 'lib/ibex/frontend/token_adapter.rb', line 8
def last_token
@last_token
end
|
#previous_external ⇒ external_token?
9
10
11
|
# File 'lib/ibex/frontend/token_adapter.rb', line 9
def previous_external
@previous_external
end
|
Instance Method Details
#classify(token) ⇒ external_token
97
98
99
100
101
102
103
104
|
# File 'lib/ibex/frontend/token_adapter.rb', line 97
def classify(token)
remaining = @tokens.drop(@index)
rules = @rules
return @declarations.classify(token, remaining) unless rules
rules.classify(token, remaining, last_external: @last_external,
previous_external: @previous_external)
end
|
#conversion_name ⇒ Token?
44
45
46
|
# File 'lib/ibex/frontend/token_adapter.rb', line 44
def conversion_name
@declarations.conversion_name
end
|
#cst_pragma? ⇒ Boolean
64
65
66
|
# File 'lib/ibex/frontend/token_adapter.rb', line 64
def cst_pragma?
@declarations.cst_pragma?
end
|
#declaration ⇒ Symbol?
49
50
51
|
# File 'lib/ibex/frontend/token_adapter.rb', line 49
def declaration
@declarations.declaration
end
|
#enter_rules ⇒ void
This method returns an undefined value.
107
108
109
110
|
# File 'lib/ibex/frontend/token_adapter.rb', line 107
def enter_rules
@rules = RuleState.new
@classifier = @rules
end
|
#expectation(token) ⇒ String?
90
91
92
|
# File 'lib/ibex/frontend/token_adapter.rb', line 90
def expectation(token)
@classifier.expectation(token)
end
|
#extended_pragma? ⇒ Boolean
59
60
61
|
# File 'lib/ibex/frontend/token_adapter.rb', line 59
def extended_pragma?
@declarations.extended_pragma?
end
|
#group_opening ⇒ Token?
80
81
82
|
# File 'lib/ibex/frontend/token_adapter.rb', line 80
def group_opening
@rules&.group_opening
end
|
#next_token ⇒ [ external_token, Token ], false
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/ibex/frontend/token_adapter.rb', line 27
def next_token
token = @tokens.fetch(@index)
@index += 1
@last_token = token
if token.type == :eof
@eof_token = token
return false
end
external = classify(token)
enter_rules if @classifier == @declarations && @declarations.rules?
@previous_external = @last_external
@last_external = external
[external, token]
end
|
#open_delimiter_kind ⇒ delimiter_kind?
85
86
87
|
# File 'lib/ibex/frontend/token_adapter.rb', line 85
def open_delimiter_kind
@rules&.open_delimiter_kind
end
|
#precedence_closer ⇒ String?
54
55
56
|
# File 'lib/ibex/frontend/token_adapter.rb', line 54
def precedence_closer
@declarations.precedence_closer
end
|
#section ⇒ parser_section
69
70
71
72
|
# File 'lib/ibex/frontend/token_adapter.rb', line 69
def section
rules = @rules
rules ? rules.section : :declarations
end
|
#state ⇒ Symbol
75
76
77
|
# File 'lib/ibex/frontend/token_adapter.rb', line 75
def state
@classifier.state
end
|