Class: Treetop::Compiler::Terminal
- Inherits:
-
AtomicExpression
- Object
- Runtime::SyntaxNode
- ParsingExpression
- AtomicExpression
- Treetop::Compiler::Terminal
- Defined in:
- lib/treetop/compiler/node_classes/terminal.rb
Instance Attribute Summary
Attributes inherited from ParsingExpression
#address, #builder, #parent_expression, #subexpression_address, #var_symbols
Attributes inherited from Runtime::SyntaxNode
Instance Method Summary collapse
Methods inherited from AtomicExpression
#inline_modules, #single_quote
Methods inherited from ParsingExpression
#accumulate_subexpression_result, #accumulator_var, #assign_failure, #assign_lazily_instantiated_node, #assign_result, #begin_comment, #declared_module_name, #decorated?, #end_comment, #epsilon_node, #extend_result, #extend_result_with_declared_module, #extend_result_with_inline_module, #init_value, #inline_module_name, #node_class_name, #obtain_new_subexpression_address, #on_one_line, #optional_arg, #reset_index, #result_var, #start_index_var, #subexpression_result_var, #subexpression_success?, #use_vars, #var, #var_initialization
Methods inherited from Runtime::SyntaxNode
#<=>, #dot_id, #elements, #empty?, #extension_modules, #initialize, #inspect, #nonterminal?, #terminal?, #text_value, #write_dot, #write_dot_file
Constructor Details
This class inherits a constructor from Treetop::Runtime::SyntaxNode
Instance Method Details
#compile(address, builder, parent_expression = nil) ⇒ Object
4 5 6 7 8 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/treetop/compiler/node_classes/terminal.rb', line 4 def compile(address, builder, parent_expression = nil) super # Handle modifiers: insensitive = modifiers.text_value.include? 'i' re = modifiers.text_value.include? 'r' if re grounded_regexp = "#{('\A'+eval(string)).inspect}" cache_key = "'__#{modifiers.text_value}__'+(gr = #{grounded_regexp})" re_modifiers = "#{insensitive ? 'Regexp::IGNORECASE' : 0}" str = "@regexps[#{cache_key}] ||= Regexp.new(gr, #{re_modifiers})" mode = ':regexp' elsif insensitive str = string.downcase string_length = eval(str).length mode = ':insens' else str = string string_length = eval(str).length mode = 'false' end builder.if__ "(match_len = has_terminal?(#{str}, #{mode}, index))" do if address == 0 || decorated? || mode != 'false' || string_length > 1 assign_result "instantiate_node(#{node_class_name},input, index...(index + match_len))" extend_result_with_inline_module else assign_lazily_instantiated_node end builder << "@index += match_len" end builder.else_ do builder << "terminal_parse_failure(#{string})" assign_result 'nil' end end |