Class: Treetop::Compiler::CharacterClass
- Inherits:
-
AtomicExpression
- Object
- Runtime::SyntaxNode
- ParsingExpression
- AtomicExpression
- Treetop::Compiler::CharacterClass
- Defined in:
- lib/treetop/compiler/node_classes/character_class.rb
Instance Attribute Summary
Attributes inherited from ParsingExpression
#address, #builder, #parent_expression, #subexpression_address, #var_symbols
Attributes inherited from Runtime::SyntaxNode
#elements, #input, #interval, #parent
Instance Method Summary collapse
Methods inherited from AtomicExpression
#inline_modules, #single_quote
Methods inherited from ParsingExpression
#accumulate_subexpression_result, #accumulator_var, #assign_failure, #assign_result, #begin_comment, #declared_module_name, #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
#empty?, #extension_modules, #initialize, #inspect, #nonterminal?, #terminal?, #text_value
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 |
# File 'lib/treetop/compiler/node_classes/character_class.rb', line 4 def compile(address, builder, parent_expression = nil) super builder.if__ "has_terminal?(#{grounded_regexp(text_value)}, true, index)" do assign_result "instantiate_node(#{node_class_name},input, index...(index + 1))" extend_result_with_inline_module builder << "@index += 1" end builder.else_ do "terminal_parse_failure(#{single_quote(characters)})" assign_result 'nil' end end |
#grounded_regexp(string) ⇒ Object
18 19 20 21 |
# File 'lib/treetop/compiler/node_classes/character_class.rb', line 18 def grounded_regexp(string) # Double any backslashes, then backslash any single-quotes: "'\\G#{string.gsub(/\\/) { '\\\\' }.gsub(/'/) { "\\'"}}'" end |