Class: Electr::ExpressionRule
- Defined in:
- lib/electr/parser/rules/expression_rule.rb
Overview
Rules an Electr expression.
TODO For now almost everything is an expression in Electr, so this is a somewhat complicated class. It should be refactored a lot.
Instance Method Summary collapse
Methods inherited from BaseRule
Constructor Details
This class inherits a constructor from Electr::BaseRule
Instance Method Details
#apply ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/electr/parser/rules/expression_rule.rb', line 9 def apply while @units.size > 0 if first_unit_fname? accept(:fname) accept(:open_parenthesis, '(') while @units.first && (not @units.first.closed_parenthesis?) accept(@units.first.type) end accept(:closed_parenthesis, ')') else accept(@units.first.type) end end sya = Sya.new(@series.dup) @series = sya.run if number? dig_series(@ast_node) else unit = @series.shift # If we want to handle = differently than other operators, we # can do something like the following: # node_class = unit.assign? ? AssignAST : OperatorAST # node = node_class.new(unit.value) node = OperatorAST.new(unit.value) dig_series(node) while @series.size > 0 @ast_node.add_child(node) end end |