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,20 +1,10 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/runtime/packrat_parser.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
1
|
require 'rattler/runtime'
|
9
2
|
|
10
3
|
module Rattler::Runtime
|
11
|
-
|
4
|
+
|
12
5
|
# A +PackratParser+ is a recursive descent parser that memoizes the results
|
13
6
|
# of applying nonterminal rules so that each rule method is invoked at most
|
14
7
|
# once at a given parse position.
|
15
|
-
#
|
16
|
-
# @author Jason Arhart
|
17
|
-
#
|
18
8
|
class PackratParser < RecursiveDescentParser
|
19
9
|
|
20
10
|
# Create a new packrat parser to parse +source+.
|
@@ -24,49 +14,45 @@ module Rattler::Runtime
|
|
24
14
|
#
|
25
15
|
def initialize(source, options={})
|
26
16
|
super
|
27
|
-
@memo = Hash.new {|h,
|
17
|
+
@memo = Hash.new {|h, match_method_name| h[match_method_name] = {} }
|
28
18
|
end
|
29
19
|
|
30
20
|
protected
|
31
21
|
|
32
|
-
# Apply a rule by dispatching to the
|
33
|
-
#
|
34
|
-
#
|
35
|
-
# so that the rule method is invoked at most once at a given parse
|
36
|
-
# position.
|
22
|
+
# Apply a rule by dispatching to the given match method. The result of
|
23
|
+
# applying the rule is memoized so that the match method is invoked at most
|
24
|
+
# once at a given parse position.
|
37
25
|
#
|
38
26
|
# @param (see RecursiveDescentParser#apply)
|
39
27
|
# @return (see RecursiveDescentParser#apply)
|
40
28
|
#
|
41
|
-
def apply(
|
29
|
+
def apply(match_method_name)
|
42
30
|
start_pos = @scanner.pos
|
43
|
-
if m = memo(
|
44
|
-
recall m,
|
31
|
+
if m = memo(match_method_name, start_pos)
|
32
|
+
recall m, match_method_name
|
45
33
|
else
|
46
|
-
m = inject_fail
|
47
|
-
save m, eval_rule(
|
34
|
+
m = inject_fail match_method_name, start_pos
|
35
|
+
save m, eval_rule(match_method_name)
|
48
36
|
end
|
49
37
|
end
|
50
38
|
|
51
|
-
alias_method :memoize, :apply
|
52
|
-
|
53
39
|
alias_method :eval_rule, :send
|
54
40
|
|
55
41
|
private
|
56
42
|
|
57
43
|
# @private
|
58
|
-
def memo(
|
59
|
-
@memo[
|
44
|
+
def memo(match_method_name, start_pos) #:nodoc:
|
45
|
+
@memo[match_method_name][start_pos]
|
60
46
|
end
|
61
47
|
|
62
48
|
# @private
|
63
|
-
def inject_memo(
|
64
|
-
@memo[
|
49
|
+
def inject_memo(match_method_name, start_pos, result, end_pos) #:nodoc:
|
50
|
+
@memo[match_method_name][start_pos] = MemoEntry.new(result, end_pos)
|
65
51
|
end
|
66
52
|
|
67
53
|
# @private
|
68
|
-
def inject_fail(
|
69
|
-
@memo[
|
54
|
+
def inject_fail(match_method_name, fail_pos) #:nodoc:
|
55
|
+
@memo[match_method_name][fail_pos] = MemoEntry.new(false, fail_pos)
|
70
56
|
end
|
71
57
|
|
72
58
|
# @private
|
@@ -76,7 +62,7 @@ module Rattler::Runtime
|
|
76
62
|
end
|
77
63
|
|
78
64
|
# @private
|
79
|
-
def recall(m,
|
65
|
+
def recall(m, match_method_name) #:nodoc:
|
80
66
|
@scanner.pos = m.end_pos
|
81
67
|
m.result
|
82
68
|
end
|
@@ -1,20 +1,10 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/runtime/parse_failure.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
1
|
require 'rattler/runtime'
|
9
2
|
|
10
3
|
module Rattler::Runtime
|
11
|
-
|
4
|
+
|
12
5
|
# A +ParseFailure+ represents a position and explanation of a failed parse.
|
13
|
-
#
|
14
|
-
# @author Jason Arhart
|
15
|
-
#
|
16
6
|
class ParseFailure
|
17
|
-
|
7
|
+
|
18
8
|
# Create a new parse error object.
|
19
9
|
#
|
20
10
|
# @overload initialize(source, pos)
|
@@ -46,39 +36,39 @@ module Rattler::Runtime
|
|
46
36
|
end
|
47
37
|
@lc = Rattler::Util::LineCounter.new(source)
|
48
38
|
end
|
49
|
-
|
39
|
+
|
50
40
|
attr_reader :pos, :message
|
51
|
-
|
52
|
-
#
|
53
|
-
#
|
41
|
+
|
42
|
+
# @return [Integer] the (1-based) column number where the parse error
|
43
|
+
# occurred
|
54
44
|
def column
|
55
45
|
@lc.column(pos)
|
56
46
|
end
|
57
|
-
|
58
|
-
#
|
59
|
-
#
|
47
|
+
|
48
|
+
# @return [Integer] the (1-based) line number where the parse error
|
49
|
+
# occurred
|
60
50
|
def line
|
61
51
|
@lc.line(pos)
|
62
52
|
end
|
63
|
-
|
53
|
+
|
64
54
|
# Return a string representation of the parse error suitable for showing
|
65
55
|
# to the user, e.g. "parse error at line 17, column 42: expr expected"
|
66
56
|
#
|
67
|
-
# @return [String] a string representation of the parse error suitable for
|
68
|
-
# to the user
|
57
|
+
# @return [String] a string representation of the parse error suitable for
|
58
|
+
# showing to the user
|
69
59
|
def to_s
|
70
60
|
message ? "#{intro_str}:\n #{message}" : intro_str
|
71
61
|
end
|
72
|
-
|
62
|
+
|
73
63
|
private
|
74
|
-
|
64
|
+
|
75
65
|
def intro_str
|
76
66
|
"parse error #{pos_str}"
|
77
67
|
end
|
78
|
-
|
68
|
+
|
79
69
|
def pos_str
|
80
70
|
"at line #{line}, column #{column}"
|
81
71
|
end
|
82
|
-
|
72
|
+
|
83
73
|
end
|
84
74
|
end
|
@@ -1,21 +1,11 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/runtime/parse_node.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
1
|
require 'rattler/runtime'
|
9
2
|
|
10
3
|
module Rattler::Runtime
|
11
|
-
|
4
|
+
|
12
5
|
# +ParseNode+ is intended as s a convenient class to use as a parsing
|
13
6
|
# result type.
|
14
|
-
#
|
15
|
-
# @author Jason Arhart
|
16
|
-
#
|
17
7
|
class ParseNode < Rattler::Util::Node
|
18
|
-
|
8
|
+
|
19
9
|
# Create a parse node from the results of a parsing expression.
|
20
10
|
#
|
21
11
|
# @param [Array] children the children of the parse node
|
@@ -26,7 +16,7 @@ module Rattler::Runtime
|
|
26
16
|
def self.parsed(children, attrs={})
|
27
17
|
self.new(children, attrs.reject {|_, val| val.nil? })
|
28
18
|
end
|
29
|
-
|
19
|
+
|
30
20
|
# Access the parse node's children.
|
31
21
|
#
|
32
22
|
# @overload [](index)
|
@@ -55,13 +45,13 @@ module Rattler::Runtime
|
|
55
45
|
super
|
56
46
|
end
|
57
47
|
end
|
58
|
-
|
48
|
+
|
59
49
|
# Return a hash associating labels with the labeled children
|
60
50
|
# @return [Hash] a hash associating labels with the labeled children
|
61
51
|
def labeled
|
62
52
|
attrs.fetch(:labeled, {})
|
63
53
|
end
|
64
|
-
|
54
|
+
|
65
55
|
# Return +true+ if the node has the same value as +other+, i.e. +other+
|
66
56
|
# is an instance of the same class and has equal children and attributes
|
67
57
|
# and the children are labeled the same.
|
@@ -71,16 +61,16 @@ module Rattler::Runtime
|
|
71
61
|
super &&
|
72
62
|
self.labeled == other.labeled
|
73
63
|
end
|
74
|
-
|
64
|
+
|
75
65
|
# Allow labeled children to be accessed as methods.
|
76
66
|
def method_missing(symbol, *args)
|
77
67
|
(args.empty? and labeled.has_key?(symbol)) ? labeled[symbol] : super
|
78
68
|
end
|
79
|
-
|
69
|
+
|
80
70
|
# @private
|
81
71
|
def respond_to?(symbol) #:nodoc:
|
82
72
|
super || labeled.has_key?(symbol)
|
83
73
|
end
|
84
|
-
|
74
|
+
|
85
75
|
end
|
86
76
|
end
|
@@ -1,19 +1,9 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/runtime/parser.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
1
|
require 'rattler/runtime'
|
9
2
|
require 'strscan'
|
10
3
|
|
11
4
|
module Rattler::Runtime
|
12
|
-
|
5
|
+
|
13
6
|
# +Parser+ is the base class for all parsers in the Rattler framework.
|
14
|
-
#
|
15
|
-
# @author Jason Arhart
|
16
|
-
#
|
17
7
|
class Parser < Rattler::Util::Node
|
18
8
|
|
19
9
|
# Parse +source+ and raise a {SyntaxError} if the parse fails.
|
@@ -38,15 +28,14 @@ module Rattler::Runtime
|
|
38
28
|
# Create a new parser to parse +source+.
|
39
29
|
#
|
40
30
|
# @param [String] source the source to parse
|
41
|
-
# @option options [
|
42
|
-
# numbers
|
31
|
+
# @option options [Integer] :tab_size (8) tab size to use to calculate
|
32
|
+
# column numbers
|
43
33
|
def initialize(source, options={})
|
44
34
|
@source = source
|
45
35
|
@scanner = StringScanner.new(source)
|
46
36
|
@tab_size = options[:tab_size]
|
47
37
|
end
|
48
38
|
|
49
|
-
# The source that this parser parses
|
50
39
|
# @return [String] the source that this parser parses
|
51
40
|
attr_reader :source
|
52
41
|
|
@@ -84,15 +73,14 @@ module Rattler::Runtime
|
|
84
73
|
parse_fully or raise_error
|
85
74
|
end
|
86
75
|
|
87
|
-
#
|
88
|
-
# @return [Integer] the current parse position
|
76
|
+
# @return [Fixnum] the current parse position
|
89
77
|
def pos
|
90
78
|
@scanner.pos
|
91
79
|
end
|
92
80
|
|
93
81
|
# Set the current parse position
|
94
82
|
# @param [Integer] n the new parse position
|
95
|
-
# @return [
|
83
|
+
# @return [Fixnum] the new parse position
|
96
84
|
def pos=(n)
|
97
85
|
@scanner.pos = n
|
98
86
|
end
|
@@ -167,7 +155,7 @@ module Rattler::Runtime
|
|
167
155
|
# Register a parse failure
|
168
156
|
#
|
169
157
|
# @param [Integer] position the position of the failure
|
170
|
-
# @param [String, Symbol] a failure message or rule name or +nil+
|
158
|
+
# @param [String, Symbol] message a failure message or rule name or +nil+
|
171
159
|
#
|
172
160
|
# @return [false]
|
173
161
|
def register_failure(position, message)
|
@@ -1,19 +1,12 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/runtime/parser_helper.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
1
|
require 'rattler/runtime'
|
9
2
|
|
10
3
|
module Rattler::Runtime
|
11
4
|
# @private
|
12
5
|
module ParserHelper #:nodoc:
|
13
|
-
|
6
|
+
|
14
7
|
def select_captures(results)
|
15
|
-
results.reject {|_| _
|
8
|
+
results.reject {|_| _.equal? true }
|
16
9
|
end
|
17
|
-
|
10
|
+
|
18
11
|
end
|
19
12
|
end
|
@@ -1,24 +1,20 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/runtime/recursive_descent_parser.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
1
|
require 'rattler/runtime'
|
9
2
|
|
10
3
|
module Rattler::Runtime
|
11
|
-
|
4
|
+
|
12
5
|
# +RecursiveDescentParser+ is the base class for any recursive descent
|
13
6
|
# parsers. It supports unlimited backtracking, which may result in rules
|
14
7
|
# being applied to the same source many times. It is usually preferable to
|
15
8
|
# use {PackratParser}, which memoizes parse results.
|
16
|
-
#
|
17
|
-
# @author Jason Arhart
|
18
|
-
#
|
19
9
|
class RecursiveDescentParser < Parser
|
20
10
|
include ParserHelper
|
21
|
-
|
11
|
+
|
12
|
+
class <<self
|
13
|
+
private
|
14
|
+
def grammar(source)
|
15
|
+
Rattler.compile(self, source)
|
16
|
+
end
|
17
|
+
end
|
22
18
|
|
23
19
|
# Create a new recursive descent parser to parse +source+.
|
24
20
|
#
|
@@ -30,22 +26,25 @@ module Rattler::Runtime
|
|
30
26
|
@rule_method_names = Hash.new {|h, name| h[name] = :"match_#{name}" }
|
31
27
|
end
|
32
28
|
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# @return (see #apply)
|
29
|
+
# Attempt to match the source by applying the named parse rule and return
|
30
|
+
# the result. If the rule is successfully matched the result is "thruthy".
|
31
|
+
# If the rules captures parse results, the captured results are returned,
|
32
|
+
# otherwise the result is +true+. If the rule fails to match, the result
|
33
|
+
# may be +false+ or +nil+.
|
39
34
|
#
|
35
|
+
# @param [Symbol] rule_name the name of the parse rule.
|
36
|
+
# @return the result of applying the parse rule.
|
40
37
|
def match(rule_name)
|
41
|
-
send @rule_method_names[rule_name]
|
38
|
+
send @rule_method_names[rule_name]
|
42
39
|
end
|
43
40
|
|
44
|
-
|
41
|
+
# @private
|
42
|
+
def method_missing(symbol, *args) #:nodoc:
|
45
43
|
(symbol == :start_rule) ? :start : super
|
46
44
|
end
|
47
45
|
|
48
|
-
|
46
|
+
# @private
|
47
|
+
def respond_to?(symbol) #:nodoc:
|
49
48
|
super or (symbol == :start_rule)
|
50
49
|
end
|
51
50
|
|
@@ -59,8 +58,12 @@ module Rattler::Runtime
|
|
59
58
|
match start_rule
|
60
59
|
end
|
61
60
|
|
62
|
-
|
63
|
-
|
61
|
+
# Apply a rule by directly dispatching to the given match method.
|
62
|
+
#
|
63
|
+
# @param [Symbol] match_method_name the name of the match method.
|
64
|
+
# @return the result of applying the parse rule.
|
65
|
+
def apply(match_method_name)
|
66
|
+
send match_method_name
|
64
67
|
end
|
65
68
|
|
66
69
|
end
|
@@ -1,17 +1,7 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/runtime/syntax_error.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
1
|
require 'rattler/runtime'
|
9
2
|
|
10
3
|
module Rattler::Runtime
|
11
4
|
# +SyntaxError+ is raised by {Parser#raise_error} to indicate a failed parse.
|
12
|
-
#
|
13
|
-
# @author Jason Arhart
|
14
|
-
#
|
15
5
|
class SyntaxError < RuntimeError
|
16
6
|
end
|
17
7
|
end
|
data/lib/rattler/util.rb
CHANGED
@@ -1,9 +1,3 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/util.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
1
|
require 'rattler'
|
8
2
|
|
9
3
|
module Rattler
|
@@ -12,6 +6,8 @@ module Rattler
|
|
12
6
|
autoload :LineCounter, 'rattler/util/line_counter'
|
13
7
|
autoload :Node, 'rattler/util/node'
|
14
8
|
autoload :ParserSpecHelper, 'rattler/util/parser_spec_helper'
|
9
|
+
autoload :ParserCLI, 'rattler/util/parser_cli'
|
10
|
+
autoload :GrammarCLI, 'rattler/util/grammar_cli'
|
15
11
|
autoload :GraphViz, 'rattler/util/graphviz'
|
16
12
|
end
|
17
13
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rattler/util'
|
2
|
+
|
3
|
+
module Rattler::Util
|
4
|
+
|
5
|
+
# +GrammarCLI+ defines a command line interface for generated grammars.
|
6
|
+
class GrammarCLI < ParserCLI
|
7
|
+
|
8
|
+
# Create a new command line interface for the given grammar module
|
9
|
+
#
|
10
|
+
# @param [Module] grammar_module the grammar module to run the command line
|
11
|
+
# interface for
|
12
|
+
def initialize(grammar_module)
|
13
|
+
parser_class = Class.new(Rattler::Runtime::ExtendedPackratParser)
|
14
|
+
parser_class.module_eval { include grammar_module }
|
15
|
+
super(parser_class)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|