rattler 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -175
- data/features/README.markdown +27 -0
- data/features/Tutorial.md +224 -0
- data/features/command_line/output_option.feature +2 -1
- data/features/command_line/{parser_generator.feature → rtlr.feature} +43 -15
- data/features/error_reporting/automatic_error_messages.feature +40 -0
- data/features/error_reporting/custom_error_messages.feature +28 -0
- data/features/examples/json_parser.markdown +88 -0
- data/features/{grammar → extended_matching_syntax}/back_reference.feature +5 -3
- data/features/{grammar → extended_matching_syntax}/e_symbol.feature +2 -2
- data/features/{grammar → extended_matching_syntax}/eof.feature +4 -3
- data/features/{grammar → extended_matching_syntax}/fail.feature +8 -6
- data/features/extended_matching_syntax/fragments.feature +29 -0
- data/features/extended_matching_syntax/include.feature +42 -0
- data/features/{grammar → extended_matching_syntax}/list_matching.feature +7 -6
- data/features/extended_matching_syntax/posix_class.feature +127 -0
- data/features/{grammar → extended_matching_syntax}/repeat.feature +29 -3
- data/features/{grammar → extended_matching_syntax}/skip_operator.feature +2 -1
- data/features/extended_matching_syntax/super.feature +24 -0
- data/features/{grammar → extended_matching_syntax}/token.feature +6 -5
- data/features/{grammar → extended_matching_syntax}/whitespace.feature +7 -6
- data/features/{grammar → extended_matching_syntax}/word_literal.feature +10 -6
- data/features/grammar_heading/explicit_start_rule.feature +20 -0
- data/features/grammar_heading/grammar_declaration.feature +60 -0
- data/features/grammar_heading/include.feature +19 -0
- data/features/grammar_heading/require.feature +27 -0
- data/features/{grammar → peg_syntax}/any_character.feature +1 -1
- data/features/peg_syntax/character_class.feature +25 -0
- data/features/{grammar → peg_syntax}/comments.feature +1 -1
- data/features/{grammar → peg_syntax}/literal.feature +5 -3
- data/features/{grammar → peg_syntax}/negative_lookahead.feature +5 -3
- data/features/peg_syntax/nonterminal.feature +46 -0
- data/features/peg_syntax/one_or_more.feature +59 -0
- data/features/{grammar → peg_syntax}/optional.feature +2 -2
- data/features/peg_syntax/ordered_choice.feature +24 -0
- data/features/{grammar → peg_syntax}/positive_lookahead.feature +6 -4
- data/features/peg_syntax/sequence.feature +23 -0
- data/features/{grammar → peg_syntax}/start_rule.feature +1 -1
- data/features/peg_syntax/zero_or_more.feature +59 -0
- data/features/{grammar → semantics}/labels.feature +0 -0
- data/features/{grammar → semantics}/negative_semantic_predicate.feature +30 -9
- data/features/{grammar → semantics}/node_action.feature +0 -0
- data/features/{grammar → semantics}/positive_semantic_predicate.feature +29 -8
- data/features/{grammar/symantic_action.feature → semantics/semantic_action.feature} +2 -2
- data/features/semantics/semantic_result.feature +86 -0
- data/features/{grammar → semantics}/side_effect.feature +33 -21
- data/features/step_definitions/cli_steps.rb +1 -1
- data/features/step_definitions/grammar_steps.rb +19 -5
- data/features/support/env.rb +5 -0
- data/lib/rattler.rb +21 -44
- data/lib/rattler/compiler.rb +69 -0
- data/lib/rattler/{grammar → compiler}/grammar_parser.rb +58 -24
- data/lib/rattler/compiler/metagrammar.rb +1570 -0
- data/lib/rattler/compiler/optimizer.rb +77 -0
- data/lib/rattler/{back_end → compiler}/optimizer/composite_reducing.rb +2 -2
- data/lib/rattler/{back_end → compiler}/optimizer/flatten_choice.rb +3 -12
- data/lib/rattler/{back_end → compiler}/optimizer/flatten_sequence.rb +4 -16
- data/lib/rattler/{back_end → compiler}/optimizer/flattening.rb +2 -2
- data/lib/rattler/compiler/optimizer/inline_regular_rules.rb +24 -0
- data/lib/rattler/{back_end → compiler}/optimizer/join_match_capturing_sequence.rb +16 -14
- data/lib/rattler/{back_end → compiler}/optimizer/join_match_choice.rb +4 -13
- data/lib/rattler/{back_end → compiler}/optimizer/join_match_matching_sequence.rb +4 -13
- data/lib/rattler/compiler/optimizer/join_match_sequence.rb +7 -0
- data/lib/rattler/{back_end → compiler}/optimizer/join_predicate_bare_match.rb +3 -12
- data/lib/rattler/compiler/optimizer/join_predicate_match.rb +7 -0
- data/lib/rattler/{back_end → compiler}/optimizer/join_predicate_nested_match.rb +4 -13
- data/lib/rattler/{back_end → compiler}/optimizer/join_predicate_or_bare_match.rb +3 -12
- data/lib/rattler/compiler/optimizer/join_predicate_or_match.rb +7 -0
- data/lib/rattler/{back_end → compiler}/optimizer/join_predicate_or_nested_match.rb +4 -13
- data/lib/rattler/{back_end → compiler}/optimizer/match_joining.rb +2 -2
- data/lib/rattler/{back_end → compiler}/optimizer/optimization.rb +12 -34
- data/lib/rattler/compiler/optimizer/optimization_context.rb +83 -0
- data/lib/rattler/{back_end → compiler}/optimizer/optimization_sequence.rb +3 -11
- data/lib/rattler/compiler/optimizer/optimizations.rb +27 -0
- data/lib/rattler/{back_end → compiler}/optimizer/optimize_children.rb +6 -14
- data/lib/rattler/{back_end → compiler}/optimizer/reduce_repeat_match.rb +4 -13
- data/lib/rattler/compiler/optimizer/remove_meaningless_wrapper.rb +22 -0
- data/lib/rattler/{back_end → compiler}/optimizer/simplify_redundant_repeat.rb +4 -13
- data/lib/rattler/{back_end → compiler}/optimizer/simplify_token_match.rb +4 -13
- data/lib/rattler/compiler/parser_generator.rb +108 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/apply_generator.rb +7 -21
- data/lib/rattler/{back_end → compiler}/parser_generator/assert_generator.rb +11 -19
- data/lib/rattler/compiler/parser_generator/attributed_sequence_generator.rb +37 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/back_reference_generator.rb +10 -10
- data/lib/rattler/{back_end → compiler}/parser_generator/choice_generator.rb +10 -22
- data/lib/rattler/{back_end → compiler}/parser_generator/delegating_generator.rb +2 -2
- data/lib/rattler/{back_end → compiler}/parser_generator/disallow_generator.rb +11 -19
- data/lib/rattler/{back_end → compiler}/parser_generator/e_symbol_generator.rb +2 -10
- data/lib/rattler/{back_end → compiler}/parser_generator/eof_generator.rb +2 -10
- data/lib/rattler/{back_end → compiler}/parser_generator/expr_generator.rb +9 -35
- data/lib/rattler/{back_end → compiler}/parser_generator/fail_generator.rb +7 -3
- data/lib/rattler/{back_end → compiler}/parser_generator/gen_method_names.rb +3 -5
- data/lib/rattler/{back_end → compiler}/parser_generator/general_list_generator.rb +6 -18
- data/lib/rattler/{back_end → compiler}/parser_generator/general_repeat_generator.rb +16 -22
- data/lib/rattler/{back_end/parser_generator/rule_set_generator.rb → compiler/parser_generator/grammar_generator.rb} +24 -33
- data/lib/rattler/compiler/parser_generator/group_match.rb +33 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/group_match_generator.rb +4 -17
- data/lib/rattler/compiler/parser_generator/label_generator.rb +37 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/list0_generating.rb +5 -5
- data/lib/rattler/{back_end → compiler}/parser_generator/list1_generating.rb +3 -3
- data/lib/rattler/{back_end → compiler}/parser_generator/list_generator.rb +2 -2
- data/lib/rattler/{back_end → compiler}/parser_generator/match_generator.rb +10 -10
- data/lib/rattler/{back_end → compiler}/parser_generator/nested.rb +2 -2
- data/lib/rattler/compiler/parser_generator/node_action_generator.rb +49 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/one_or_more_generating.rb +3 -3
- data/lib/rattler/{back_end → compiler}/parser_generator/optional_generating.rb +6 -22
- data/lib/rattler/compiler/parser_generator/predicate_propogating.rb +24 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/repeat_generator.rb +2 -2
- data/lib/rattler/compiler/parser_generator/rule_generator.rb +66 -0
- data/lib/rattler/compiler/parser_generator/rule_set_generator.rb +33 -0
- data/lib/rattler/compiler/parser_generator/semantic_action_generator.rb +58 -0
- data/lib/rattler/compiler/parser_generator/sequence_generating.rb +138 -0
- data/lib/rattler/compiler/parser_generator/sequence_generator.rb +57 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/skip_generator.rb +4 -18
- data/lib/rattler/compiler/parser_generator/skip_propogating.rb +16 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/sub_generating.rb +19 -11
- data/lib/rattler/compiler/parser_generator/super_generator.rb +54 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/token_generator.rb +3 -3
- data/lib/rattler/compiler/parser_generator/token_propogating.rb +10 -0
- data/lib/rattler/{back_end → compiler}/parser_generator/top_level.rb +2 -2
- data/lib/rattler/{back_end → compiler}/parser_generator/zero_or_more_generating.rb +5 -5
- data/lib/rattler/compiler/rattler.rtlr +201 -0
- data/lib/rattler/{back_end → compiler}/ruby_generator.rb +16 -25
- data/lib/rattler/parsers.rb +12 -33
- data/lib/rattler/parsers/action_code.rb +25 -16
- data/lib/rattler/{grammar → parsers}/analysis.rb +32 -11
- data/lib/rattler/parsers/apply.rb +10 -19
- data/lib/rattler/parsers/assert.rb +4 -14
- data/lib/rattler/parsers/atomic.rb +3 -10
- data/lib/rattler/parsers/attributed_sequence.rb +50 -0
- data/lib/rattler/parsers/back_reference.rb +19 -14
- data/lib/rattler/parsers/choice.rb +11 -12
- data/lib/rattler/parsers/combinator_parser.rb +15 -7
- data/lib/rattler/parsers/combining.rb +15 -9
- data/lib/rattler/parsers/disallow.rb +5 -12
- data/lib/rattler/parsers/e_symbol.rb +5 -14
- data/lib/rattler/parsers/eof.rb +10 -15
- data/lib/rattler/parsers/fail.rb +16 -26
- data/lib/rattler/{grammar → parsers}/grammar.rb +15 -20
- data/lib/rattler/parsers/label.rb +10 -16
- data/lib/rattler/parsers/list_parser.rb +14 -14
- data/lib/rattler/parsers/match.rb +5 -17
- data/lib/rattler/parsers/node_action.rb +72 -0
- data/lib/rattler/parsers/node_code.rb +47 -30
- data/lib/rattler/parsers/parser.rb +63 -32
- data/lib/rattler/parsers/parser_scope.rb +88 -0
- data/lib/rattler/parsers/predicate.rb +12 -10
- data/lib/rattler/parsers/repeat.rb +15 -8
- data/lib/rattler/parsers/rule.rb +8 -23
- data/lib/rattler/parsers/rule_set.rb +67 -12
- data/lib/rattler/parsers/semantic.rb +36 -0
- data/lib/rattler/parsers/semantic_action.rb +39 -0
- data/lib/rattler/parsers/sequence.rb +25 -40
- data/lib/rattler/parsers/sequencing.rb +40 -0
- data/lib/rattler/parsers/skip.rb +11 -12
- data/lib/rattler/parsers/super.rb +33 -0
- data/lib/rattler/parsers/token.rb +3 -13
- data/lib/rattler/rake_task.rb +50 -0
- data/lib/rattler/runner.rb +19 -22
- data/lib/rattler/runtime.rb +0 -10
- data/lib/rattler/runtime/extended_packrat_parser.rb +40 -45
- data/lib/rattler/runtime/packrat_parser.rb +17 -31
- data/lib/rattler/runtime/parse_failure.rb +16 -26
- data/lib/rattler/runtime/parse_node.rb +8 -18
- data/lib/rattler/runtime/parser.rb +6 -18
- data/lib/rattler/runtime/parser_helper.rb +3 -10
- data/lib/rattler/runtime/recursive_descent_parser.rb +26 -23
- data/lib/rattler/runtime/syntax_error.rb +0 -10
- data/lib/rattler/util.rb +2 -6
- data/lib/rattler/util/grammar_cli.rb +19 -0
- data/lib/rattler/util/graphviz.rb +6 -17
- data/lib/rattler/util/graphviz/digraph_builder.rb +10 -17
- data/lib/rattler/util/graphviz/node_builder.rb +45 -31
- data/lib/rattler/util/line_counter.rb +11 -20
- data/lib/rattler/util/node.rb +52 -30
- data/lib/rattler/util/parser_cli.rb +84 -0
- data/lib/rattler/util/parser_spec_helper.rb +8 -12
- data/spec/rattler/compiler/assert_compiler_examples.rb +284 -0
- data/spec/rattler/compiler/attributed_sequence_compiler_examples.rb +154 -0
- data/spec/rattler/compiler/disallow_compiler_examples.rb +293 -0
- data/spec/rattler/compiler/grammar_parser_spec.rb +700 -0
- data/spec/rattler/{back_end → compiler}/optimizer/flatten_choice_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/flatten_sequence_spec.rb +1 -1
- data/spec/rattler/compiler/optimizer/inline_regular_rules_spec.rb +50 -0
- data/spec/rattler/{back_end → compiler}/optimizer/join_match_capturing_sequence_spec.rb +106 -22
- data/spec/rattler/{back_end → compiler}/optimizer/join_match_choice_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/join_match_matching_sequence_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/join_predicate_bare_match_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/join_predicate_nested_match_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/join_predicate_or_bare_match_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/join_predicate_or_nested_match_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/reduce_repeat_match_spec.rb +1 -1
- data/spec/rattler/compiler/optimizer/remove_meaningless_wrapper_spec.rb +82 -0
- data/spec/rattler/{back_end → compiler}/optimizer/simplify_redundant_repeat_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer/simplify_token_match_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/optimizer_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/parser_generator/apply_generator_spec.rb +1 -39
- data/spec/rattler/{back_end → compiler}/parser_generator/assert_generator_spec.rb +1 -55
- data/spec/rattler/compiler/parser_generator/attributed_sequence_generator_spec.rb +699 -0
- data/spec/rattler/{back_end → compiler}/parser_generator/back_reference_generator_spec.rb +3 -56
- data/spec/rattler/{back_end → compiler}/parser_generator/choice_generator_spec.rb +1 -63
- data/spec/rattler/{back_end → compiler}/parser_generator/disallow_generator_spec.rb +1 -55
- data/spec/rattler/{back_end → compiler}/parser_generator/e_symbol_generator_spec.rb +1 -39
- data/spec/rattler/{back_end → compiler}/parser_generator/eof_generator_spec.rb +1 -39
- data/spec/rattler/{back_end → compiler}/parser_generator/fail_generator_spec.rb +94 -23
- data/spec/rattler/compiler/parser_generator/grammar_generator_spec.rb +98 -0
- data/spec/rattler/compiler/parser_generator/group_match_generator_spec.rb +67 -0
- data/spec/rattler/{back_end → compiler}/parser_generator/group_match_spec.rb +1 -1
- data/spec/rattler/{back_end → compiler}/parser_generator/label_generator_spec.rb +1 -55
- data/spec/rattler/{back_end → compiler}/parser_generator/list0_generator_examples.rb +0 -88
- data/spec/rattler/{back_end → compiler}/parser_generator/list1_generator_examples.rb +0 -88
- data/spec/rattler/{back_end → compiler}/parser_generator/list_generator_spec.rb +1 -227
- data/spec/rattler/{back_end → compiler}/parser_generator/match_generator_spec.rb +1 -55
- data/spec/rattler/compiler/parser_generator/node_action_generator_spec.rb +135 -0
- data/spec/rattler/{back_end → compiler}/parser_generator/one_or_more_generator_examples.rb +0 -74
- data/spec/rattler/{back_end → compiler}/parser_generator/optional_generator_examples.rb +0 -62
- data/spec/rattler/{back_end → compiler}/parser_generator/repeat_generator_spec.rb +66 -1
- data/spec/rattler/{back_end → compiler}/parser_generator/rule_generator_spec.rb +3 -2
- data/spec/rattler/{back_end → compiler}/parser_generator/rule_set_generator_spec.rb +9 -27
- data/spec/rattler/compiler/parser_generator/semantic_action_generator_spec.rb +437 -0
- data/spec/rattler/{back_end → compiler}/parser_generator/sequence_generator_spec.rb +234 -68
- data/spec/rattler/{back_end → compiler}/parser_generator/skip_generator_spec.rb +1 -55
- data/spec/rattler/compiler/parser_generator/super_generator_spec.rb +93 -0
- data/spec/rattler/{back_end → compiler}/parser_generator/token_generator_spec.rb +1 -55
- data/spec/rattler/{back_end → compiler}/parser_generator/zero_or_more_generator_examples.rb +0 -74
- data/spec/rattler/{back_end → compiler}/ruby_generator_spec.rb +13 -13
- data/spec/rattler/compiler/semantic_action_compiler_examples.rb +57 -0
- data/spec/rattler/{back_end → compiler}/shared_compiler_examples.rb +111 -140
- data/spec/rattler/{back_end → compiler}/skip_compiler_examples.rb +60 -57
- data/spec/rattler/{back_end → compiler}/token_compiler_examples.rb +99 -104
- data/spec/rattler/compiler_spec.rb +67 -0
- data/spec/rattler/parsers/action_code_spec.rb +34 -18
- data/spec/rattler/{grammar → parsers}/analysis_spec.rb +13 -67
- data/spec/rattler/parsers/apply_spec.rb +6 -0
- data/spec/rattler/parsers/assert_spec.rb +38 -2
- data/spec/rattler/parsers/attributed_sequence_spec.rb +204 -0
- data/spec/rattler/parsers/back_reference_spec.rb +6 -0
- data/spec/rattler/parsers/choice_spec.rb +38 -1
- data/spec/rattler/parsers/combinator_parser_spec.rb +2 -1
- data/spec/rattler/parsers/disallow_spec.rb +38 -2
- data/spec/rattler/parsers/e_symbol_spec.rb +6 -0
- data/spec/rattler/parsers/eof_spec.rb +6 -0
- data/spec/rattler/parsers/fail_spec.rb +6 -0
- data/spec/rattler/{grammar → parsers}/grammar_spec.rb +10 -15
- data/spec/rattler/parsers/label_spec.rb +30 -0
- data/spec/rattler/parsers/list_parser_spec.rb +31 -2
- data/spec/rattler/parsers/match_spec.rb +6 -0
- data/spec/rattler/parsers/node_action_spec.rb +121 -0
- data/spec/rattler/parsers/parser_scope_spec.rb +105 -0
- data/spec/rattler/parsers/repeat_spec.rb +56 -0
- data/spec/rattler/parsers/rule_set_spec.rb +42 -0
- data/spec/rattler/parsers/semantic_action_spec.rb +89 -0
- data/spec/rattler/parsers/sequence_spec.rb +156 -12
- data/spec/rattler/parsers/skip_spec.rb +21 -0
- data/spec/rattler/parsers/super_spec.rb +45 -0
- data/spec/rattler/parsers/token_spec.rb +33 -14
- data/spec/rattler/runtime/extended_packrat_parser_spec.rb +10 -8
- data/spec/rattler/runtime/recursive_descent_parser_spec.rb +26 -0
- data/spec/rattler/runtime/shared_parser_examples.rb +22 -16
- data/spec/rattler/util/graphviz/node_builder_spec.rb +33 -17
- data/spec/rattler/util/line_counter_spec.rb +21 -21
- data/spec/rattler/util/node_spec.rb +62 -0
- data/spec/rattler_spec.rb +7 -41
- data/spec/spec_helper.rb +1 -2
- data/spec/support/combinator_parser_spec_helper.rb +1 -1
- data/spec/support/compiler_spec_helper.rb +0 -4
- data/spec/support/parser_generator_spec_helper.rb +7 -7
- data/spec/support/runtime_parser_spec_helper.rb +57 -3
- metadata +447 -303
- data/features/grammar/character_class.feature +0 -20
- data/features/grammar/nonterminal.feature +0 -24
- data/features/grammar/one_or_more.feature +0 -34
- data/features/grammar/ordered_choice.feature +0 -21
- data/features/grammar/posix_class.feature +0 -70
- data/features/grammar/sequence.feature +0 -20
- data/features/grammar/zero_or_more.feature +0 -34
- data/lib/rattler/back_end.rb +0 -22
- data/lib/rattler/back_end/compiler.rb +0 -128
- data/lib/rattler/back_end/optimizer.rb +0 -101
- data/lib/rattler/back_end/optimizer/inline_regular_rules.rb +0 -46
- data/lib/rattler/back_end/optimizer/join_match_sequence.rb +0 -17
- data/lib/rattler/back_end/optimizer/join_predicate_match.rb +0 -17
- data/lib/rattler/back_end/optimizer/join_predicate_or_match.rb +0 -17
- data/lib/rattler/back_end/optimizer/optimization_context.rb +0 -72
- data/lib/rattler/back_end/optimizer/remove_meaningless_wrapper.rb +0 -32
- data/lib/rattler/back_end/optimizer/specialize_repeat.rb +0 -40
- data/lib/rattler/back_end/parser_generator.rb +0 -113
- data/lib/rattler/back_end/parser_generator/direct_action_generator.rb +0 -45
- data/lib/rattler/back_end/parser_generator/dispatch_action_generator.rb +0 -45
- data/lib/rattler/back_end/parser_generator/group_match.rb +0 -26
- data/lib/rattler/back_end/parser_generator/label_generator.rb +0 -64
- data/lib/rattler/back_end/parser_generator/predicate_propogating.rb +0 -24
- data/lib/rattler/back_end/parser_generator/rule_generator.rb +0 -53
- data/lib/rattler/back_end/parser_generator/sequence_generator.rb +0 -190
- data/lib/rattler/back_end/parser_generator/skip_propogating.rb +0 -16
- data/lib/rattler/back_end/parser_generator/token_propogating.rb +0 -10
- data/lib/rattler/grammar.rb +0 -43
- data/lib/rattler/grammar/grammar_dsl.rb +0 -51
- data/lib/rattler/grammar/metagrammar.rb +0 -990
- data/lib/rattler/grammar/rattler.rtlr +0 -183
- data/lib/rattler/parsers/assert_code.rb +0 -31
- data/lib/rattler/parsers/direct_action.rb +0 -85
- data/lib/rattler/parsers/disallow_code.rb +0 -31
- data/lib/rattler/parsers/dispatch_action.rb +0 -121
- data/lib/rattler/parsers/effect_code.rb +0 -31
- data/lib/rattler/parsers/parser_dsl.rb +0 -414
- data/lib/rattler/parsers/semantic_assert.rb +0 -19
- data/lib/rattler/parsers/semantic_disallow.rb +0 -19
- data/lib/rattler/parsers/side_effect.rb +0 -19
- data/spec/rattler/back_end/assert_compiler_examples.rb +0 -187
- data/spec/rattler/back_end/compiler_spec.rb +0 -43
- data/spec/rattler/back_end/direct_action_compiler_examples.rb +0 -227
- data/spec/rattler/back_end/disallow_compiler_examples.rb +0 -187
- data/spec/rattler/back_end/dispatch_action_compiler_examples.rb +0 -225
- data/spec/rattler/back_end/optimizer/inline_regular_rules_spec.rb +0 -80
- data/spec/rattler/back_end/parser_generator/direct_action_generator_spec.rb +0 -204
- data/spec/rattler/back_end/parser_generator/dispatch_action_generator_spec.rb +0 -204
- data/spec/rattler/back_end/parser_generator/group_match_generator_spec.rb +0 -185
- data/spec/rattler/back_end/semantic_assert_compiler_examples.rb +0 -152
- data/spec/rattler/back_end/semantic_disallow_compiler_examples.rb +0 -152
- data/spec/rattler/back_end/side_effect_compiler_examples.rb +0 -227
- data/spec/rattler/grammar/grammar_parser_spec.rb +0 -626
- data/spec/rattler/parsers/direct_action_spec.rb +0 -224
- data/spec/rattler/parsers/dispatch_action_spec.rb +0 -209
- data/spec/rattler/parsers/node_code_spec.rb +0 -59
- data/spec/rattler/parsers/parser_dsl_spec.rb +0 -334
- data/spec/rattler/parsers/semantic_assert_spec.rb +0 -83
- data/spec/rattler/parsers/semantic_disallow_spec.rb +0 -83
- data/spec/rattler/parsers/side_effect_spec.rb +0 -214
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'rattler/parsers'
|
2
|
+
|
3
|
+
module Rattler::Parsers
|
4
|
+
|
5
|
+
# +ParserScope+ represents the scope of bindings and captures in a parse
|
6
|
+
# sequence.
|
7
|
+
class ParserScope
|
8
|
+
|
9
|
+
# @return [ParserScope] an empty scope as a singleton
|
10
|
+
def self.empty
|
11
|
+
@empty ||= self.new
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param [Hash] bindings labeled bindings
|
15
|
+
# @param [Array] captures captured parse results
|
16
|
+
# @param [Boolean] captures_decidable whether the list of captured parse
|
17
|
+
# results can be known statically
|
18
|
+
def initialize(bindings={}, captures=[], captures_decidable=true)
|
19
|
+
@bindings = bindings
|
20
|
+
@captures = captures
|
21
|
+
@captures_decidable = captures_decidable
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :bindings, :captures
|
25
|
+
|
26
|
+
# @param [Hash] new_bindings bindings to add or replace the current
|
27
|
+
# bindings
|
28
|
+
# @return [ParserScope] a new scope with additional bindings
|
29
|
+
def bind(new_bindings)
|
30
|
+
self.class.new(@bindings.merge(new_bindings), @captures, @captures_decidable)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param new_captures captures to add to the current captures
|
34
|
+
# @return [ParserScope] a new scope with additional captures
|
35
|
+
def capture(*new_captures)
|
36
|
+
self.class.new(@bindings, @captures + new_captures, @captures_decidable)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Create a new scope with this scope as the outer scope. The new scope
|
40
|
+
# inherits this scope's bindings, but not its captures.
|
41
|
+
#
|
42
|
+
# @return [ParserScope] a new scope with this scope as the outer scope
|
43
|
+
def nest
|
44
|
+
self.class.new(@bindings, [], @captures_decidable)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @param [ParserScope] other another scope
|
48
|
+
# @return [ParserScope] a new scope with bindings the other scope
|
49
|
+
def merge(other)
|
50
|
+
bind(other.bindings)
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [ParserScope] a new scope with captures_decidable +false+
|
54
|
+
def with_undecidable_captures
|
55
|
+
if captures_decidable?
|
56
|
+
self.class.new(@bindings, @captures, false)
|
57
|
+
else
|
58
|
+
self
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# @return whether the list of captured parse results can be known
|
63
|
+
# statically
|
64
|
+
def captures_decidable?
|
65
|
+
@captures_decidable
|
66
|
+
end
|
67
|
+
|
68
|
+
# @param [Symbol] name a binding name
|
69
|
+
# @return whether the scope has a binding for +name+
|
70
|
+
def has_name?(name)
|
71
|
+
@bindings.has_key?(name)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Run the block once for each binding
|
75
|
+
# @yield [name, value] the binding name and value
|
76
|
+
# @return self#bindings
|
77
|
+
def each_binding
|
78
|
+
@bindings.each {|name, value| yield name, value }
|
79
|
+
end
|
80
|
+
|
81
|
+
# @param [Symbol] name a binding name
|
82
|
+
# @return the value bound to +name+ in the scope
|
83
|
+
def [](name)
|
84
|
+
@bindings[name]
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
@@ -1,24 +1,26 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/predicate.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
1
|
require 'rattler/parsers'
|
9
2
|
|
10
3
|
module Rattler::Parsers
|
11
|
-
|
12
|
-
|
4
|
+
|
5
|
+
# A +Predicate+ is a parser that either succeeds or fails and never consumes
|
6
|
+
# any input or captures any parse results.
|
7
|
+
class Predicate < Parser
|
13
8
|
include Combining
|
14
9
|
|
15
|
-
|
10
|
+
# @private
|
11
|
+
def self.parsed(results, *_) #:nodoc:
|
16
12
|
self[results.first]
|
17
13
|
end
|
18
14
|
|
15
|
+
# (see Parser#capturing?)
|
19
16
|
def capturing?
|
20
17
|
false
|
21
18
|
end
|
22
19
|
|
20
|
+
# (see Parser#capturing_decidable?)
|
21
|
+
def capturing_decidable?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
23
25
|
end
|
24
26
|
end
|
@@ -1,17 +1,18 @@
|
|
1
1
|
require 'rattler/parsers'
|
2
2
|
|
3
3
|
module Rattler::Parsers
|
4
|
-
|
4
|
+
|
5
5
|
# +Repeat+ decorates a parser with repeat counts to match repeatedly (up to
|
6
6
|
# the upper bound, if given) and succeed if the decorated parser succeeds at
|
7
7
|
# least as many times as specified by the lower bound.
|
8
|
-
#
|
9
|
-
# @author Jason Arhart
|
10
|
-
#
|
11
8
|
class Repeat < Parser
|
12
9
|
include Combining
|
13
10
|
|
14
|
-
|
11
|
+
# @param [Parser] parser the parser to wrap and match with repeatedly
|
12
|
+
# @param [Integer] lower_bound the minimum number of times to match
|
13
|
+
# @param [Integer] upper_bound the maximum number of times to match
|
14
|
+
# @return [Repeat] a parser that decorates +parser+ and matches repeatedly
|
15
|
+
def self.[](parser, lower_bound, upper_bound = nil)
|
15
16
|
self.new(parser, :lower_bound => lower_bound, :upper_bound => upper_bound)
|
16
17
|
end
|
17
18
|
|
@@ -27,13 +28,13 @@ module Rattler::Parsers
|
|
27
28
|
# +true+ if the wrapped parser is not <tt>capturing?</tt>. Return +false+
|
28
29
|
# if the lower bound is not reached.
|
29
30
|
#
|
30
|
-
# @param (see
|
31
|
+
# @param (see Match#parse)
|
31
32
|
#
|
32
33
|
# @return [Array, Boolean] an array containing the decorated parser's parse
|
33
34
|
# results, or +true+ if the decorated parser is not <tt>capturing?</tt>,
|
34
35
|
# or +false+ if the decorated parser does not succeed up to the lower
|
35
36
|
# bound.
|
36
|
-
def parse(scanner, rules, scope =
|
37
|
+
def parse(scanner, rules, scope = ParserScope.empty)
|
37
38
|
a = []
|
38
39
|
start_pos = scanner.pos
|
39
40
|
while result = child.parse(scanner, rules, scope)
|
@@ -41,33 +42,39 @@ module Rattler::Parsers
|
|
41
42
|
break if upper_bound? and a.size >= upper_bound
|
42
43
|
end
|
43
44
|
if a.size >= lower_bound
|
44
|
-
capturing? ? a : true
|
45
|
+
capturing? ? select_captures(a) : true
|
45
46
|
else
|
46
47
|
scanner.pos = start_pos
|
47
48
|
false
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
52
|
+
# @return +true+ if the bounds define a zero-or-more
|
51
53
|
def zero_or_more?
|
52
54
|
lower_bound == 0 and not upper_bound?
|
53
55
|
end
|
54
56
|
|
57
|
+
# @return +true+ if the bounds define a one-or-more parser
|
55
58
|
def one_or_more?
|
56
59
|
lower_bound == 1 and not upper_bound?
|
57
60
|
end
|
58
61
|
|
62
|
+
# @return +true+ if the bounds define an optional (zero-or-one) parser
|
59
63
|
def optional?
|
60
64
|
lower_bound == 0 and upper_bound == 1
|
61
65
|
end
|
62
66
|
|
67
|
+
# @return +true+ if there is a lower bound
|
63
68
|
def lower_bound?
|
64
69
|
lower_bound > 0
|
65
70
|
end
|
66
71
|
|
72
|
+
# @return +true+ if there is an upper bound
|
67
73
|
def upper_bound?
|
68
74
|
not upper_bound.nil?
|
69
75
|
end
|
70
76
|
|
77
|
+
# (see Parser#variable_capture_count?)
|
71
78
|
def variable_capture_count?
|
72
79
|
true
|
73
80
|
end
|
data/lib/rattler/parsers/rule.rb
CHANGED
@@ -1,19 +1,9 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/rule.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
|
# +Rule+ is a binding for a parser that can be referenced by name from
|
13
6
|
# another rule.
|
14
|
-
#
|
15
|
-
# @author Jason Arhart
|
16
|
-
#
|
17
7
|
class Rule < Rattler::Util::Node
|
18
8
|
|
19
9
|
# Create a new +Rule+.
|
@@ -28,26 +18,21 @@ module Rattler::Parsers
|
|
28
18
|
|
29
19
|
alias_method :expr, :child
|
30
20
|
|
31
|
-
# Parse using
|
32
|
-
#
|
21
|
+
# Parse using the rule body and on success return the result, on failure
|
22
|
+
# return a false value.
|
33
23
|
#
|
34
|
-
# @param
|
35
|
-
# @
|
36
|
-
|
37
|
-
# @return (see Parser#parse_labeled)
|
38
|
-
def parse(scanner, rules, scope = {})
|
24
|
+
# @param (see Match#parse)
|
25
|
+
# @return (see Match#parse)
|
26
|
+
def parse(scanner, rules, scope = ParserScope.empty)
|
39
27
|
catch(:rule_failed) do
|
40
28
|
return expr.parse(scanner, rules, scope)
|
41
29
|
end
|
42
30
|
false
|
43
31
|
end
|
44
32
|
|
45
|
-
|
46
|
-
Rule[name, new_expr, attrs]
|
47
|
-
end
|
33
|
+
alias_method :with_expr, :with_children
|
48
34
|
|
49
|
-
#
|
50
|
-
# @return (see Parser#with_ws)
|
35
|
+
# (see Parser#with_ws)
|
51
36
|
def with_ws(ws)
|
52
37
|
self.with_expr expr.with_ws(ws)
|
53
38
|
end
|
@@ -1,20 +1,26 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/rule_set.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
1
|
require 'rattler/parsers'
|
9
2
|
|
10
3
|
module Rattler::Parsers
|
4
|
+
|
5
|
+
# +RuleSet+ encapsulates a set of parse rules that define a grammar and
|
6
|
+
# provides accessors to the rules by name.
|
11
7
|
class RuleSet < Rattler::Util::Node
|
12
8
|
|
13
9
|
# @private
|
14
10
|
def self.parsed(results, *_) #:nodoc:
|
15
|
-
self.new(results)
|
11
|
+
self.new(results[0])
|
16
12
|
end
|
17
13
|
|
14
|
+
# Create a +RuleSet+ instance.
|
15
|
+
#
|
16
|
+
# @overload initialize()
|
17
|
+
# @return [RuleSet]
|
18
|
+
# @overload initialize(rule...)
|
19
|
+
# @return [RuleSet]
|
20
|
+
# @overload initialize(attribute...)
|
21
|
+
# @return [RuleSet]
|
22
|
+
# @overload initialize(rule..., attribute...)
|
23
|
+
# @return [RuleSet]
|
18
24
|
def initialize(*args)
|
19
25
|
super
|
20
26
|
@by_name = {}
|
@@ -23,14 +29,44 @@ module Rattler::Parsers
|
|
23
29
|
|
24
30
|
alias_method :rules, :children
|
25
31
|
|
32
|
+
# @return [Symbol] the name of the rule to start parsing with
|
26
33
|
def start_rule
|
27
34
|
attrs[:start_rule]
|
28
35
|
end
|
29
36
|
|
37
|
+
# @param [Symbol] name the name of a rule in the rule set
|
38
|
+
# @return [Rule] the rule with the given name in the rule set
|
30
39
|
def rule(name)
|
31
|
-
@by_name[name]
|
40
|
+
@by_name[name] || inherited_rule(name)
|
41
|
+
end
|
42
|
+
|
43
|
+
# @param [Symbol] name the name of a rule in an inherited rule set
|
44
|
+
# @return [Rule] the rule with the given name in the inherited rule set
|
45
|
+
def inherited_rule(name)
|
46
|
+
includes.inject(nil) {|r,s| r || s.rule(name) }
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [Array<String>] a list of modules to be included in the parser
|
50
|
+
def includes
|
51
|
+
attrs[:includes] || []
|
32
52
|
end
|
33
53
|
|
54
|
+
# Access the rule set's rules
|
55
|
+
#
|
56
|
+
# @overload [](rule_name)
|
57
|
+
# @param [Symbol] name the name of a rule in the rule set
|
58
|
+
# @return [Rule] the rule with the given name in the rule set
|
59
|
+
# @overload [](index)
|
60
|
+
# @param [Integer] index index of the rule
|
61
|
+
# @return the rule at +index+
|
62
|
+
# @overload [](start, length)
|
63
|
+
# @param [Integer] start the index of the first rule
|
64
|
+
# @param [Integer] length the number of rules to return
|
65
|
+
# @return [Array] the rules starting at +start+ and continuing for
|
66
|
+
# +length+ rules
|
67
|
+
# @overload [](range)
|
68
|
+
# @param [Range] range the range of rules
|
69
|
+
# @return [Array] the rules specified by +range+
|
34
70
|
def [](*args)
|
35
71
|
if args.length == 1 and args[0].is_a?(Symbol)
|
36
72
|
rule(args[0])
|
@@ -39,24 +75,43 @@ module Rattler::Parsers
|
|
39
75
|
end
|
40
76
|
end
|
41
77
|
|
78
|
+
# @param [Hash] new_attrs a hash of attributes to merge with the existing
|
79
|
+
# attributes
|
80
|
+
# @return [RuleSet] a new rule set with the same rules and the new
|
81
|
+
# attributes merged
|
42
82
|
def with_attrs(new_attrs)
|
43
83
|
self.class.new(children, attrs.merge(new_attrs))
|
44
84
|
end
|
45
85
|
|
86
|
+
# @param [Array<Rule>] new_rules the new list of rules to replace the
|
87
|
+
# existing rules
|
88
|
+
# @return [RuleSet] a new rule set with a new list of rules and the same
|
89
|
+
# attributes
|
46
90
|
def with_rules(new_rules)
|
47
91
|
self.class.new(new_rules, attrs)
|
48
92
|
end
|
49
93
|
|
94
|
+
# @yield Run the block once for each rule
|
95
|
+
# @yieldparam [Rule] rule one rule in the rule set
|
96
|
+
# @yieldreturn [Rule] a rule to replace the one yielded to the block
|
97
|
+
# @return [RuleSet] a new rule set with the result of running the block
|
98
|
+
# once for each rule
|
50
99
|
def map_rules
|
51
|
-
self.with_rules rules.map {|
|
100
|
+
self.with_rules rules.map {|rule| yield rule }
|
52
101
|
end
|
53
102
|
|
103
|
+
# @yield Run the block as a predicate once for each rule
|
104
|
+
# @yieldparam [Rule] rule one rule in the rule set
|
105
|
+
# @yieldreturn [Boolean] +true+ to include the rule in the new rule set
|
106
|
+
# @return [RuleSet] a new rule set with the rules for which the block
|
107
|
+
# returns +true+
|
54
108
|
def select_rules
|
55
|
-
self.with_rules rules.select {|
|
109
|
+
self.with_rules rules.select {|rule| yield rule }
|
56
110
|
end
|
57
111
|
|
112
|
+
# @return [Analysis] a static analysis of the rules
|
58
113
|
def analysis
|
59
|
-
@analysis ||=
|
114
|
+
@analysis ||= Analysis.new(self)
|
60
115
|
end
|
61
116
|
|
62
117
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rattler/parsers'
|
2
|
+
|
3
|
+
module Rattler::Parsers
|
4
|
+
|
5
|
+
# +Semantic+ describes parsers that perform a semantic action
|
6
|
+
module Semantic
|
7
|
+
|
8
|
+
# @param [ParserScope] scope the scope of captures to bind in the code
|
9
|
+
# @return [String] ruby code that performs the action
|
10
|
+
def bind(scope)
|
11
|
+
bindable_code.bind(scope)
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return an object that be bound to a parser scope to return ruby code
|
15
|
+
# that performs the action
|
16
|
+
def bindable_code
|
17
|
+
@bindable_code ||= create_bindable_code
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return +true+
|
21
|
+
def semantic?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def apply(scope)
|
28
|
+
code_bindings = {}
|
29
|
+
scope.each_binding {|k, v| code_bindings[k] = v.inspect }
|
30
|
+
code_captures = scope.captures.map {|_| _.inspect }
|
31
|
+
code_scope = ParserScope.new(code_bindings, code_captures)
|
32
|
+
eval(bind(code_scope))
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Rattler::Parsers
|
2
|
+
|
3
|
+
# +SemanticAction+ is a pseudo-parser that performs a semantic action by
|
4
|
+
# evaluating ruby code in the context of a parser scope.
|
5
|
+
class SemanticAction < Parser
|
6
|
+
include Semantic
|
7
|
+
|
8
|
+
# @private
|
9
|
+
def self.parsed(results, *_) #:nodoc:
|
10
|
+
self[results.first]
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param [String] code ruby code that can be bound to a parser scope to
|
14
|
+
# perform an action
|
15
|
+
# @return [SemanticAction] a pseudo-parser that performs a semantic action
|
16
|
+
def self.[](code)
|
17
|
+
self.new(:code => code.strip)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Perform the semantic action in the context of +scope+
|
21
|
+
#
|
22
|
+
# @param (see Match#parse)
|
23
|
+
#
|
24
|
+
# @return the result of performing the semantic action in the context of
|
25
|
+
# +scope+
|
26
|
+
def parse(scanner, rules, scope = ParserScope.empty)
|
27
|
+
apply scope
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
# @return [ActionCode] an object that be bound to a parser scope to return
|
33
|
+
# ruby code that performs the action
|
34
|
+
def create_bindable_code
|
35
|
+
ActionCode.new(code)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|