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,183 +0,0 @@
|
|
1
|
-
require 'rattler/grammar'
|
2
|
-
|
3
|
-
grammar Rattler::Grammar::Metagrammar
|
4
|
-
|
5
|
-
include Rattler::Parsers
|
6
|
-
|
7
|
-
%whitespace (SPACE+ / comment)* {
|
8
|
-
|
9
|
-
grammar <- heading rules EOF <Grammar>
|
10
|
-
|
11
|
-
heading <- requires module_decl? includes { heading *_ }
|
12
|
-
|
13
|
-
requires <- (~`require` @(!eol .)+ ~eol)* { { :requires => _ } }
|
14
|
-
|
15
|
-
module_decl <- ~`parser` constant (~'<' constant)? ~eol { parser_decl *_ }
|
16
|
-
/ ~`grammar` constant ~eol { { :grammar_name => _ } }
|
17
|
-
|
18
|
-
includes <- (~`include` constant ~eol)* { { :includes => _ } }
|
19
|
-
|
20
|
-
rules <- (directive / rule / block_close)+ <RuleSet>
|
21
|
-
|
22
|
-
directive <- ws_directive / wc_directive / inline_directive
|
23
|
-
|
24
|
-
ws_directive <- ws_decl ~'{' { start_ws _ }
|
25
|
-
/ ws_decl { set_ws _ }
|
26
|
-
|
27
|
-
ws_decl <- ~`%whitespace` unattributed
|
28
|
-
|
29
|
-
wc_directive <- wc_decl ~'{' { start_wc _ }
|
30
|
-
/ wc_decl { set_wc _ }
|
31
|
-
|
32
|
-
wc_decl <- ~`%word_character` unattributed
|
33
|
-
|
34
|
-
inline_directive <- ~`%inline` ~'{' { start_inline }
|
35
|
-
/ ~`%inline` { set_inline }
|
36
|
-
|
37
|
-
block_close <- ~'}' { end_block }
|
38
|
-
|
39
|
-
rule <- identifier ~'<-' expression { rule *_ }
|
40
|
-
|
41
|
-
unattributed <- unattributed ~'/' terms <Choice>
|
42
|
-
/ terms
|
43
|
-
|
44
|
-
expression <- expression ~'/' attributed <Choice>
|
45
|
-
/ attributed
|
46
|
-
|
47
|
-
attributed <- attributed? ~'<' node_action? literal? ~'>' <DispatchAction>
|
48
|
-
/ attributed? ~'{' action ~'}' <DirectAction>
|
49
|
-
/ attributed? ~'~' ~'{' action ~'}' <SideEffect>
|
50
|
-
/ attributed? ~'&' ~'{' action ~'}' <SemanticAssert>
|
51
|
-
/ attributed? ~'!' ~'{' action ~'}' <SemanticDisallow>
|
52
|
-
/ attributed_terms
|
53
|
-
|
54
|
-
node_action <- @(name (~'.' var_name)?)
|
55
|
-
|
56
|
-
action <- @(( '{' [^}]* '}'
|
57
|
-
/ [^{}] )*)
|
58
|
-
|
59
|
-
attributed_terms <- attributed term <Sequence>
|
60
|
-
/ terms
|
61
|
-
|
62
|
-
terms <- terms term <Sequence>
|
63
|
-
/ term
|
64
|
-
|
65
|
-
term <- fail_expr / labeled / labelable
|
66
|
-
|
67
|
-
fail_expr <- (`fail` / `fail_rule` / `fail_parse`) fail_arg <Fail>
|
68
|
-
|
69
|
-
fail_arg <- ~'(' literal ~')'
|
70
|
-
/ literal
|
71
|
-
|
72
|
-
labeled <- var_name ~':' labelable <Label>
|
73
|
-
|
74
|
-
labelable <- list
|
75
|
-
/ list_term
|
76
|
-
|
77
|
-
list <- list_term ~('*' ',') list_term { list0 *_ }
|
78
|
-
/ list_term ~('+' ',') list_term { list1 *_ }
|
79
|
-
/ list_term repeat_count ~',' list_term <ListParser>
|
80
|
-
|
81
|
-
list_term <- prefixed
|
82
|
-
/ prefixable
|
83
|
-
/ fail 'term expected'
|
84
|
-
|
85
|
-
prefixed <- ~'&' prefixable <Assert>
|
86
|
-
/ ~'!' prefixable <Disallow>
|
87
|
-
/ ~'~' prefixable <Skip>
|
88
|
-
/ ~'@' prefixable <Token>
|
89
|
-
|
90
|
-
prefixable <- suffixed / primary
|
91
|
-
|
92
|
-
suffixed <- primary ~'?' { optional _ }
|
93
|
-
/ primary ~'*' !',' { zero_or_more _ }
|
94
|
-
/ primary ~'+' !',' { one_or_more _ }
|
95
|
-
/ primary repeat_count !',' <Repeat>
|
96
|
-
|
97
|
-
repeat_count <- @DIGIT+ ~'..' @DIGIT+ { _.map {|s| s.to_i } }
|
98
|
-
/ @DIGIT+ ~'..' { [_.to_i, nil] }
|
99
|
-
/ @DIGIT+ { [_.to_i] * 2 }
|
100
|
-
|
101
|
-
primary <- ~'(' expression ~')'
|
102
|
-
/ atom
|
103
|
-
|
104
|
-
atom <- ~`EOF` <Eof>
|
105
|
-
/ ~`E` <ESymbol>
|
106
|
-
/ posix_class { posix_class _ }
|
107
|
-
/ identifier !'<-' <Apply>
|
108
|
-
/ literal { literal _ }
|
109
|
-
/ word_literal { word_literal _ }
|
110
|
-
/ class { char_class _ }
|
111
|
-
/ back_reference <BackReference>
|
112
|
-
/ ~'.' { Match[/./] }
|
113
|
-
/ fail 'atom expected'
|
114
|
-
|
115
|
-
%inline
|
116
|
-
|
117
|
-
posix_class <- `ALNUM`
|
118
|
-
/ `ALPHA`
|
119
|
-
/ `ASCII`
|
120
|
-
/ `BLANK`
|
121
|
-
/ `CNTRL`
|
122
|
-
/ `DIGIT`
|
123
|
-
/ `GRAPH`
|
124
|
-
/ `LOWER`
|
125
|
-
/ `PRINT`
|
126
|
-
/ `PUNCT`
|
127
|
-
/ `SPACE`
|
128
|
-
/ `UPPER`
|
129
|
-
/ `XDIGIT`
|
130
|
-
/ `WORD`
|
131
|
-
/ fail 'posix_class expected'
|
132
|
-
|
133
|
-
literal <- @('"' ('\\' . / [^"])* '"')
|
134
|
-
/ @("'" ('\\' . / [^'])* "'")
|
135
|
-
/ @('%(' ('\\' . / [^)])* ')')
|
136
|
-
/ @('%{' ('\\' . / [^}])* '}')
|
137
|
-
/ @('%[' ('\\' . / [^\]])* ']')
|
138
|
-
/ @('%<' ('\\' . / [^>])* '>')
|
139
|
-
/ @('%' q:PUNCT ('\\' . / !$q .)* $q)
|
140
|
-
|
141
|
-
word_literal <- @("`" ('\\' . / [^`])* "`")
|
142
|
-
|
143
|
-
class <- @('[' (!']' range)+ ']')
|
144
|
-
|
145
|
-
name <- var_name
|
146
|
-
/ constant
|
147
|
-
|
148
|
-
identifier <- !`EOF` @(ALPHA WORD*)
|
149
|
-
|
150
|
-
back_reference <- @('$' LOWER WORD*)
|
151
|
-
|
152
|
-
var_name <- @(LOWER WORD*)
|
153
|
-
|
154
|
-
constant <- @((UPPER WORD* '::')* UPPER WORD*)
|
155
|
-
|
156
|
-
const_name <- @(UPPER WORD*)
|
157
|
-
}
|
158
|
-
|
159
|
-
range <- @( '[:' posix_name ':]'
|
160
|
-
/ class_char ('-' class_char)?)
|
161
|
-
|
162
|
-
posix_name <- `alnum`
|
163
|
-
/ `alpha`
|
164
|
-
/ `ascii`
|
165
|
-
/ `blank`
|
166
|
-
/ `cntrl`
|
167
|
-
/ `digit`
|
168
|
-
/ `graph`
|
169
|
-
/ `lower`
|
170
|
-
/ `print`
|
171
|
-
/ `punct`
|
172
|
-
/ `space`
|
173
|
-
/ `upper`
|
174
|
-
/ `xdigit`
|
175
|
-
|
176
|
-
class_char <- @( '\\' [0-3] [0-7] [0-7]
|
177
|
-
/ '\\x' XDIGIT XDIGIT
|
178
|
-
/ '\\' .
|
179
|
-
/ [^\\\]] )
|
180
|
-
|
181
|
-
eol <- ~(BLANK* (EOF / ';' / ("\r"? "\n") / comment))
|
182
|
-
|
183
|
-
comment <- ~('#' [^\n]*)
|
@@ -1,31 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/assert_code.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
|
-
require 'rattler/parsers'
|
9
|
-
|
10
|
-
module Rattler::Parsers
|
11
|
-
# @private
|
12
|
-
class AssertCode < ActionCode #:nodoc:
|
13
|
-
|
14
|
-
def bind(scope, bind_args)
|
15
|
-
"(#{super}) && #{result_code bind_args}"
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def result_code(bind_args)
|
21
|
-
if bind_args.size > 1
|
22
|
-
'[' + bind_args.join(', ') + ']'
|
23
|
-
elsif bind_args.size == 1
|
24
|
-
bind_args.first
|
25
|
-
else
|
26
|
-
'true'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/direct_action.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
|
-
require 'rattler/parsers'
|
9
|
-
|
10
|
-
module Rattler::Parsers
|
11
|
-
#
|
12
|
-
# +DirectAction+ decorates a parser to peform a symantic action on success by
|
13
|
-
# evaluating ruby code.
|
14
|
-
#
|
15
|
-
# @author Jason Arhart
|
16
|
-
#
|
17
|
-
class DirectAction < Parser
|
18
|
-
include Combining
|
19
|
-
|
20
|
-
def self.[](child, code)
|
21
|
-
self.new(child, :code => code.strip)
|
22
|
-
end
|
23
|
-
|
24
|
-
# @private
|
25
|
-
def self.parsed(results, *_) #:nodoc:
|
26
|
-
optional_expr, code = results
|
27
|
-
expr = optional_expr.first || ESymbol[]
|
28
|
-
self[expr, code]
|
29
|
-
end
|
30
|
-
|
31
|
-
# If the wrapped parser matches at the parse position, return the result
|
32
|
-
# of applying the symantic action, otherwise return a false value.
|
33
|
-
#
|
34
|
-
# @param (see Parser#parse_labeled)
|
35
|
-
#
|
36
|
-
# @return the result of applying the symantic action, or a false value if
|
37
|
-
# the parse failed.
|
38
|
-
def parse(scanner, rules, scope = {})
|
39
|
-
if result = parse_child(child, scanner, rules, scope) {|_| scope = _ }
|
40
|
-
if not child.capturing?
|
41
|
-
apply([])
|
42
|
-
elsif result.respond_to?(:to_ary)
|
43
|
-
apply(result, scope)
|
44
|
-
else
|
45
|
-
apply([result], scope)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def bindable_code
|
51
|
-
@bindable_code ||= create_bindable_code
|
52
|
-
end
|
53
|
-
|
54
|
-
def bind(scope, bind_args)
|
55
|
-
bindable_code.bind(scope, bind_args)
|
56
|
-
end
|
57
|
-
|
58
|
-
protected
|
59
|
-
|
60
|
-
def create_bindable_code
|
61
|
-
ActionCode.new(code)
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
def parse_child(child, scanner, rules, scope)
|
67
|
-
if child.is_a? Sequence
|
68
|
-
child.parse_and_yield_scope(scanner, rules, scope) {|_| yield _ }
|
69
|
-
else
|
70
|
-
child.parse(scanner, rules, scope) {|_| yield _ }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def apply(results, scope={})
|
75
|
-
code_scope = {}
|
76
|
-
scope.each {|k, v| code_scope[k] = v.inspect }
|
77
|
-
if child.variable_capture_count?
|
78
|
-
eval(bind(code_scope, [results.inspect]))
|
79
|
-
else
|
80
|
-
eval(bind(code_scope, results.map {|_| _.inspect }))
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/disallow_code.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
|
-
require 'rattler/parsers'
|
9
|
-
|
10
|
-
module Rattler::Parsers
|
11
|
-
# @private
|
12
|
-
class DisallowCode < ActionCode #:nodoc:
|
13
|
-
|
14
|
-
def bind(scope, bind_args)
|
15
|
-
"!(#{super}) && #{result_code bind_args}"
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def result_code(bind_args)
|
21
|
-
if bind_args.size > 1
|
22
|
-
'[' + bind_args.join(', ') + ']'
|
23
|
-
elsif bind_args.size == 1
|
24
|
-
bind_args.first
|
25
|
-
else
|
26
|
-
'true'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/dispatch_action.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
|
-
require 'rattler/parsers'
|
9
|
-
|
10
|
-
module Rattler::Parsers
|
11
|
-
#
|
12
|
-
# +DispatchAction+ decorates a parser to peform a symantic action on success
|
13
|
-
# by dispatching to a method.
|
14
|
-
#
|
15
|
-
# @author Jason Arhart
|
16
|
-
#
|
17
|
-
class DispatchAction < Parser
|
18
|
-
include Combining
|
19
|
-
|
20
|
-
# @private
|
21
|
-
@@node_defaults = {
|
22
|
-
:target => 'Rattler::Runtime::ParseNode',
|
23
|
-
:method => 'parsed'
|
24
|
-
}
|
25
|
-
|
26
|
-
# @private
|
27
|
-
def self.parsed(results, *_) #:nodoc:
|
28
|
-
optional_expr, optional_attribute, optional_name = results
|
29
|
-
expr = optional_expr.first || ESymbol[]
|
30
|
-
a = self[expr, optional_attribute.first || @@node_defaults[:target]]
|
31
|
-
unless optional_name.empty?
|
32
|
-
a.with_attrs(:target_attrs => {:name => eval(optional_name.first, TOPLEVEL_BINDING)})
|
33
|
-
else
|
34
|
-
a
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# @private
|
39
|
-
def self.parse_attrs_arg(arg) #:nodoc:
|
40
|
-
case arg
|
41
|
-
when Hash
|
42
|
-
arg
|
43
|
-
when /^\s*(.+?)\s*\.\s*(.+?)\s*$/
|
44
|
-
{ :target => $1, :method => $2 }
|
45
|
-
else
|
46
|
-
{ :target => arg.to_s.strip }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Create a new parser that decorates a parser to peform a symantic
|
51
|
-
# on success.
|
52
|
-
#
|
53
|
-
# @overload initialize(parser, opts={})
|
54
|
-
# @param [Parser] parser
|
55
|
-
# @option opts [String] target ('Rattler::Runtime::ParseNode') the
|
56
|
-
# object on which to invoke a method as the symantic action
|
57
|
-
# @option opts [String] method ('parsed') the name of the method to
|
58
|
-
# invoke as the symantic action
|
59
|
-
#
|
60
|
-
# @overload initialize(method_spec)
|
61
|
-
# @param [String] method_spec a specification of the target and optional
|
62
|
-
# method name separated by "."
|
63
|
-
#
|
64
|
-
def initialize(children, attrs_arg={})
|
65
|
-
super(children, self.class.parse_attrs_arg(attrs_arg))
|
66
|
-
@@node_defaults.each {|k, v| attrs[k] ||= v } unless attrs[:code]
|
67
|
-
@method_name = attrs[:method]
|
68
|
-
@target_attrs = attrs[:target_attrs] || {}
|
69
|
-
end
|
70
|
-
|
71
|
-
# the name of the method used as the symantic action
|
72
|
-
attr_reader :method_name, :target_attrs
|
73
|
-
|
74
|
-
# If the wrapped parser matches at the parse position, return the result
|
75
|
-
# of applying the symantic action, otherwise return a false value.
|
76
|
-
#
|
77
|
-
# @param (see Parser#parse_labeled)
|
78
|
-
#
|
79
|
-
# @return the result of applying the symantic action, or a false value if
|
80
|
-
# the parse failed.
|
81
|
-
def parse(scanner, rules, scope = {})
|
82
|
-
if result = parse_child(child, scanner, rules, scope) {|_| scope = _ }
|
83
|
-
if not capturing?
|
84
|
-
apply([])
|
85
|
-
elsif result.respond_to?(:to_ary)
|
86
|
-
apply(result, scope)
|
87
|
-
else
|
88
|
-
apply([result], scope)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def bindable_code
|
94
|
-
@bindable_code ||= NodeCode.new(target, method_name, target_attrs)
|
95
|
-
end
|
96
|
-
|
97
|
-
def bind(scope, bind_args)
|
98
|
-
bindable_code.bind(scope, bind_args)
|
99
|
-
end
|
100
|
-
|
101
|
-
private
|
102
|
-
|
103
|
-
def parse_child(child, scanner, rules, scope)
|
104
|
-
if child.is_a? Sequence
|
105
|
-
child.parse_and_yield_scope(scanner, rules, scope) {|_| yield _ }
|
106
|
-
else
|
107
|
-
child.parse(scanner, rules, scope) {|_| yield _ }
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def apply(results, scope={})
|
112
|
-
attrs = scope.empty? ? {} : {:labeled => scope}
|
113
|
-
target_class.send method_name, results, attrs
|
114
|
-
end
|
115
|
-
|
116
|
-
def target_class
|
117
|
-
@target_class ||= target.split('::').inject(Kernel, :const_get)
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
end
|