Module: Pegparse::BiopRuleChain
- Includes:
- ParserCore
- Included in:
- BiopRuleChainImitation
- Defined in:
- lib/pegparse/biop_rule_chain.rb
Overview
Binary operator rule helper.
Class Method Summary collapse
-
.based_on(parser_class, &exec_block) ⇒ Class<Pegparse::BiopRuleChainImitation>
Create new parser class derived from passed one.
Instance Method Summary collapse
-
#construct_result(lhs, op, rhs) ⇒ Object
Default construction of matching result.
- #initialize(scanner_or_context) ⇒ Object
-
#left_op(operator_matcher) ⇒ Pegparse::BiopRuleChainImitation
Add left-associative binary operators.
-
#operand_sp ⇒ Object
Default matching rule of spaces before operand.
-
#operator_sp ⇒ Object
Default matching rule of spaces before operator.
-
#term(term_block) ⇒ Object
Set terminal matching rule.
Class Method Details
.based_on(parser_class, &exec_block) ⇒ Class<Pegparse::BiopRuleChainImitation>
Create new parser class derived from passed one. If you want to customize parser behavior, override method in exec_block.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/pegparse/biop_rule_chain.rb', line 10 def self.based_on(parser_class, &exec_block) raise ArgumentError unless parser_class.ancestors.include?(Pegparse::ParserBase) klass = Class.new(parser_class) do include Pegparse::BiopRuleChain end klass.class_exec(&exec_block) if exec_block klass end |
Instance Method Details
#construct_result(lhs, op, rhs) ⇒ Object
Default construction of matching result. (override this if you want)
29 30 31 |
# File 'lib/pegparse/biop_rule_chain.rb', line 29 def construct_result(lhs, op, rhs) [op, lhs, rhs] end |
#initialize(scanner_or_context) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/pegparse/biop_rule_chain.rb', line 21 def initialize(scanner_or_context) super(scanner_or_context) @start_rule_symbol = :start_rule @operators = [] @term = nil end |
#left_op(operator_matcher) ⇒ Pegparse::BiopRuleChainImitation
Add left-associative binary operators. Call in order of operators precedence. If you have multiple operators in same precedence, pass Array as parameter.
71 72 73 74 |
# File 'lib/pegparse/biop_rule_chain.rb', line 71 def left_op(operator_matcher) @operators << get_operator_matcher(operator_matcher) self end |
#operand_sp ⇒ Object
Default matching rule of spaces before operand. (override this if you want)
40 41 42 |
# File 'lib/pegparse/biop_rule_chain.rb', line 40 def operand_sp sp() end |
#operator_sp ⇒ Object
Default matching rule of spaces before operator. (override this if you want) This rule will be used when you pass string to #left_op.
35 36 37 |
# File 'lib/pegparse/biop_rule_chain.rb', line 35 def operator_sp sp() end |
#term(term_block) ⇒ Object
Set terminal matching rule.
78 79 80 81 |
# File 'lib/pegparse/biop_rule_chain.rb', line 78 def term(term_block) @term = term_block nil end |