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/parsers/label.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
|
# +Label+ decorates a parser and associates a label with the decorated
|
13
6
|
# parser's parse result if successful. The label only applies if nested in a
|
14
7
|
# +Choice+ or +Sequence+ decorated by an +Action+.
|
15
|
-
#
|
16
|
-
# @author Jason Arhart
|
17
|
-
#
|
18
8
|
class Label < Parser
|
19
9
|
include Combining
|
20
10
|
|
@@ -29,8 +19,12 @@ module Rattler::Parsers
|
|
29
19
|
self.new(parser, :label => label.to_sym)
|
30
20
|
end
|
31
21
|
|
32
|
-
#
|
33
|
-
|
22
|
+
# (see Parser#capturing_decidable?)
|
23
|
+
def capturing_decidable?
|
24
|
+
child.capturing_decidable?
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return +true+
|
34
28
|
def labeled?
|
35
29
|
true
|
36
30
|
end
|
@@ -38,12 +32,12 @@ module Rattler::Parsers
|
|
38
32
|
# Delegate to the decorated parser and associate #label with the parse
|
39
33
|
# result if successful.
|
40
34
|
#
|
41
|
-
# @param (see
|
35
|
+
# @param (see Match#parse)
|
42
36
|
#
|
43
37
|
# @return the decorated parser's parse result
|
44
|
-
def parse(scanner, rules, scope =
|
38
|
+
def parse(scanner, rules, scope = ParserScope.empty)
|
45
39
|
if result = child.parse(scanner, rules, scope) {|_| scope = _ }
|
46
|
-
yield scope.
|
40
|
+
yield scope.bind(label => result) if block_given?
|
47
41
|
result
|
48
42
|
end
|
49
43
|
end
|
@@ -1,21 +1,11 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/list_parser.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
|
# +ListParser+ matches terms matched by a term parser in a list with
|
13
6
|
# separators matched by a separator parser. +ListParser+ fails unless at
|
14
7
|
# least <tt>#lower_bound</tt> terms are matched and stops matching at
|
15
8
|
# <tt>#upper_bound</tt>.
|
16
|
-
#
|
17
|
-
# @author Jason Arhart
|
18
|
-
#
|
19
9
|
class ListParser < Parser
|
20
10
|
include Combining
|
21
11
|
|
@@ -25,15 +15,22 @@ module Rattler::Parsers
|
|
25
15
|
self[term_parser, sep_parser, *bounds]
|
26
16
|
end
|
27
17
|
|
18
|
+
# @param [Parser] term_parser the parser for matching list terms
|
19
|
+
# @param [Parser] sep_parser the parser for matching the list separator
|
20
|
+
# @param [Integer] lower_bound the minimum number of terms to match
|
21
|
+
# @param [Integer] upper_bound the maximum number of terms to match
|
22
|
+
# @return [ListParser] a parser that matches lists
|
28
23
|
def self.[](term_parser, sep_parser, lower_bound, upper_bound)
|
29
24
|
self.new(term_parser, sep_parser.skip,
|
30
25
|
:lower_bound => lower_bound, :upper_bound => upper_bound)
|
31
26
|
end
|
32
27
|
|
28
|
+
# @return [Parser] the parser for matching list terms
|
33
29
|
def term_parser
|
34
30
|
children[0]
|
35
31
|
end
|
36
32
|
|
33
|
+
# @return [Parser] the parser for matching the list separator
|
37
34
|
def sep_parser
|
38
35
|
children[1]
|
39
36
|
end
|
@@ -44,12 +41,12 @@ module Rattler::Parsers
|
|
44
41
|
# least <tt>#lower_bound</tt> terms are matched and stops matching at
|
45
42
|
# <tt>#upper_bound</tt>.
|
46
43
|
#
|
47
|
-
# @param (see
|
44
|
+
# @param (see Match#parse)
|
48
45
|
#
|
49
|
-
# @return [Array
|
46
|
+
# @return [Array or Boolean] an array containing the term parser's parse
|
50
47
|
# results, or +true+ if the term parser is not <tt>capturing?</tt> or
|
51
48
|
# +false+ if the parse fails.
|
52
|
-
def parse(scanner, rules, scope =
|
49
|
+
def parse(scanner, rules, scope = ParserScope.empty)
|
53
50
|
a = []
|
54
51
|
p = start_pos = scanner.pos
|
55
52
|
while result = term_parser.parse(scanner, rules, scope) and
|
@@ -67,14 +64,17 @@ module Rattler::Parsers
|
|
67
64
|
end
|
68
65
|
end
|
69
66
|
|
67
|
+
# @return [Fixnum] lower_bound the minimum number of terms to match
|
70
68
|
def lower_bound?
|
71
69
|
lower_bound > 0
|
72
70
|
end
|
73
71
|
|
72
|
+
# @return [Fixnum] upper_bound the maximum number of terms to match
|
74
73
|
def upper_bound?
|
75
74
|
not upper_bound.nil?
|
76
75
|
end
|
77
76
|
|
77
|
+
# @return +true+
|
78
78
|
def variable_capture_count?
|
79
79
|
true
|
80
80
|
end
|
@@ -1,29 +1,15 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/match.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
|
# +Match+ parses by matching with a +Regexp+. If the +Regexp+ matches at
|
13
6
|
# the parse position the entire matched string is returned, otherwise the
|
14
7
|
# parse fails.
|
15
|
-
#
|
16
|
-
# @author Jason Arhart
|
17
|
-
#
|
18
8
|
class Match < Parser
|
19
9
|
include Atomic
|
20
10
|
|
21
|
-
# Create a new parser that matches with +re+.
|
22
|
-
#
|
23
11
|
# @param [Regexp] re the pattern to match
|
24
|
-
#
|
25
12
|
# @return [Match] a new match parser that matches with +re+
|
26
|
-
#
|
27
13
|
def self.[](re)
|
28
14
|
self.new(:re => re)
|
29
15
|
end
|
@@ -36,10 +22,12 @@ module Rattler::Parsers
|
|
36
22
|
# If the +Regexp+ matches at the parse position, return the matched
|
37
23
|
# string, otherwise return a false value.
|
38
24
|
#
|
39
|
-
# @param
|
25
|
+
# @param [StringScanner] scanner the scanner for the current parse
|
26
|
+
# @param [RuleSet] rules the grammar rules being used for the current parse
|
27
|
+
# @param [ParserScope] scope the scope of captured results
|
40
28
|
#
|
41
29
|
# @return the matched string, or +nil+
|
42
|
-
def parse(scanner, rules, scope=
|
30
|
+
def parse(scanner, rules, scope = ParserScope.empty)
|
43
31
|
scanner.scan re
|
44
32
|
end
|
45
33
|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Rattler::Parsers
|
2
|
+
|
3
|
+
# +NodeAction+ is a pseudo-parser that creates a parse node object from
|
4
|
+
# captured parse results
|
5
|
+
class NodeAction < Parser
|
6
|
+
include Semantic
|
7
|
+
|
8
|
+
DEFAULT_NODE_TYPE = 'Rattler::Runtime::ParseNode'
|
9
|
+
DEFAULT_FACTORY_METHOD = :parsed
|
10
|
+
|
11
|
+
# @private
|
12
|
+
def self.parsed(results, *_) #:nodoc:
|
13
|
+
optional_node_def, optional_name = results
|
14
|
+
attrs = {}
|
15
|
+
unless optional_name.empty?
|
16
|
+
attrs[:node_attrs] = {:name => eval(optional_name[0], TOPLEVEL_BINDING)}
|
17
|
+
end
|
18
|
+
if optional_node_def.empty?
|
19
|
+
self[DEFAULT_NODE_TYPE, attrs]
|
20
|
+
else
|
21
|
+
node_type, optional_method = optional_node_def[0]
|
22
|
+
attrs[:method] = optional_method[0] unless optional_method.empty?
|
23
|
+
self[node_type, attrs]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param [String,Symbol] node_type the name of the class to instantiate
|
28
|
+
# nodes from
|
29
|
+
# @param [Hash] attrs attributes defining how to instantiate the node
|
30
|
+
# @option attrs [Hash] :node_attrs ({}) attributes to add to new parse
|
31
|
+
# nodes
|
32
|
+
# @option attrs [Strin,Symbol] :method (:parsed) the class method used to
|
33
|
+
# create new parse nodes
|
34
|
+
# @return [NodeAction] a pseudo-parser that creates parse nodes
|
35
|
+
def self.[](node_type, attrs={})
|
36
|
+
self.new(attrs.merge :node_type => node_type)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Symbol] the name of the class to instantiate nodes from
|
40
|
+
def node_type
|
41
|
+
(attrs[:node_type] || DEFAULT_NODE_TYPE).to_sym
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Hash] attributes to add to the instantiated node
|
45
|
+
def node_attrs
|
46
|
+
attrs[:node_attrs] || {}
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [Symbol] the class method used to create new parse nodes
|
50
|
+
def factory_method
|
51
|
+
(attrs[:method] || DEFAULT_FACTORY_METHOD).to_sym
|
52
|
+
end
|
53
|
+
|
54
|
+
# Create a new parse node from parse results in +scope+
|
55
|
+
#
|
56
|
+
# @param (see Match#parse)
|
57
|
+
#
|
58
|
+
# @return a new parse node created from parse results in +scope+
|
59
|
+
def parse(scanner, rules, scope = ParserScope.empty)
|
60
|
+
apply scope
|
61
|
+
end
|
62
|
+
|
63
|
+
protected
|
64
|
+
|
65
|
+
# @return [NodeCode] an object that be bound to a parser scope to return
|
66
|
+
# ruby code that creates a new node
|
67
|
+
def create_bindable_code
|
68
|
+
NodeCode.new(node_type, factory_method, node_attrs)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
@@ -1,45 +1,62 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/node_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
|
+
# +NodeCode+ defines a set of attributes that can be found to captured parse
|
6
|
+
# returns to produce ruby code that creates a new node from the parse results.
|
12
7
|
class NodeCode #:nodoc:
|
13
8
|
|
14
|
-
|
15
|
-
|
9
|
+
# @param [Symbol] node_type the name of the class to instantiate nodes from
|
10
|
+
# @param [Symbol] factory_method the class method used to create new parse
|
11
|
+
# nodes
|
12
|
+
# @param [Hash] node_attrs attributes to add to new parse nodes
|
13
|
+
def initialize(node_type, factory_method, node_attrs)
|
14
|
+
@node_type = node_type
|
15
|
+
@factory_method = factory_method
|
16
|
+
@node_attrs = node_attrs
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :node_type, :factory_method, :node_attrs
|
20
|
+
|
21
|
+
# @param [ParserScope] scope the scope of captured parse results
|
22
|
+
# @return [String] ruby code that creates a new node from the parse results
|
23
|
+
def bind(scope)
|
24
|
+
"#{node_type}.#{factory_method}(#{args_expr scope})"
|
16
25
|
end
|
17
26
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
27
|
+
# @param [ParserScope] scope the scope of captured parse results
|
28
|
+
# @return [String] ruby code for the arguments to the node factory method
|
29
|
+
def args_expr(scope)
|
30
|
+
args = [captures_expr(scope)]
|
31
|
+
attrs = encoded_binding_attrs(scope).merge encoded_node_attrs(scope)
|
32
|
+
args << encode_assocs(attrs) unless attrs.empty?
|
33
|
+
args.join(', ')
|
22
34
|
end
|
23
35
|
|
24
|
-
|
36
|
+
# @param [ParserScope] scope the scope of captured parse results
|
37
|
+
# @return [String] ruby code for the captures argument to the node factory
|
38
|
+
# method
|
39
|
+
def captures_expr(scope)
|
40
|
+
expr = '[' + scope.captures.join(', ') + ']'
|
41
|
+
scope.captures_decidable? ? expr : "select_captures(#{expr})"
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def encoded_binding_attrs(scope)
|
47
|
+
scope.bindings.empty? ? {} : { :labeled => encode_hash(scope.bindings) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def encoded_node_attrs(scope)
|
51
|
+
node_attrs.map {|k, v| {k => v.inspect} }.inject({}, &:merge)
|
52
|
+
end
|
25
53
|
|
26
|
-
def
|
27
|
-
|
28
|
-
if not scope.empty?
|
29
|
-
labeled = '{' + scope.map {|k, v| ":#{k} => #{v}"}.join(', ') + '}'
|
30
|
-
args << ":labeled => #{labeled}"
|
31
|
-
end
|
32
|
-
target_attrs.each {|k, v| args << ":#{k} => #{v.inspect}" }
|
33
|
-
t = target_name == 'self' ? '' : "#{target_name}."
|
34
|
-
"#{t}#{method_name}(#{args.join ', '})"
|
54
|
+
def encode_hash(h)
|
55
|
+
"{#{encode_assocs h}}"
|
35
56
|
end
|
36
57
|
|
37
|
-
def
|
38
|
-
|
39
|
-
bind_args
|
40
|
-
else
|
41
|
-
'[' + bind_args.join(', ') + ']'
|
42
|
-
end
|
58
|
+
def encode_assocs(h)
|
59
|
+
h.map {|k, v| ":#{k} => #{v}" }.join(', ')
|
43
60
|
end
|
44
61
|
|
45
62
|
end
|
@@ -1,79 +1,110 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/parser.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
|
# +Parser+ is the base class for all of Rattler's combinator parser types.
|
13
|
-
#
|
14
|
-
# @author Jason Arhart
|
15
|
-
#
|
16
6
|
class Parser < Rattler::Util::Node
|
17
7
|
|
8
|
+
include Rattler::Runtime::ParserHelper
|
9
|
+
|
18
10
|
# @private
|
19
11
|
def self.parsed(*args) #:nodoc:
|
20
12
|
self[*args]
|
21
13
|
end
|
22
14
|
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# @return [Boolean] +true+ if the parser returns parse results on
|
27
|
-
# success, or +false+ if the parser simply returns +true+ on success
|
15
|
+
# @return +true+ if the parser returns parse results on success, or +false+
|
16
|
+
# if the parser simply returns +true+ on success
|
28
17
|
def capturing?
|
29
18
|
true
|
30
19
|
end
|
31
20
|
|
21
|
+
# @return +true+ if the number of parse results returned by the parser
|
22
|
+
# varies based on the input
|
32
23
|
def variable_capture_count?
|
33
24
|
false
|
34
25
|
end
|
35
26
|
|
36
|
-
#
|
27
|
+
# @return +true+ if it can be determined statically whether the parser
|
28
|
+
# returns parse results on success
|
29
|
+
def capturing_decidable?
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
# +true+ if the parser associates a label with parse results. Only
|
37
34
|
# instances of +Label+ should return +true+.
|
38
35
|
#
|
39
|
-
# @return
|
36
|
+
# @return +true+ if the parser associates a label with parse
|
37
|
+
# results
|
40
38
|
def labeled?
|
41
39
|
false
|
42
40
|
end
|
43
41
|
|
42
|
+
# @return +true+ if the parser is a sequence
|
43
|
+
def sequence?
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return +true+ if the parser is a semantic action
|
48
|
+
def semantic?
|
49
|
+
false
|
50
|
+
end
|
51
|
+
|
44
52
|
# @param [Parser] other the parser to try if this parser fails.
|
45
|
-
# @return a new parser that tries this parser first and if it
|
46
|
-
# +other+
|
53
|
+
# @return [Choice] a new parser that tries this parser first and if it
|
54
|
+
# fails tries +other+
|
47
55
|
def |(other)
|
48
56
|
Choice[self, other]
|
49
57
|
end
|
50
58
|
|
51
59
|
# @param [Parser] other the next parser to try if this parser succeeds.
|
52
|
-
# @return a new parser that tries both this parser and +other+
|
53
|
-
# unless both parse in sequence
|
60
|
+
# @return [Sequence] a new parser that tries both this parser and +other+
|
61
|
+
# and fails unless both parse in sequence
|
54
62
|
def &(other)
|
55
63
|
Sequence[self, other]
|
56
64
|
end
|
57
65
|
|
58
|
-
# @
|
59
|
-
#
|
66
|
+
# @param [Parser] semantic a semantic action.
|
67
|
+
# @return [AttributedSequence] a new parser that tries this parser and
|
68
|
+
# returns the result of the semantic action if it succeeds
|
69
|
+
def >>(semantic)
|
70
|
+
AttributedSequence[self, semantic]
|
71
|
+
end
|
72
|
+
|
73
|
+
# @param [Integer] lower_bound the minimum number of times to match
|
74
|
+
# @param [Integer] upper_bound the maximum number of times to match
|
75
|
+
# @return [Repeat] a new parser that tries this parser repeatedly
|
76
|
+
def repeat(lower_bound, upper_bound)
|
77
|
+
Repeat[self, lower_bound, upper_bound]
|
78
|
+
end
|
79
|
+
|
80
|
+
# @return [Repeat] a new parser that tries this parser but returns +true+
|
81
|
+
# if it fails
|
60
82
|
def optional
|
61
|
-
|
83
|
+
repeat(0, 1)
|
62
84
|
end
|
63
85
|
|
64
|
-
# @return a new parser that tries this parser until it fails
|
65
|
-
# all of the results
|
86
|
+
# @return [Repeat] a new parser that tries this parser until it fails
|
87
|
+
# and returns all of the results
|
66
88
|
def zero_or_more
|
67
|
-
|
89
|
+
repeat(0, nil)
|
68
90
|
end
|
69
91
|
|
70
|
-
# @return a new parser that tries this parser until it fails
|
71
|
-
# all of the results if it succeeded at least once and fails
|
92
|
+
# @return [Repeat] a new parser that tries this parser until it fails
|
93
|
+
# and returns all of the results if it succeeded at least once and fails
|
94
|
+
# otherwise
|
72
95
|
def one_or_more
|
73
|
-
|
96
|
+
repeat(1, nil)
|
97
|
+
end
|
98
|
+
|
99
|
+
# @param [Parser] sep_parser the parser for matching the list separator
|
100
|
+
# @param [Integer] lower_bound the minimum number of times to match
|
101
|
+
# @param [Integer] upper_bound the maximum number of times to match
|
102
|
+
# @return [Repeat] a new parser that matches lists with this parser
|
103
|
+
def list(sep_parser, lower_bound, upper_bound)
|
104
|
+
ListParser[self, sep_parser, lower_bound, upper_bound]
|
74
105
|
end
|
75
106
|
|
76
|
-
# @return a new parser that skips over what this parser matches
|
107
|
+
# @return [Skip] a new parser that skips over what this parser matches
|
77
108
|
def skip
|
78
109
|
Skip[self]
|
79
110
|
end
|