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
@@ -1,22 +1,13 @@
|
|
1
|
-
|
2
|
-
# = rattler/back_end/ruby_generator.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
require 'rattler/back_end'
|
1
|
+
require 'rattler/compiler'
|
8
2
|
require 'stringio'
|
9
3
|
|
10
|
-
module Rattler::
|
11
|
-
|
4
|
+
module Rattler::Compiler
|
5
|
+
|
12
6
|
# A +RubyGenerator+ is used to generate well-formatted ruby code. It keeps
|
13
7
|
# track of the indent level and has various methods for adding code, all of
|
14
8
|
# which return +self+ to allow method chaining.
|
15
|
-
#
|
16
|
-
# @author Jason Arhart
|
17
|
-
#
|
18
9
|
class RubyGenerator
|
19
|
-
|
10
|
+
|
20
11
|
# Create a new +RubyGenerator+ with the given options, yield it to the
|
21
12
|
# block, and return the code generated by the block.
|
22
13
|
#
|
@@ -30,7 +21,7 @@ module Rattler::BackEnd
|
|
30
21
|
yield generator
|
31
22
|
generator.code
|
32
23
|
end
|
33
|
-
|
24
|
+
|
34
25
|
# Create a new +RubyGenerator+ with the given options.
|
35
26
|
#
|
36
27
|
# @option options [Integer] :indent_level (0) the initial indent level
|
@@ -41,7 +32,7 @@ module Rattler::BackEnd
|
|
41
32
|
@indent_level = options[:indent_level] || 0
|
42
33
|
@io = options[:io] || StringIO.new
|
43
34
|
end
|
44
|
-
|
35
|
+
|
45
36
|
# Add arbirtrary code.
|
46
37
|
#
|
47
38
|
# @param [String] s the code to add
|
@@ -51,7 +42,7 @@ module Rattler::BackEnd
|
|
51
42
|
@io << s
|
52
43
|
self
|
53
44
|
end
|
54
|
-
|
45
|
+
|
55
46
|
# Add the appropriate amount of space to indent the start of a line.
|
56
47
|
#
|
57
48
|
# @return [self]
|
@@ -59,7 +50,7 @@ module Rattler::BackEnd
|
|
59
50
|
@io << (' ' * @indent_level)
|
60
51
|
self
|
61
52
|
end
|
62
|
-
|
53
|
+
|
63
54
|
# Add a line break followed by the appropriate amount of space to indent
|
64
55
|
# the start of a line.
|
65
56
|
#
|
@@ -68,7 +59,7 @@ module Rattler::BackEnd
|
|
68
59
|
@io.puts
|
69
60
|
start_line
|
70
61
|
end
|
71
|
-
|
62
|
+
|
72
63
|
# Increase the indent level and start a new line for the given block.
|
73
64
|
#
|
74
65
|
# @return [self]
|
@@ -79,7 +70,7 @@ module Rattler::BackEnd
|
|
79
70
|
@indent_level -= 1
|
80
71
|
self
|
81
72
|
end
|
82
|
-
|
73
|
+
|
83
74
|
# Append the given string after code generated in the given block.
|
84
75
|
#
|
85
76
|
# @return [self]
|
@@ -87,7 +78,7 @@ module Rattler::BackEnd
|
|
87
78
|
yield
|
88
79
|
self << s
|
89
80
|
end
|
90
|
-
|
81
|
+
|
91
82
|
# Append +before+, followed by the code generated in the given block,
|
92
83
|
# followed by +after+.
|
93
84
|
#
|
@@ -99,7 +90,7 @@ module Rattler::BackEnd
|
|
99
90
|
self << before
|
100
91
|
suffix(after) { yield }
|
101
92
|
end
|
102
|
-
|
93
|
+
|
103
94
|
# Generate a multiline indented block with the code generated in the
|
104
95
|
# given block, opening the block with +before+ and closing it with
|
105
96
|
# +after+.
|
@@ -113,7 +104,7 @@ module Rattler::BackEnd
|
|
113
104
|
indent { yield }
|
114
105
|
newline << after
|
115
106
|
end
|
116
|
-
|
107
|
+
|
117
108
|
# Add a separator or newlines or both in between code generated in the
|
118
109
|
# given block for each element in +enum+. Newlines, are always added
|
119
110
|
# after the separator.
|
@@ -142,7 +133,7 @@ module Rattler::BackEnd
|
|
142
133
|
end
|
143
134
|
self
|
144
135
|
end
|
145
|
-
|
136
|
+
|
146
137
|
# Add +sep+ followed by a newline in between code generated in the given
|
147
138
|
# block for each element in +enum+.
|
148
139
|
#
|
@@ -153,13 +144,13 @@ module Rattler::BackEnd
|
|
153
144
|
def intersperse_nl(enum, sep)
|
154
145
|
intersperse(enum, :sep => sep, :newline => true) {|_| yield _ }
|
155
146
|
end
|
156
|
-
|
147
|
+
|
157
148
|
# Return the generated code.
|
158
149
|
#
|
159
150
|
# @return [String] the generated code
|
160
151
|
def code
|
161
152
|
@io.string
|
162
153
|
end
|
163
|
-
|
154
|
+
|
164
155
|
end
|
165
156
|
end
|
data/lib/rattler/parsers.rb
CHANGED
@@ -1,22 +1,13 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
1
|
require 'rattler'
|
8
2
|
|
9
3
|
module Rattler
|
10
|
-
|
4
|
+
|
11
5
|
# The +Parsers+ module defines the basic parsers and combinators used to
|
12
|
-
# compose
|
13
|
-
#
|
14
|
-
# @author Jason Arhart
|
15
|
-
#
|
6
|
+
# compose recursive descent parsers.
|
16
7
|
module Parsers
|
17
|
-
|
18
8
|
autoload :Parser, 'rattler/parsers/parser'
|
19
9
|
autoload :CombinatorParser, 'rattler/parsers/combinator_parser'
|
10
|
+
autoload :Grammar, 'rattler/parsers/grammar'
|
20
11
|
autoload :RuleSet, 'rattler/parsers/rule_set'
|
21
12
|
autoload :Rule, 'rattler/parsers/rule'
|
22
13
|
autoload :Match, 'rattler/parsers/match'
|
@@ -29,36 +20,24 @@ module Rattler
|
|
29
20
|
autoload :Disallow, 'rattler/parsers/disallow'
|
30
21
|
autoload :Eof, 'rattler/parsers/eof'
|
31
22
|
autoload :ESymbol, 'rattler/parsers/e_symbol'
|
32
|
-
autoload :
|
33
|
-
autoload :
|
34
|
-
autoload :
|
35
|
-
autoload :
|
36
|
-
autoload :SideEffect, 'rattler/parsers/side_effect'
|
23
|
+
autoload :SemanticAction, 'rattler/parsers/semantic_action'
|
24
|
+
autoload :NodeAction, 'rattler/parsers/node_action'
|
25
|
+
autoload :Semantic, 'rattler/parsers/semantic'
|
26
|
+
autoload :AttributedSequence, 'rattler/parsers/attributed_sequence'
|
37
27
|
autoload :Token, 'rattler/parsers/token'
|
38
28
|
autoload :Skip, 'rattler/parsers/skip'
|
29
|
+
autoload :Super, 'rattler/parsers/super'
|
39
30
|
autoload :Label, 'rattler/parsers/label'
|
40
31
|
autoload :BackReference, 'rattler/parsers/back_reference'
|
41
32
|
autoload :Fail, 'rattler/parsers/fail'
|
42
|
-
autoload :ParserDSL, 'rattler/parsers/parser_dsl'
|
43
33
|
autoload :Predicate, 'rattler/parsers/predicate'
|
44
34
|
autoload :Atomic, 'rattler/parsers/atomic'
|
45
35
|
autoload :Combining, 'rattler/parsers/combining'
|
46
|
-
autoload :
|
36
|
+
autoload :Sequencing, 'rattler/parsers/sequencing'
|
37
|
+
autoload :ParserScope, 'rattler/parsers/parser_scope'
|
47
38
|
autoload :ActionCode, 'rattler/parsers/action_code'
|
48
|
-
autoload :EffectCode, 'rattler/parsers/effect_code'
|
49
|
-
autoload :AssertCode, 'rattler/parsers/assert_code'
|
50
|
-
autoload :DisallowCode, 'rattler/parsers/disallow_code'
|
51
39
|
autoload :NodeCode, 'rattler/parsers/node_code'
|
52
|
-
|
53
|
-
class <<self
|
54
|
-
# Define parse rules with the given block
|
55
|
-
#
|
56
|
-
# @return [Rules] a set of parse rules
|
57
|
-
#
|
58
|
-
def define(&block)
|
59
|
-
ParserDSL.rules(&block)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
40
|
+
autoload :Analysis, 'rattler/parsers/analysis'
|
63
41
|
end
|
42
|
+
|
64
43
|
end
|
@@ -1,16 +1,14 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/action_code.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
1
|
require 'rattler/parsers'
|
9
2
|
|
10
3
|
module Rattler::Parsers
|
11
|
-
|
4
|
+
|
5
|
+
# +ActionCode+ defines abstract ruby code with variables that can be bound
|
6
|
+
# to captured parse results to produce concrete ruby code for semantic
|
7
|
+
# actions.
|
12
8
|
class ActionCode #:nodoc:
|
13
9
|
|
10
|
+
# @param [String] code ruby code with optional block parameters and free
|
11
|
+
# variables and block parameters that can bound to captured parse results
|
14
12
|
def initialize(code)
|
15
13
|
if md = /\A\s*\|([^|]*)\|(.*)\Z/.match(code)
|
16
14
|
@param_names = md[1].split(',').map {|_| _.strip }
|
@@ -23,14 +21,25 @@ module Rattler::Parsers
|
|
23
21
|
|
24
22
|
attr_reader :param_names, :body
|
25
23
|
|
26
|
-
|
27
|
-
|
24
|
+
# Bind parameters and variables in the code to parse results in +scope+
|
25
|
+
#
|
26
|
+
# @param [ParserScope] scope the scope of captured parse results
|
27
|
+
# @return [String] concrete ruby code with the parameters and variables
|
28
|
+
# bound to the captured parse results
|
29
|
+
def bind(scope)
|
30
|
+
bind_in body, scope
|
28
31
|
end
|
29
32
|
|
30
|
-
|
31
|
-
|
33
|
+
# @param [ParserScope] scope the scope of captured parse results
|
34
|
+
# @return [Hash] matchers for variables in the ruby code associated with
|
35
|
+
# replacement values
|
36
|
+
def scoped_bindings(scope)
|
37
|
+
to_bindings(scope.bindings).merge(arg_bindings(scope.captures))
|
32
38
|
end
|
33
39
|
|
40
|
+
# @param [Array] args captured parse results as arguments to the ruby code
|
41
|
+
# @return [Hash] matchers for parameters in the ruby code associated with
|
42
|
+
# +args+ as replacements values
|
34
43
|
def arg_bindings(args)
|
35
44
|
if param_names.count > args.count
|
36
45
|
raise ArgumentError, 'more parameter names than arguments'
|
@@ -46,12 +55,12 @@ module Rattler::Parsers
|
|
46
55
|
bindings
|
47
56
|
end
|
48
57
|
|
49
|
-
def bind_in(code, scope
|
58
|
+
def bind_in(code, scope)
|
50
59
|
new_code = code.dup
|
51
|
-
unless param_names.include? '_' or scope.
|
52
|
-
bind_blanks!(new_code,
|
60
|
+
unless param_names.include? '_' or scope.has_name? '_'
|
61
|
+
bind_blanks!(new_code, scope.captures)
|
53
62
|
end
|
54
|
-
scoped_bindings(scope
|
63
|
+
scoped_bindings(scope).each do |k, v|
|
55
64
|
next unless k and v
|
56
65
|
new_code.gsub!(k, v.to_s)
|
57
66
|
end
|
@@ -1,42 +1,50 @@
|
|
1
|
-
|
2
|
-
# = rattler/grammar/grammar.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
require 'rattler/grammar'
|
1
|
+
require 'rattler/parsers'
|
8
2
|
require 'set'
|
9
3
|
|
10
|
-
module Rattler::
|
11
|
-
class Analysis
|
4
|
+
module Rattler::Parsers
|
12
5
|
|
13
|
-
|
6
|
+
# +Analysis+ represents a static analysis of a set of parse rules.
|
7
|
+
class Analysis
|
14
8
|
|
9
|
+
# @param [RuleSet] rules the rule set to analyze
|
15
10
|
def initialize(rules)
|
16
11
|
@rules = rules
|
17
12
|
@references = {}
|
18
13
|
@left_references = {}
|
19
14
|
@direct_references = {}
|
20
15
|
@direct_left_references = {}
|
16
|
+
@has_super = {}
|
21
17
|
end
|
22
18
|
|
19
|
+
# @param [Symbol] rule_name the name of a parse rule in the rule set
|
20
|
+
# @return +true+ if the rule referenced by +rule_name+ is non-recursive
|
23
21
|
def regular?(rule_name)
|
24
22
|
not recursive?(rule_name)
|
25
23
|
end
|
26
24
|
|
25
|
+
# @param [Symbol] rule_name the name of a parse rule in the rule set
|
26
|
+
# @return +true+ if the rule referenced by +rule_name+ is recursive
|
27
27
|
def recursive?(rule_name)
|
28
|
+
has_super? rule_name or
|
28
29
|
referenced_from? rule_name, rule_name
|
29
30
|
end
|
30
31
|
|
32
|
+
# @param [Symbol] rule_name the name of a parse rule in the rule set
|
33
|
+
# @return +true+ if the rule referenced by +rule_name+ is left-recursive
|
31
34
|
def left_recursive?(rule_name)
|
32
35
|
left_referenced_from? rule_name, rule_name
|
33
36
|
end
|
34
37
|
|
38
|
+
# @param [Symbol] rule_name the name of a parse rule in the rule set
|
39
|
+
# @return +true+ if the rule referenced by +rule_name+ is referenced by any
|
40
|
+
# other rule in the rule set
|
35
41
|
def referenced?(rule_name)
|
36
42
|
rule_name == @rules.start_rule or
|
37
43
|
referenced_from? @rules.start_rule, rule_name
|
38
44
|
end
|
39
45
|
|
46
|
+
private
|
47
|
+
|
40
48
|
def referenced_from?(referencer, referencee)
|
41
49
|
references_from(referencer).include? referencee
|
42
50
|
end
|
@@ -45,7 +53,20 @@ module Rattler::Grammar
|
|
45
53
|
left_references_from(referencer).include? referencee
|
46
54
|
end
|
47
55
|
|
48
|
-
|
56
|
+
def has_super?(rule_name)
|
57
|
+
@has_super[rule_name] ||= expr_has_super?(@rules[rule_name].expr)
|
58
|
+
end
|
59
|
+
|
60
|
+
def expr_has_super?(expr)
|
61
|
+
case expr
|
62
|
+
when Super
|
63
|
+
true
|
64
|
+
when Rattler::Parsers::Parser
|
65
|
+
expr.any? {|_| expr_has_super? _ }
|
66
|
+
else
|
67
|
+
false
|
68
|
+
end
|
69
|
+
end
|
49
70
|
|
50
71
|
def references_from(rule_name)
|
51
72
|
@references[rule_name] ||= trace_references rule_name, :direct_references
|
@@ -1,25 +1,11 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/apply.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
1
|
require 'rattler/parsers'
|
9
2
|
|
10
3
|
module Rattler::Parsers
|
11
|
-
|
4
|
+
|
12
5
|
# +Apply+ parses by applying a referenced parse rule.
|
13
|
-
#
|
14
|
-
# @author Jason Arhart
|
15
|
-
#
|
16
6
|
class Apply < Parser
|
17
7
|
|
18
|
-
#
|
19
|
-
# by +rule_name+.
|
20
|
-
#
|
21
|
-
# @param [Symbol] rule_name the name of the referenced rule
|
22
|
-
#
|
8
|
+
# @param [Symbol,String] rule_name the name of the referenced rule
|
23
9
|
# @return [Apply] a new parser that parses by applying the rule
|
24
10
|
# referenced by +rule_name+
|
25
11
|
def self.[](rule_name)
|
@@ -33,11 +19,16 @@ module Rattler::Parsers
|
|
33
19
|
|
34
20
|
# Apply the parse rule referenced by the #rule_name.
|
35
21
|
#
|
36
|
-
# @param (see
|
22
|
+
# @param (see Match#parse)
|
37
23
|
#
|
38
24
|
# @return the result of applying the referenced parse rule
|
39
|
-
def parse(scanner, rules, scope =
|
40
|
-
(rule = rules[rule_name]) && rule.parse(scanner, rules)
|
25
|
+
def parse(scanner, rules, scope = ParserScope.empty)
|
26
|
+
(rule = rules[rule_name]) && rule.parse(scanner, rules, scope)
|
27
|
+
end
|
28
|
+
|
29
|
+
# (see Parser#capturing_decidable?)
|
30
|
+
def capturing_decidable?
|
31
|
+
false
|
41
32
|
end
|
42
33
|
|
43
34
|
end
|
@@ -1,28 +1,18 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/assert.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
1
|
require 'rattler/parsers'
|
9
2
|
|
10
3
|
module Rattler::Parsers
|
11
|
-
|
4
|
+
|
12
5
|
# +Assert+ decorates a parser and succeeds or fails like the decorated
|
13
|
-
# parser but never consumes any input.
|
14
|
-
#
|
15
|
-
# @author Jason Arhart
|
16
|
-
#
|
6
|
+
# parser but never consumes any input (zero-width positive lookahead).
|
17
7
|
class Assert < Predicate
|
18
8
|
|
19
9
|
# Succeed or fail like the decorated parser but do not consume any input
|
20
10
|
# and return +true+ on success.
|
21
11
|
#
|
22
|
-
# @param (see
|
12
|
+
# @param (see Match#parse)
|
23
13
|
#
|
24
14
|
# @return [Boolean] +true+ if the decorated parser succeeds
|
25
|
-
def parse(scanner, rules, scope =
|
15
|
+
def parse(scanner, rules, scope = ParserScope.empty)
|
26
16
|
pos = scanner.pos
|
27
17
|
result = (child.parse(scanner, rules, scope) && true)
|
28
18
|
scanner.pos = pos
|
@@ -1,16 +1,9 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/atomic.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
1
|
module Rattler::Parsers
|
9
|
-
|
2
|
+
|
3
|
+
# +Atomic+ describes a parser that is not a combination of other parsers.
|
10
4
|
module Atomic #:nodoc:
|
11
5
|
|
12
|
-
#
|
13
|
-
# @return (see Parser#with_ws)
|
6
|
+
# (see Parser#with_ws)
|
14
7
|
def with_ws(ws)
|
15
8
|
ws.skip & self
|
16
9
|
end
|