Sha256: 90649c688b25fa5ed11a85d94c71cb0207d63351ee45fa4adfd06188efe13383
Contents?: true
Size: 1.58 KB
Versions: 3
Compression:
Stored size: 1.58 KB
Contents
module Treetop module Compiler class Repetition < ParsingExpression def compile(address, builder, parent_expression) super repeated_expression = parent_expression.atomic begin_comment(parent_expression) use_vars :result, :accumulator, :nested_results, :start_index builder.loop do obtain_new_subexpression_address repeated_expression.compile(subexpression_address, builder) accumulate_nested_result builder.if__ subexpression_success? do accumulate_subexpression_result end builder.else_ do builder.break end end end def inline_module_name parent_expression.inline_module_name end def assign_and_extend_result assign_result "#{node_class}.new(input, #{start_index_var}...index, #{accumulator_var}, #{nested_results_var})" builder << "#{result_var}.extend(#{inline_module_name})" if inline_module_name end end class ZeroOrMore < Repetition def compile(address, builder, parent_expression) super assign_and_extend_result end_comment(parent_expression) end end class OneOrMore < Repetition def compile(address, builder, parent_expression) super builder.if__ "#{accumulator_var}.empty?" do reset_index assign_failure start_index_var, nested_results_var end builder.else_ do assign_and_extend_result end end_comment(parent_expression) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
treetop-1.0.0 | lib/treetop/compiler/node_classes/repetition.rb |
treetop-1.0.1 | lib/treetop/compiler/node_classes/repetition.rb |
treetop-1.0.2 | lib/treetop/compiler/node_classes/repetition.rb |