Class: Ibex::Frontend::DSL::RuleBuilder
- Inherits:
-
Object
- Object
- Ibex::Frontend::DSL::RuleBuilder
- Defined in:
- lib/ibex/frontend/dsl.rb,
sig/ibex/frontend/dsl.rbs
Overview
Collects alternatives for one nonterminal.
Instance Attribute Summary collapse
Instance Method Summary collapse
- #alt(*items, action: nil, precedence: nil, node: nil) ⇒ void
-
#initialize(grammar, default_location) ⇒ RuleBuilder
constructor
A new instance of RuleBuilder.
Constructor Details
#initialize(grammar, default_location) ⇒ RuleBuilder
Returns a new instance of RuleBuilder.
235 236 237 238 239 |
# File 'lib/ibex/frontend/dsl.rb', line 235 def initialize(grammar, default_location) @grammar = grammar @default_location = default_location @alternatives = [] #: Array[AST::Alternative] end |
Instance Attribute Details
#alternatives ⇒ Array[AST::Alternative] (readonly)
229 230 231 |
# File 'lib/ibex/frontend/dsl.rb', line 229 def alternatives @alternatives end |
Instance Method Details
#alt(*items, action: nil, precedence: nil, node: nil) ⇒ void
This method returns an undefined value.
242 243 244 245 246 247 248 249 250 251 |
# File 'lib/ibex/frontend/dsl.rb', line 242 def alt(*items, action: nil, precedence: nil, node: nil) location = @grammar.next_location || @default_location normalized = items.map { |item| @grammar.normalize_item(item) } action_node = action && AST::InlineAction.new(code: action.to_s, loc: location) alternative = AST::Alternative.new( items: normalized, action: action_node, precedence: precedence&.to_s, node_annotation: node, loc: location ) @alternatives << alternative end |