Class: Ibex::Frontend::TokenAdapter::RuleState
- Inherits:
-
Object
- Object
- Ibex::Frontend::TokenAdapter::RuleState
- Defined in:
- lib/ibex/frontend/token_adapter/rule_state.rb
Overview
Classifies context-dependent tokens in the grammar rule section.
Constant Summary collapse
- SCALAR_TYPES =
{ literal: :LITERAL, integer: :INTEGER, action: :ACTION, user_code: :USER_CODE }.freeze
Instance Attribute Summary collapse
-
#section ⇒ Object
readonly
: Hash[Symbol, external_token].
-
#state ⇒ Object
readonly
: Symbol.
Instance Method Summary collapse
- #classify(token, remaining, last_external:, previous_external:) ⇒ Object
- #expectation(token) ⇒ Object
- #group_opening ⇒ Object
-
#initialize ⇒ RuleState
constructor
A new instance of RuleState.
- #open_delimiter_kind ⇒ Object
Constructor Details
#initialize ⇒ RuleState
Returns a new instance of RuleState.
21 22 23 24 25 |
# File 'lib/ibex/frontend/token_adapter/rule_state.rb', line 21 def initialize @state = :rules_lhs @section = :rules @delimiters = DelimiterTracker.new end |
Instance Attribute Details
#section ⇒ Object (readonly)
: Hash[Symbol, external_token]
12 13 14 |
# File 'lib/ibex/frontend/token_adapter/rule_state.rb', line 12 def section @section end |
#state ⇒ Object (readonly)
: Symbol
13 14 15 |
# File 'lib/ibex/frontend/token_adapter/rule_state.rb', line 13 def state @state end |
Instance Method Details
#classify(token, remaining, last_external:, previous_external:) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ibex/frontend/token_adapter/rule_state.rb', line 29 def classify(token, remaining, last_external:, previous_external:) external = if token.type == :identifier classify_identifier(token, remaining, last_external, previous_external) elsif token.type == :node @node_annotation = true :NODE elsif token.type == :inline classify_inline elsif token.type == :empty :EMPTY elsif SCALAR_TYPES.key?(token.type) SCALAR_TYPES.fetch(token.type) else classify_punctuation(token) end @delimiters.observe(token, external, last_external) @node_annotation = false if token.type == :")" && @node_annotation external end |
#expectation(token) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/ibex/frontend/token_adapter/rule_state.rb', line 60 def expectation(token) if @state == :rules_lhs && @section == :rules rules_lhs_expectation(token) elsif @state == :rule_colon ":" elsif @state == :rule_rhs && %w[) ,].include?(token&.value) "a grammar symbol" end end |
#group_opening ⇒ Object
50 51 52 |
# File 'lib/ibex/frontend/token_adapter/rule_state.rb', line 50 def group_opening @delimiters.group_opening end |
#open_delimiter_kind ⇒ Object
55 56 57 |
# File 'lib/ibex/frontend/token_adapter/rule_state.rb', line 55 def open_delimiter_kind @delimiters.open_kind end |