rattler 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +3 -175
- data/features/README.markdown +27 -0
- data/features/Tutorial.md +224 -0
- data/features/command_line/output_option.feature +2 -1
- data/features/command_line/{parser_generator.feature → rtlr.feature} +43 -15
- data/features/error_reporting/automatic_error_messages.feature +40 -0
- data/features/error_reporting/custom_error_messages.feature +28 -0
- data/features/examples/json_parser.markdown +88 -0
- data/features/{grammar → extended_matching_syntax}/back_reference.feature +5 -3
- data/features/{grammar → extended_matching_syntax}/e_symbol.feature +2 -2
- data/features/{grammar → extended_matching_syntax}/eof.feature +4 -3
- data/features/{grammar → extended_matching_syntax}/fail.feature +8 -6
- data/features/extended_matching_syntax/fragments.feature +29 -0
- data/features/extended_matching_syntax/include.feature +42 -0
- data/features/{grammar → extended_matching_syntax}/list_matching.feature +7 -6
- data/features/extended_matching_syntax/posix_class.feature +127 -0
- data/features/{grammar → extended_matching_syntax}/repeat.feature +29 -3
- data/features/{grammar → extended_matching_syntax}/skip_operator.feature +2 -1
- data/features/extended_matching_syntax/super.feature +24 -0
- data/features/{grammar → extended_matching_syntax}/token.feature +6 -5
- data/features/{grammar → extended_matching_syntax}/whitespace.feature +7 -6
- data/features/{grammar → extended_matching_syntax}/word_literal.feature +10 -6
- data/features/grammar_heading/explicit_start_rule.feature +20 -0
- data/features/grammar_heading/grammar_declaration.feature +60 -0
- data/features/grammar_heading/include.feature +19 -0
- data/features/grammar_heading/require.feature +27 -0
- data/features/{grammar → peg_syntax}/any_character.feature +1 -1
- data/features/peg_syntax/character_class.feature +25 -0
- data/features/{grammar → peg_syntax}/comments.feature +1 -1
- data/features/{grammar → peg_syntax}/literal.feature +5 -3
- data/features/{grammar → peg_syntax}/negative_lookahead.feature +5 -3
- data/features/peg_syntax/nonterminal.feature +46 -0
- data/features/peg_syntax/one_or_more.feature +59 -0
- data/features/{grammar → peg_syntax}/optional.feature +2 -2
- data/features/peg_syntax/ordered_choice.feature +24 -0
- data/features/{grammar → peg_syntax}/positive_lookahead.feature +6 -4
- data/features/peg_syntax/sequence.feature +23 -0
- data/features/{grammar → peg_syntax}/start_rule.feature +1 -1
- data/features/peg_syntax/zero_or_more.feature +59 -0
- data/features/{grammar → semantics}/labels.feature +0 -0
- data/features/{grammar → semantics}/negative_semantic_predicate.feature +30 -9
- data/features/{grammar → semantics}/node_action.feature +0 -0
- data/features/{grammar → semantics}/positive_semantic_predicate.feature +29 -8
- data/features/{grammar/symantic_action.feature → semantics/semantic_action.feature} +2 -2
- data/features/semantics/semantic_result.feature +86 -0
- data/features/{grammar → semantics}/side_effect.feature +33 -21
- data/features/step_definitions/cli_steps.rb +1 -1
- data/features/step_definitions/grammar_steps.rb +19 -5
- data/features/support/env.rb +5 -0
- data/lib/rattler.rb +21 -44
- data/lib/rattler/compiler.rb +69 -0
- data/lib/rattler/{grammar → compiler}/grammar_parser.rb +58 -24
- data/lib/rattler/compiler/metagrammar.rb +1570 -0
- data/lib/rattler/compiler/optimizer.rb +77 -0
- data/lib/rattler/{back_end → compiler}/optimizer/composite_reducing.rb +2 -2
- data/lib/rattler/{back_end → compiler}/optimizer/flatten_choice.rb +3 -12
- data/lib/rattler/{back_end → compiler}/optimizer/flatten_sequence.rb +4 -16
- data/lib/rattler/{back_end → compiler}/optimizer/flattening.rb +2 -2
- data/lib/rattler/compiler/optimizer/inline_regular_rules.rb +24 -0
- data/lib/rattler/{back_end → compiler}/optimizer/join_match_capturing_sequence.rb +16 -14
- data/lib/rattler/{back_end → compiler}/optimizer/join_match_choice.rb +4 -13
- data/lib/rattler/{back_end → compiler}/optimizer/join_match_matching_sequence.rb +4 -13
- data/lib/rattler/compiler/optimizer/join_match_sequence.rb +7 -0
- data/lib/rattler/{back_end → compiler}/optimizer/join_predicate_bare_match.rb +3 -12
- data/lib/rattler/compiler/optimizer/join_predicate_match.rb +7 -0
- data/lib/rattler/{back_end → compiler}/optimizer/join_predicate_nested_match.rb +4 -13
- data/lib/rattler/{back_end → compiler}/optimizer/join_predicate_or_bare_match.rb +3 -12
- data/lib/rattler/compiler/optimizer/join_predicate_or_match.rb +7 -0
- data/lib/rattler/{back_end → compiler}/optimizer/join_predicate_or_nested_match.rb +4 -13
- data/lib/rattler/{back_end → compiler}/optimizer/match_joining.rb +2 -2
- data/lib/rattler/{back_end → compiler}/optimizer/optimization.rb +12 -34
- data/lib/rattler/compiler/optimizer/optimization_context.rb +83 -0
- data/lib/rattler/{back_end → compiler}/optimizer/optimization_sequence.rb +3 -11
- data/lib/rattler/compiler/optimizer/optimizations.rb +27 -0
- data/lib/rattler/{back_end → compiler}/optimizer/optimize_children.rb +6 -14
- data/lib/rattler/{back_end → compiler}/optimizer/reduce_repeat_match.rb +4 -13
- data/lib/rattler/compiler/optimizer/remove_meaningless_wrapper.rb +22 -0
- data/lib/rattler/{back_end → compiler}/optimizer/simplify_redundant_repeat.rb +4 -13
- data/lib/rattler/{back_end → compiler}/optimizer/simplify_token_match.rb +4 -13
- data/lib/rattler/compiler/parser_generator.rb +108 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/apply_generator.rb +7 -21
- data/lib/rattler/{back_end → compiler}/parser_generator/assert_generator.rb +11 -19
- data/lib/rattler/compiler/parser_generator/attributed_sequence_generator.rb +37 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/back_reference_generator.rb +10 -10
- data/lib/rattler/{back_end → compiler}/parser_generator/choice_generator.rb +10 -22
- data/lib/rattler/{back_end → compiler}/parser_generator/delegating_generator.rb +2 -2
- data/lib/rattler/{back_end → compiler}/parser_generator/disallow_generator.rb +11 -19
- data/lib/rattler/{back_end → compiler}/parser_generator/e_symbol_generator.rb +2 -10
- data/lib/rattler/{back_end → compiler}/parser_generator/eof_generator.rb +2 -10
- data/lib/rattler/{back_end → compiler}/parser_generator/expr_generator.rb +9 -35
- data/lib/rattler/{back_end → compiler}/parser_generator/fail_generator.rb +7 -3
- data/lib/rattler/{back_end → compiler}/parser_generator/gen_method_names.rb +3 -5
- data/lib/rattler/{back_end → compiler}/parser_generator/general_list_generator.rb +6 -18
- data/lib/rattler/{back_end → compiler}/parser_generator/general_repeat_generator.rb +16 -22
- data/lib/rattler/{back_end/parser_generator/rule_set_generator.rb → compiler/parser_generator/grammar_generator.rb} +24 -33
- data/lib/rattler/compiler/parser_generator/group_match.rb +33 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/group_match_generator.rb +4 -17
- data/lib/rattler/compiler/parser_generator/label_generator.rb +37 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/list0_generating.rb +5 -5
- data/lib/rattler/{back_end → compiler}/parser_generator/list1_generating.rb +3 -3
- data/lib/rattler/{back_end → compiler}/parser_generator/list_generator.rb +2 -2
- data/lib/rattler/{back_end → compiler}/parser_generator/match_generator.rb +10 -10
- data/lib/rattler/{back_end → compiler}/parser_generator/nested.rb +2 -2
- data/lib/rattler/compiler/parser_generator/node_action_generator.rb +49 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/one_or_more_generating.rb +3 -3
- data/lib/rattler/{back_end → compiler}/parser_generator/optional_generating.rb +6 -22
- data/lib/rattler/compiler/parser_generator/predicate_propogating.rb +24 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/repeat_generator.rb +2 -2
- data/lib/rattler/compiler/parser_generator/rule_generator.rb +66 -0
- data/lib/rattler/compiler/parser_generator/rule_set_generator.rb +33 -0
- data/lib/rattler/compiler/parser_generator/semantic_action_generator.rb +58 -0
- data/lib/rattler/compiler/parser_generator/sequence_generating.rb +138 -0
- data/lib/rattler/compiler/parser_generator/sequence_generator.rb +57 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/skip_generator.rb +4 -18
- data/lib/rattler/compiler/parser_generator/skip_propogating.rb +16 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/sub_generating.rb +19 -11
- data/lib/rattler/compiler/parser_generator/super_generator.rb +54 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/token_generator.rb +3 -3
- data/lib/rattler/compiler/parser_generator/token_propogating.rb +10 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/top_level.rb +2 -2
- data/lib/rattler/{back_end → compiler}/parser_generator/zero_or_more_generating.rb +5 -5
- data/lib/rattler/compiler/rattler.rtlr +201 -0
- data/lib/rattler/{back_end → compiler}/ruby_generator.rb +16 -25
- data/lib/rattler/parsers.rb +12 -33
- data/lib/rattler/parsers/action_code.rb +25 -16
- data/lib/rattler/{grammar → parsers}/analysis.rb +32 -11
- data/lib/rattler/parsers/apply.rb +10 -19
- data/lib/rattler/parsers/assert.rb +4 -14
- data/lib/rattler/parsers/atomic.rb +3 -10
- data/lib/rattler/parsers/attributed_sequence.rb +50 -0
- data/lib/rattler/parsers/back_reference.rb +19 -14
- data/lib/rattler/parsers/choice.rb +11 -12
- data/lib/rattler/parsers/combinator_parser.rb +15 -7
- data/lib/rattler/parsers/combining.rb +15 -9
- data/lib/rattler/parsers/disallow.rb +5 -12
- data/lib/rattler/parsers/e_symbol.rb +5 -14
- data/lib/rattler/parsers/eof.rb +10 -15
- data/lib/rattler/parsers/fail.rb +16 -26
- data/lib/rattler/{grammar → parsers}/grammar.rb +15 -20
- data/lib/rattler/parsers/label.rb +10 -16
- data/lib/rattler/parsers/list_parser.rb +14 -14
- data/lib/rattler/parsers/match.rb +5 -17
- data/lib/rattler/parsers/node_action.rb +72 -0
- data/lib/rattler/parsers/node_code.rb +47 -30
- data/lib/rattler/parsers/parser.rb +63 -32
- data/lib/rattler/parsers/parser_scope.rb +88 -0
- data/lib/rattler/parsers/predicate.rb +12 -10
- data/lib/rattler/parsers/repeat.rb +15 -8
- data/lib/rattler/parsers/rule.rb +8 -23
- data/lib/rattler/parsers/rule_set.rb +67 -12
- data/lib/rattler/parsers/semantic.rb +36 -0
- data/lib/rattler/parsers/semantic_action.rb +39 -0
- data/lib/rattler/parsers/sequence.rb +25 -40
- data/lib/rattler/parsers/sequencing.rb +40 -0
- data/lib/rattler/parsers/skip.rb +11 -12
- data/lib/rattler/parsers/super.rb +33 -0
- data/lib/rattler/parsers/token.rb +3 -13
- data/lib/rattler/rake_task.rb +50 -0
- data/lib/rattler/runner.rb +19 -22
- data/lib/rattler/runtime.rb +0 -10
- data/lib/rattler/runtime/extended_packrat_parser.rb +40 -45
- data/lib/rattler/runtime/packrat_parser.rb +17 -31
- data/lib/rattler/runtime/parse_failure.rb +16 -26
- data/lib/rattler/runtime/parse_node.rb +8 -18
- data/lib/rattler/runtime/parser.rb +6 -18
- data/lib/rattler/runtime/parser_helper.rb +3 -10
- data/lib/rattler/runtime/recursive_descent_parser.rb +26 -23
- data/lib/rattler/runtime/syntax_error.rb +0 -10
- data/lib/rattler/util.rb +2 -6
- data/lib/rattler/util/grammar_cli.rb +19 -0
- data/lib/rattler/util/graphviz.rb +6 -17
- data/lib/rattler/util/graphviz/digraph_builder.rb +10 -17
- data/lib/rattler/util/graphviz/node_builder.rb +45 -31
- data/lib/rattler/util/line_counter.rb +11 -20
- data/lib/rattler/util/node.rb +52 -30
- data/lib/rattler/util/parser_cli.rb +84 -0
- data/lib/rattler/util/parser_spec_helper.rb +8 -12
- data/spec/rattler/compiler/assert_compiler_examples.rb +284 -0
- data/spec/rattler/compiler/attributed_sequence_compiler_examples.rb +154 -0
- data/spec/rattler/compiler/disallow_compiler_examples.rb +293 -0
- data/spec/rattler/compiler/grammar_parser_spec.rb +700 -0
- data/spec/rattler/{back_end → compiler}/optimizer/flatten_choice_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/flatten_sequence_spec.rb +1 -1
- data/spec/rattler/compiler/optimizer/inline_regular_rules_spec.rb +50 -0
- data/spec/rattler/{back_end → compiler}/optimizer/join_match_capturing_sequence_spec.rb +106 -22
- data/spec/rattler/{back_end → compiler}/optimizer/join_match_choice_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/join_match_matching_sequence_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/join_predicate_bare_match_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/join_predicate_nested_match_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/join_predicate_or_bare_match_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/join_predicate_or_nested_match_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/reduce_repeat_match_spec.rb +1 -1
- data/spec/rattler/compiler/optimizer/remove_meaningless_wrapper_spec.rb +82 -0
- data/spec/rattler/{back_end → compiler}/optimizer/simplify_redundant_repeat_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/simplify_token_match_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/parser_generator/apply_generator_spec.rb +1 -39
- data/spec/rattler/{back_end → compiler}/parser_generator/assert_generator_spec.rb +1 -55
- data/spec/rattler/compiler/parser_generator/attributed_sequence_generator_spec.rb +699 -0
- data/spec/rattler/{back_end → compiler}/parser_generator/back_reference_generator_spec.rb +3 -56
- data/spec/rattler/{back_end → compiler}/parser_generator/choice_generator_spec.rb +1 -63
- data/spec/rattler/{back_end → compiler}/parser_generator/disallow_generator_spec.rb +1 -55
- data/spec/rattler/{back_end → compiler}/parser_generator/e_symbol_generator_spec.rb +1 -39
- data/spec/rattler/{back_end → compiler}/parser_generator/eof_generator_spec.rb +1 -39
- data/spec/rattler/{back_end → compiler}/parser_generator/fail_generator_spec.rb +94 -23
- data/spec/rattler/compiler/parser_generator/grammar_generator_spec.rb +98 -0
- data/spec/rattler/compiler/parser_generator/group_match_generator_spec.rb +67 -0
- data/spec/rattler/{back_end → compiler}/parser_generator/group_match_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/parser_generator/label_generator_spec.rb +1 -55
- data/spec/rattler/{back_end → compiler}/parser_generator/list0_generator_examples.rb +0 -88
- data/spec/rattler/{back_end → compiler}/parser_generator/list1_generator_examples.rb +0 -88
- data/spec/rattler/{back_end → compiler}/parser_generator/list_generator_spec.rb +1 -227
- data/spec/rattler/{back_end → compiler}/parser_generator/match_generator_spec.rb +1 -55
- data/spec/rattler/compiler/parser_generator/node_action_generator_spec.rb +135 -0
- data/spec/rattler/{back_end → compiler}/parser_generator/one_or_more_generator_examples.rb +0 -74
- data/spec/rattler/{back_end → compiler}/parser_generator/optional_generator_examples.rb +0 -62
- data/spec/rattler/{back_end → compiler}/parser_generator/repeat_generator_spec.rb +66 -1
- data/spec/rattler/{back_end → compiler}/parser_generator/rule_generator_spec.rb +3 -2
- data/spec/rattler/{back_end → compiler}/parser_generator/rule_set_generator_spec.rb +9 -27
- data/spec/rattler/compiler/parser_generator/semantic_action_generator_spec.rb +437 -0
- data/spec/rattler/{back_end → compiler}/parser_generator/sequence_generator_spec.rb +234 -68
- data/spec/rattler/{back_end → compiler}/parser_generator/skip_generator_spec.rb +1 -55
- data/spec/rattler/compiler/parser_generator/super_generator_spec.rb +93 -0
- data/spec/rattler/{back_end → compiler}/parser_generator/token_generator_spec.rb +1 -55
- data/spec/rattler/{back_end → compiler}/parser_generator/zero_or_more_generator_examples.rb +0 -74
- data/spec/rattler/{back_end → compiler}/ruby_generator_spec.rb +13 -13
- data/spec/rattler/compiler/semantic_action_compiler_examples.rb +57 -0
- data/spec/rattler/{back_end → compiler}/shared_compiler_examples.rb +111 -140
- data/spec/rattler/{back_end → compiler}/skip_compiler_examples.rb +60 -57
- data/spec/rattler/{back_end → compiler}/token_compiler_examples.rb +99 -104
- data/spec/rattler/compiler_spec.rb +67 -0
- data/spec/rattler/parsers/action_code_spec.rb +34 -18
- data/spec/rattler/{grammar → parsers}/analysis_spec.rb +13 -67
- data/spec/rattler/parsers/apply_spec.rb +6 -0
- data/spec/rattler/parsers/assert_spec.rb +38 -2
- data/spec/rattler/parsers/attributed_sequence_spec.rb +204 -0
- data/spec/rattler/parsers/back_reference_spec.rb +6 -0
- data/spec/rattler/parsers/choice_spec.rb +38 -1
- data/spec/rattler/parsers/combinator_parser_spec.rb +2 -1
- data/spec/rattler/parsers/disallow_spec.rb +38 -2
- data/spec/rattler/parsers/e_symbol_spec.rb +6 -0
- data/spec/rattler/parsers/eof_spec.rb +6 -0
- data/spec/rattler/parsers/fail_spec.rb +6 -0
- data/spec/rattler/{grammar → parsers}/grammar_spec.rb +10 -15
- data/spec/rattler/parsers/label_spec.rb +30 -0
- data/spec/rattler/parsers/list_parser_spec.rb +31 -2
- data/spec/rattler/parsers/match_spec.rb +6 -0
- data/spec/rattler/parsers/node_action_spec.rb +121 -0
- data/spec/rattler/parsers/parser_scope_spec.rb +105 -0
- data/spec/rattler/parsers/repeat_spec.rb +56 -0
- data/spec/rattler/parsers/rule_set_spec.rb +42 -0
- data/spec/rattler/parsers/semantic_action_spec.rb +89 -0
- data/spec/rattler/parsers/sequence_spec.rb +156 -12
- data/spec/rattler/parsers/skip_spec.rb +21 -0
- data/spec/rattler/parsers/super_spec.rb +45 -0
- data/spec/rattler/parsers/token_spec.rb +33 -14
- data/spec/rattler/runtime/extended_packrat_parser_spec.rb +10 -8
- data/spec/rattler/runtime/recursive_descent_parser_spec.rb +26 -0
- data/spec/rattler/runtime/shared_parser_examples.rb +22 -16
- data/spec/rattler/util/graphviz/node_builder_spec.rb +33 -17
- data/spec/rattler/util/line_counter_spec.rb +21 -21
- data/spec/rattler/util/node_spec.rb +62 -0
- data/spec/rattler_spec.rb +7 -41
- data/spec/spec_helper.rb +1 -2
- data/spec/support/combinator_parser_spec_helper.rb +1 -1
- data/spec/support/compiler_spec_helper.rb +0 -4
- data/spec/support/parser_generator_spec_helper.rb +7 -7
- data/spec/support/runtime_parser_spec_helper.rb +57 -3
- metadata +447 -303
- data/features/grammar/character_class.feature +0 -20
- data/features/grammar/nonterminal.feature +0 -24
- data/features/grammar/one_or_more.feature +0 -34
- data/features/grammar/ordered_choice.feature +0 -21
- data/features/grammar/posix_class.feature +0 -70
- data/features/grammar/sequence.feature +0 -20
- data/features/grammar/zero_or_more.feature +0 -34
- data/lib/rattler/back_end.rb +0 -22
- data/lib/rattler/back_end/compiler.rb +0 -128
- data/lib/rattler/back_end/optimizer.rb +0 -101
- data/lib/rattler/back_end/optimizer/inline_regular_rules.rb +0 -46
- data/lib/rattler/back_end/optimizer/join_match_sequence.rb +0 -17
- data/lib/rattler/back_end/optimizer/join_predicate_match.rb +0 -17
- data/lib/rattler/back_end/optimizer/join_predicate_or_match.rb +0 -17
- data/lib/rattler/back_end/optimizer/optimization_context.rb +0 -72
- data/lib/rattler/back_end/optimizer/remove_meaningless_wrapper.rb +0 -32
- data/lib/rattler/back_end/optimizer/specialize_repeat.rb +0 -40
- data/lib/rattler/back_end/parser_generator.rb +0 -113
- data/lib/rattler/back_end/parser_generator/direct_action_generator.rb +0 -45
- data/lib/rattler/back_end/parser_generator/dispatch_action_generator.rb +0 -45
- data/lib/rattler/back_end/parser_generator/group_match.rb +0 -26
- data/lib/rattler/back_end/parser_generator/label_generator.rb +0 -64
- data/lib/rattler/back_end/parser_generator/predicate_propogating.rb +0 -24
- data/lib/rattler/back_end/parser_generator/rule_generator.rb +0 -53
- data/lib/rattler/back_end/parser_generator/sequence_generator.rb +0 -190
- data/lib/rattler/back_end/parser_generator/skip_propogating.rb +0 -16
- data/lib/rattler/back_end/parser_generator/token_propogating.rb +0 -10
- data/lib/rattler/grammar.rb +0 -43
- data/lib/rattler/grammar/grammar_dsl.rb +0 -51
- data/lib/rattler/grammar/metagrammar.rb +0 -990
- data/lib/rattler/grammar/rattler.rtlr +0 -183
- data/lib/rattler/parsers/assert_code.rb +0 -31
- data/lib/rattler/parsers/direct_action.rb +0 -85
- data/lib/rattler/parsers/disallow_code.rb +0 -31
- data/lib/rattler/parsers/dispatch_action.rb +0 -121
- data/lib/rattler/parsers/effect_code.rb +0 -31
- data/lib/rattler/parsers/parser_dsl.rb +0 -414
- data/lib/rattler/parsers/semantic_assert.rb +0 -19
- data/lib/rattler/parsers/semantic_disallow.rb +0 -19
- data/lib/rattler/parsers/side_effect.rb +0 -19
- data/spec/rattler/back_end/assert_compiler_examples.rb +0 -187
- data/spec/rattler/back_end/compiler_spec.rb +0 -43
- data/spec/rattler/back_end/direct_action_compiler_examples.rb +0 -227
- data/spec/rattler/back_end/disallow_compiler_examples.rb +0 -187
- data/spec/rattler/back_end/dispatch_action_compiler_examples.rb +0 -225
- data/spec/rattler/back_end/optimizer/inline_regular_rules_spec.rb +0 -80
- data/spec/rattler/back_end/parser_generator/direct_action_generator_spec.rb +0 -204
- data/spec/rattler/back_end/parser_generator/dispatch_action_generator_spec.rb +0 -204
- data/spec/rattler/back_end/parser_generator/group_match_generator_spec.rb +0 -185
- data/spec/rattler/back_end/semantic_assert_compiler_examples.rb +0 -152
- data/spec/rattler/back_end/semantic_disallow_compiler_examples.rb +0 -152
- data/spec/rattler/back_end/side_effect_compiler_examples.rb +0 -227
- data/spec/rattler/grammar/grammar_parser_spec.rb +0 -626
- data/spec/rattler/parsers/direct_action_spec.rb +0 -224
- data/spec/rattler/parsers/dispatch_action_spec.rb +0 -209
- data/spec/rattler/parsers/node_code_spec.rb +0 -59
- data/spec/rattler/parsers/parser_dsl_spec.rb +0 -334
- data/spec/rattler/parsers/semantic_assert_spec.rb +0 -83
- data/spec/rattler/parsers/semantic_disallow_spec.rb +0 -83
- data/spec/rattler/parsers/side_effect_spec.rb +0 -214
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require 'rattler/compiler/optimizer'
|
|
2
|
+
|
|
3
|
+
module Rattler::Compiler::Optimizer
|
|
4
|
+
|
|
5
|
+
# +OptimizationContext+ provides contextual information to optimzations.
|
|
6
|
+
class OptimizationContext
|
|
7
|
+
|
|
8
|
+
# @private
|
|
9
|
+
@@cache = Hash.new {|h, attrs| h[attrs] = self.new(attrs) }
|
|
10
|
+
|
|
11
|
+
# @param [Hash] attrs attributes of an optimization context
|
|
12
|
+
# @return [OptimizationContext] an optimization context with the given
|
|
13
|
+
# attributes
|
|
14
|
+
def self.[](attrs)
|
|
15
|
+
@@cache[attrs]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @param [Hash] attrs attributes of an optimization context
|
|
19
|
+
def initialize(attrs)
|
|
20
|
+
@attrs = attrs
|
|
21
|
+
@rules = @attrs[:rules]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
attr_reader :type, :rules
|
|
25
|
+
|
|
26
|
+
# @return [Symbol] the name of the start rule
|
|
27
|
+
def start_rule
|
|
28
|
+
rules && rules.start_rule
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @return [Rattler::Parsers::Analysis] an analysis of the parse rules
|
|
32
|
+
def analysis
|
|
33
|
+
rules && rules.analysis
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @return whether this is a capturing context
|
|
37
|
+
def capturing?
|
|
38
|
+
@attrs[:type] == :capturing
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @return whether this is a matching context
|
|
42
|
+
def matching?
|
|
43
|
+
@attrs[:type] == :matching
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @param [Symbol] rule_name the name of a rule in the context
|
|
47
|
+
# @return whether the rule can be inlined
|
|
48
|
+
def inlineable?(rule_name)
|
|
49
|
+
if rule = rules[rule_name]
|
|
50
|
+
rule.attrs[:inline] and
|
|
51
|
+
analysis.regular? rule_name
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# @param [Rattler::Parsers::Rule] rule a rule in the context
|
|
56
|
+
# @return whether the rule is relavent to the optimized parser
|
|
57
|
+
def relavent?(rule)
|
|
58
|
+
!rule.attrs[:inline] or
|
|
59
|
+
analysis.referenced?(rule.name)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# @param [Hash] new_attrs additional attributes
|
|
63
|
+
# @return [OptimizationContext] a new context with +new_attrs+ added
|
|
64
|
+
def with(new_attrs)
|
|
65
|
+
self.class[@attrs.merge new_attrs]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# @private
|
|
69
|
+
def method_missing(symbol, *args) #:nodoc:
|
|
70
|
+
if args.empty? and @attrs.has_key? symbol
|
|
71
|
+
@attrs[symbol]
|
|
72
|
+
else
|
|
73
|
+
super
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# @private
|
|
78
|
+
def respond_to?(symbol) #:nodoc:
|
|
79
|
+
super or @attrs.has_key? symbol
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# Documentation:: Author
|
|
6
|
-
#
|
|
7
|
-
require 'rattler'
|
|
2
|
+
require 'rattler/compiler/optimizer'
|
|
3
|
+
|
|
4
|
+
module Rattler::Compiler::Optimizer
|
|
8
5
|
|
|
9
|
-
module Rattler::BackEnd::Optimizer
|
|
10
|
-
#
|
|
11
6
|
# An +OptimizationSequence+ sequences a pair of optimzations so that applying
|
|
12
7
|
# the sequence applies the first optimization, then applies the second
|
|
13
8
|
# optimzation to the result.
|
|
14
|
-
#
|
|
15
|
-
# @author Jason Arhart
|
|
16
|
-
#
|
|
17
9
|
class OptimizationSequence < Optimization
|
|
18
10
|
|
|
19
11
|
def initialize(init, last)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'rattler/compiler/optimizer'
|
|
2
|
+
|
|
3
|
+
module Rattler::Compiler::Optimizer
|
|
4
|
+
|
|
5
|
+
# +Optimizations+ defines the sequence of optimizations to apply to optimize
|
|
6
|
+
# parsers
|
|
7
|
+
module Optimizations
|
|
8
|
+
|
|
9
|
+
# @return [Optimization] the sequence of optimizations to apply to optimize
|
|
10
|
+
# parsers
|
|
11
|
+
def optimizations
|
|
12
|
+
@optimizations ||=
|
|
13
|
+
InlineRegularRules >>
|
|
14
|
+
OptimizeChildren >>
|
|
15
|
+
SimplifyRedundantRepeat >>
|
|
16
|
+
RemoveMeaninglessWrapper >>
|
|
17
|
+
SimplifyTokenMatch >>
|
|
18
|
+
FlattenSequence >>
|
|
19
|
+
FlattenChoice >>
|
|
20
|
+
ReduceRepeatMatch >>
|
|
21
|
+
JoinPredicateMatch >>
|
|
22
|
+
JoinPredicateOrMatch >>
|
|
23
|
+
JoinMatchSequence >>
|
|
24
|
+
JoinMatchChoice
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# Documentation:: Author
|
|
6
|
-
#
|
|
7
|
-
require 'rattler'
|
|
8
|
-
|
|
9
|
-
module Rattler::BackEnd::Optimizer
|
|
10
|
-
#
|
|
1
|
+
require 'rattler/compiler/optimizer'
|
|
2
|
+
|
|
3
|
+
module Rattler::Compiler::Optimizer
|
|
4
|
+
|
|
11
5
|
# Optimizes all of the children of a parser model in the appropriate context.
|
|
12
|
-
#
|
|
13
|
-
# @author Jason Arhart
|
|
14
|
-
#
|
|
15
6
|
class OptimizeChildren < Optimization
|
|
16
7
|
|
|
8
|
+
include Optimizations
|
|
17
9
|
include Rattler::Parsers
|
|
18
10
|
|
|
19
11
|
protected
|
|
@@ -27,7 +19,7 @@ module Rattler::BackEnd::Optimizer
|
|
|
27
19
|
|
|
28
20
|
def _apply(parser, context)
|
|
29
21
|
parser.with_children(parser.map do |_|
|
|
30
|
-
|
|
22
|
+
optimizations.apply _, child_context(parser, context)
|
|
31
23
|
end)
|
|
32
24
|
end
|
|
33
25
|
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# Documentation:: Author
|
|
6
|
-
#
|
|
7
|
-
require 'rattler'
|
|
8
|
-
|
|
9
|
-
module Rattler::BackEnd::Optimizer
|
|
10
|
-
#
|
|
1
|
+
require 'rattler/compiler/optimizer'
|
|
2
|
+
|
|
3
|
+
module Rattler::Compiler::Optimizer
|
|
4
|
+
|
|
11
5
|
# A repeat of a Regexp match can be reduced to a single Regexp match.
|
|
12
|
-
#
|
|
13
|
-
# @author Jason Arhart
|
|
14
|
-
#
|
|
15
6
|
class ReduceRepeatMatch < Optimization
|
|
16
7
|
|
|
17
8
|
include Rattler::Parsers
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'rattler/compiler/optimizer'
|
|
2
|
+
|
|
3
|
+
module Rattler::Compiler::Optimizer
|
|
4
|
+
|
|
5
|
+
# Token and skip wrappers only have meaning in a capturing context.
|
|
6
|
+
class RemoveMeaninglessWrapper < Optimization
|
|
7
|
+
|
|
8
|
+
include Rattler::Parsers
|
|
9
|
+
|
|
10
|
+
protected
|
|
11
|
+
|
|
12
|
+
def _applies_to?(parser, context)
|
|
13
|
+
context.matching? and
|
|
14
|
+
[Token, Skip].any? {|_| parser.is_a? _ }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def _apply(parser, context)
|
|
18
|
+
parser.child
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# Documentation:: Author
|
|
6
|
-
#
|
|
7
|
-
require 'rattler'
|
|
8
|
-
|
|
9
|
-
module Rattler::BackEnd::Optimizer
|
|
10
|
-
#
|
|
1
|
+
require 'rattler/compiler/optimizer'
|
|
2
|
+
|
|
3
|
+
module Rattler::Compiler::Optimizer
|
|
4
|
+
|
|
11
5
|
# A repeat of a repeat can be simplified to a simple repeat.
|
|
12
|
-
#
|
|
13
|
-
# @author Jason Arhart
|
|
14
|
-
#
|
|
15
6
|
class SimplifyRedundantRepeat < Optimization
|
|
16
7
|
|
|
17
8
|
include Rattler::Parsers
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# Documentation:: Author
|
|
6
|
-
#
|
|
7
|
-
require 'rattler'
|
|
8
|
-
|
|
9
|
-
module Rattler::BackEnd::Optimizer
|
|
10
|
-
#
|
|
1
|
+
require 'rattler/compiler/optimizer'
|
|
2
|
+
|
|
3
|
+
module Rattler::Compiler::Optimizer
|
|
4
|
+
|
|
11
5
|
# A token wrapping a terminal parser is redundant.
|
|
12
|
-
#
|
|
13
|
-
# @author Jason Arhart
|
|
14
|
-
#
|
|
15
6
|
class SimplifyTokenMatch < Optimization
|
|
16
7
|
|
|
17
8
|
include Rattler::Parsers
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require 'rattler/compiler'
|
|
2
|
+
|
|
3
|
+
module Rattler::Compiler
|
|
4
|
+
|
|
5
|
+
# A +ParserGenerator+ generates ruby parsing code from parser models.
|
|
6
|
+
module ParserGenerator
|
|
7
|
+
|
|
8
|
+
autoload :GrammarGenerator, 'rattler/compiler/parser_generator/grammar_generator'
|
|
9
|
+
autoload :RuleSetGenerator, 'rattler/compiler/parser_generator/rule_set_generator'
|
|
10
|
+
autoload :RuleGenerator, 'rattler/compiler/parser_generator/rule_generator'
|
|
11
|
+
autoload :ExprGenerator, 'rattler/compiler/parser_generator/expr_generator'
|
|
12
|
+
autoload :GeneratorHelper, 'rattler/compiler/parser_generator/generator_helper'
|
|
13
|
+
autoload :NestedExprGenerator, 'rattler/compiler/parser_generator/expr_generator'
|
|
14
|
+
autoload :SubGenerating, 'rattler/compiler/parser_generator/sub_generating'
|
|
15
|
+
autoload :NestedSubGenerating, 'rattler/compiler/parser_generator/sub_generating'
|
|
16
|
+
autoload :TopLevelSubGenerating, 'rattler/compiler/parser_generator/sub_generating'
|
|
17
|
+
autoload :Nested, 'rattler/compiler/parser_generator/nested'
|
|
18
|
+
autoload :TopLevel, 'rattler/compiler/parser_generator/top_level'
|
|
19
|
+
autoload :MatchGenerator, 'rattler/compiler/parser_generator/match_generator'
|
|
20
|
+
autoload :ChoiceGenerator, 'rattler/compiler/parser_generator/choice_generator'
|
|
21
|
+
autoload :SequenceGenerator, 'rattler/compiler/parser_generator/sequence_generator'
|
|
22
|
+
autoload :RepeatGenerator, 'rattler/compiler/parser_generator/repeat_generator'
|
|
23
|
+
autoload :GeneralRepeatGenerator, 'rattler/compiler/parser_generator/general_repeat_generator'
|
|
24
|
+
autoload :ListGenerator, 'rattler/compiler/parser_generator/list_generator'
|
|
25
|
+
autoload :GeneralListGenerator, 'rattler/compiler/parser_generator/general_list_generator'
|
|
26
|
+
autoload :ApplyGenerator, 'rattler/compiler/parser_generator/apply_generator'
|
|
27
|
+
autoload :AssertGenerator, 'rattler/compiler/parser_generator/assert_generator'
|
|
28
|
+
autoload :DisallowGenerator, 'rattler/compiler/parser_generator/disallow_generator'
|
|
29
|
+
autoload :EofGenerator, 'rattler/compiler/parser_generator/eof_generator'
|
|
30
|
+
autoload :ESymbolGenerator, 'rattler/compiler/parser_generator/e_symbol_generator'
|
|
31
|
+
autoload :SemanticActionGenerator, 'rattler/compiler/parser_generator/semantic_action_generator'
|
|
32
|
+
autoload :NodeActionGenerator, 'rattler/compiler/parser_generator/node_action_generator'
|
|
33
|
+
autoload :AttributedSequenceGenerator, 'rattler/compiler/parser_generator/attributed_sequence_generator'
|
|
34
|
+
autoload :TokenGenerator, 'rattler/compiler/parser_generator/token_generator'
|
|
35
|
+
autoload :SkipGenerator, 'rattler/compiler/parser_generator/skip_generator'
|
|
36
|
+
autoload :SuperGenerator, 'rattler/compiler/parser_generator/super_generator'
|
|
37
|
+
autoload :LabelGenerator, 'rattler/compiler/parser_generator/label_generator'
|
|
38
|
+
autoload :BackReferenceGenerator, 'rattler/compiler/parser_generator/back_reference_generator'
|
|
39
|
+
autoload :FailGenerator, 'rattler/compiler/parser_generator/fail_generator'
|
|
40
|
+
autoload :DelegatingGenerator, 'rattler/compiler/parser_generator/delegating_generator'
|
|
41
|
+
autoload :SequenceGenerating, 'rattler/compiler/parser_generator/sequence_generating'
|
|
42
|
+
autoload :ZeroOrMoreGenerating, 'rattler/compiler/parser_generator/zero_or_more_generating'
|
|
43
|
+
autoload :OptionalGenerating, 'rattler/compiler/parser_generator/optional_generating'
|
|
44
|
+
autoload :OneOrMoreGenerating, 'rattler/compiler/parser_generator/one_or_more_generating'
|
|
45
|
+
autoload :List0Generating, 'rattler/compiler/parser_generator/list0_generating'
|
|
46
|
+
autoload :List1Generating, 'rattler/compiler/parser_generator/list1_generating'
|
|
47
|
+
autoload :PredicatePropogating, 'rattler/compiler/parser_generator/predicate_propogating'
|
|
48
|
+
autoload :TokenPropogating, 'rattler/compiler/parser_generator/token_propogating'
|
|
49
|
+
autoload :SkipPropogating, 'rattler/compiler/parser_generator/skip_propogating'
|
|
50
|
+
autoload :GroupMatchGenerator, 'rattler/compiler/parser_generator/group_match_generator'
|
|
51
|
+
autoload :GroupMatch, 'rattler/compiler/parser_generator/group_match'
|
|
52
|
+
autoload :GEN_METHOD_NAMES, 'rattler/compiler/parser_generator/gen_method_names'
|
|
53
|
+
|
|
54
|
+
# Generate parsing code for a parser model using a ruby generator +g+.
|
|
55
|
+
#
|
|
56
|
+
# @overload generate(g, grammar)
|
|
57
|
+
# @param [RubyGenerator] g the ruby generator to use
|
|
58
|
+
# @param [Rattler::Parsers::Grammar] grammar the grammar model
|
|
59
|
+
# @return g
|
|
60
|
+
#
|
|
61
|
+
# @overload generate(g, rules)
|
|
62
|
+
# @param [RubyGenerator] g the ruby generator to use
|
|
63
|
+
# @param [Rules] rules the parse rules
|
|
64
|
+
# @return g
|
|
65
|
+
#
|
|
66
|
+
# @overload generate(g, rule)
|
|
67
|
+
# @param [RubyGenerator] g the ruby generator to use
|
|
68
|
+
# @param [Rule] rule the parse rule
|
|
69
|
+
# @return g
|
|
70
|
+
#
|
|
71
|
+
# @overload generate(g, parser)
|
|
72
|
+
# @param [RubyGenerator] g the ruby generator to use
|
|
73
|
+
# @param [Parser] parser the parser model
|
|
74
|
+
# @return g
|
|
75
|
+
#
|
|
76
|
+
def self.generate(g, parser, opts={})
|
|
77
|
+
unless opts[:no_optimize]
|
|
78
|
+
parser = ::Rattler::Compiler::Optimizer.optimize(parser, opts)
|
|
79
|
+
end
|
|
80
|
+
GrammarGenerator.new(g).generate(parser, opts)
|
|
81
|
+
g
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Generate parsing code for +parser+ using a new {RubyGenerator} with the
|
|
85
|
+
# given options and return the generated code.
|
|
86
|
+
#
|
|
87
|
+
# @overload code_for(grammar, opts)
|
|
88
|
+
# @param [Rattler::Parsers::Grammar] grammar the grammar model
|
|
89
|
+
# @return [String] the generated code
|
|
90
|
+
#
|
|
91
|
+
# @overload code_for(rules, opts)
|
|
92
|
+
# @param [Rules] rules the parse rules
|
|
93
|
+
# @return [String] the generated code
|
|
94
|
+
#
|
|
95
|
+
# @overload code_for(rule, opts)
|
|
96
|
+
# @param [Rule] rule the parse rule
|
|
97
|
+
# @return [String] the generated code
|
|
98
|
+
#
|
|
99
|
+
# @overload code_for(parser, opts)
|
|
100
|
+
# @param [Parser] parser the parser model
|
|
101
|
+
# @return [String] the generated code
|
|
102
|
+
#
|
|
103
|
+
def self.code_for(parser, opts={})
|
|
104
|
+
::Rattler::Compiler::RubyGenerator.code(opts) {|g| generate g, parser, opts }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
require 'rattler/
|
|
1
|
+
require 'rattler/compiler/parser_generator'
|
|
2
2
|
|
|
3
|
-
module Rattler::
|
|
3
|
+
module Rattler::Compiler::ParserGenerator
|
|
4
4
|
|
|
5
5
|
# @private
|
|
6
6
|
class ApplyGenerator < ExprGenerator #:nodoc:
|
|
7
7
|
|
|
8
|
-
def gen_basic(apply, scope=
|
|
8
|
+
def gen_basic(apply, scope = ParserScope.empty)
|
|
9
9
|
@g << "match(:#{apply.rule_name})"
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def gen_assert(apply, scope=
|
|
12
|
+
def gen_assert(apply, scope = ParserScope.empty)
|
|
13
13
|
expr :block do
|
|
14
14
|
lookahead do
|
|
15
15
|
@g.surround("#{result_name} = (", ')') { gen_bare_skip apply }
|
|
@@ -19,7 +19,7 @@ module Rattler::BackEnd::ParserGenerator
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
def gen_disallow(apply, scope=
|
|
22
|
+
def gen_disallow(apply, scope = ParserScope.empty)
|
|
23
23
|
expr :block do
|
|
24
24
|
lookahead do
|
|
25
25
|
@g.surround("#{result_name} = !", '') { gen_basic apply }
|
|
@@ -29,25 +29,11 @@ module Rattler::BackEnd::ParserGenerator
|
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def
|
|
33
|
-
expr do
|
|
34
|
-
gen_capture { gen_basic apply }
|
|
35
|
-
@g << ' && ' << code.bind(scope, dispatch_action_args)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def gen_direct_action(apply, code, scope={})
|
|
40
|
-
expr do
|
|
41
|
-
gen_capture { gen_basic apply }
|
|
42
|
-
@g << ' && (' << code.bind(scope, direct_action_args) << ')'
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def gen_skip(apply, scope={})
|
|
32
|
+
def gen_skip(apply, scope = ParserScope.empty)
|
|
47
33
|
expr { gen_bare_skip apply }
|
|
48
34
|
end
|
|
49
35
|
|
|
50
|
-
def gen_intermediate_skip(apply, scope=
|
|
36
|
+
def gen_intermediate_skip(apply, scope = ParserScope.empty)
|
|
51
37
|
gen_basic apply
|
|
52
38
|
end
|
|
53
39
|
|
|
@@ -1,53 +1,45 @@
|
|
|
1
|
-
require 'rattler/
|
|
1
|
+
require 'rattler/compiler/parser_generator'
|
|
2
2
|
|
|
3
|
-
module Rattler::
|
|
3
|
+
module Rattler::Compiler::ParserGenerator
|
|
4
4
|
|
|
5
5
|
# @private
|
|
6
6
|
class AssertGenerator < ExprGenerator #:nodoc:
|
|
7
7
|
|
|
8
|
-
def gen_basic(assert, scope=
|
|
8
|
+
def gen_basic(assert, scope = ParserScope.empty)
|
|
9
9
|
generate assert.child, :assert, scope
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def gen_assert(assert, scope=
|
|
12
|
+
def gen_assert(assert, scope = ParserScope.empty)
|
|
13
13
|
gen_basic assert, scope
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def gen_disallow(assert, scope=
|
|
16
|
+
def gen_disallow(assert, scope = ParserScope.empty)
|
|
17
17
|
@g << 'false'
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def gen_skip(assert, scope=
|
|
20
|
+
def gen_skip(assert, scope = ParserScope.empty)
|
|
21
21
|
gen_basic assert, scope
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
def
|
|
25
|
-
expr(:block) { gen_action assert, code.bind(scope, '[]'), scope }
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def gen_direct_action(assert, code, scope={})
|
|
29
|
-
expr(:block) { gen_action assert, "(#{code.bind scope, []})", scope }
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def gen_token(assert, scope={})
|
|
24
|
+
def gen_token(assert, scope = ParserScope.empty)
|
|
33
25
|
expr(:block) { gen_action assert, "''", scope }
|
|
34
26
|
end
|
|
35
27
|
|
|
36
|
-
def gen_intermediate(assert, scope=
|
|
28
|
+
def gen_intermediate(assert, scope = ParserScope.empty)
|
|
37
29
|
generate assert.child, :intermediate_assert, scope
|
|
38
30
|
end
|
|
39
31
|
|
|
40
|
-
def gen_intermediate_assert(assert, scope=
|
|
32
|
+
def gen_intermediate_assert(assert, scope = ParserScope.empty)
|
|
41
33
|
gen_intermediate assert, scope
|
|
42
34
|
end
|
|
43
35
|
|
|
44
|
-
def gen_intermediate_skip(assert, scope=
|
|
36
|
+
def gen_intermediate_skip(assert, scope = ParserScope.empty)
|
|
45
37
|
gen_intermediate assert, scope
|
|
46
38
|
end
|
|
47
39
|
|
|
48
40
|
private
|
|
49
41
|
|
|
50
|
-
def gen_action(assert, result_code, scope=
|
|
42
|
+
def gen_action(assert, result_code, scope = ParserScope.empty)
|
|
51
43
|
gen_intermediate assert, scope
|
|
52
44
|
(@g << ' &&').newline << result_code
|
|
53
45
|
end
|