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,8 +1,10 @@
|
|
1
1
|
Feature: Positive Lookahead Operator
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
A positive lookahead predicate matches if a parsing expression would match
|
4
|
+
but the predicate consumes no input.
|
5
|
+
|
6
|
+
Positive lookahead is written by placing a "&" in front of a parsing
|
7
|
+
expression.
|
6
8
|
|
7
9
|
Scenario Outline: Parsing
|
8
10
|
Given a grammar with:
|
@@ -16,4 +18,4 @@ Feature: Positive Lookahead Operator
|
|
16
18
|
| input | result |
|
17
19
|
| "AB" | "A" |
|
18
20
|
| "A" | FAIL |
|
19
|
-
| "AC" | FAIL |
|
21
|
+
| "AC" | FAIL |
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Feature: Sequences
|
2
|
+
|
3
|
+
A sequence is a series of parsing expressions that matches if all of the
|
4
|
+
expressions match in sequence. If any of the parsing expressions fail, the
|
5
|
+
entire sequence fails and backtracks to the starting point.
|
6
|
+
|
7
|
+
A sequence is written as a series of parsing expressions separated by spaces.
|
8
|
+
|
9
|
+
Scenario Outline: Parsing
|
10
|
+
Given a grammar with:
|
11
|
+
"""
|
12
|
+
expr <- "A" "B"
|
13
|
+
"""
|
14
|
+
When I parse <input>
|
15
|
+
Then the parse result should be <result>
|
16
|
+
|
17
|
+
Examples:
|
18
|
+
| input | result |
|
19
|
+
| "AB" | ["A", "B"] |
|
20
|
+
| "ABC" | ["A", "B"] |
|
21
|
+
| "ACB" | FAIL |
|
22
|
+
| "A" | FAIL |
|
23
|
+
| "C" | FAIL |
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Feature: Zero-Or-More
|
2
|
+
|
3
|
+
The "*" operator following a parsing expression causes it to match repeatedly
|
4
|
+
and succeed even if the expression never matches, i.e. it matches zero or
|
5
|
+
more times.
|
6
|
+
|
7
|
+
Scenario Outline: Capturing expression
|
8
|
+
Given a grammar with:
|
9
|
+
"""
|
10
|
+
letters <- ALPHA*
|
11
|
+
"""
|
12
|
+
When I parse <input>
|
13
|
+
Then the parse result should be <result>
|
14
|
+
And the parse position should be <pos>
|
15
|
+
|
16
|
+
Examples:
|
17
|
+
| input | result | pos |
|
18
|
+
| "A" | ["A"] | 1 |
|
19
|
+
| "foo" | ["f", "o", "o"] | 3 |
|
20
|
+
| "234" | [] | 0 |
|
21
|
+
|
22
|
+
Scenario Outline: Non-Capturing expression
|
23
|
+
Given a grammar with:
|
24
|
+
"""
|
25
|
+
dashes <- ~"-"*
|
26
|
+
"""
|
27
|
+
When I parse <input>
|
28
|
+
Then the parse result should be <result>
|
29
|
+
And the parse position should be <pos>
|
30
|
+
|
31
|
+
Examples:
|
32
|
+
| input | result | pos |
|
33
|
+
| "-" | true | 1 |
|
34
|
+
| "---" | true | 3 |
|
35
|
+
| "foo" | true | 0 |
|
36
|
+
|
37
|
+
Scenario Outline: Choice of capturing or non-capturing
|
38
|
+
Given a grammar with:
|
39
|
+
"""
|
40
|
+
expr <- ("a" / ~"b")*
|
41
|
+
"""
|
42
|
+
When I parse <input>
|
43
|
+
Then the parse result should be <result>
|
44
|
+
And the parse position should be <pos>
|
45
|
+
|
46
|
+
Examples:
|
47
|
+
| input | result | pos |
|
48
|
+
| "aa" | ["a", "a"] | 2 |
|
49
|
+
| "aba" | ["a", "a"] | 3 |
|
50
|
+
| "bbc" | [] | 2 |
|
51
|
+
|
52
|
+
Scenario: Semantic attribute returning true
|
53
|
+
Given a grammar with:
|
54
|
+
"""
|
55
|
+
expr <- (ALPHA { true })*
|
56
|
+
"""
|
57
|
+
When I parse "foo "
|
58
|
+
Then the parse result should be []
|
59
|
+
And the parse position should be 3
|
File without changes
|
@@ -1,10 +1,31 @@
|
|
1
|
-
Feature: Negative
|
1
|
+
Feature: Negative Semantic Predicates
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
Semantic predicates can be used to cause a parsing expression to either
|
4
|
+
continue or fail based on the result of a Ruby expression. With a negative
|
5
|
+
semantic predicate the expression is evaluated and if the result is truthy
|
6
|
+
the parsing expression fails at that point, otherwise it continues.
|
6
7
|
|
7
|
-
|
8
|
+
A negative semantic predicate is written as a "!" followed by curly braces
|
9
|
+
surrounding a Ruby expression.
|
10
|
+
|
11
|
+
Scenario: Truthy result
|
12
|
+
Given a grammar with:
|
13
|
+
"""
|
14
|
+
expr <- !{ 1 }
|
15
|
+
"""
|
16
|
+
When I parse "anything"
|
17
|
+
Then the parse should fail
|
18
|
+
|
19
|
+
Scenario: False result
|
20
|
+
Given a grammar with:
|
21
|
+
"""
|
22
|
+
expr <- !{ false }
|
23
|
+
"""
|
24
|
+
When I parse "anything"
|
25
|
+
Then the parse result should be true
|
26
|
+
And the parse position should be 0
|
27
|
+
|
28
|
+
Scenario Outline: Single-capture sequence
|
8
29
|
Given a grammar with:
|
9
30
|
"""
|
10
31
|
expr <- @DIGIT+ !{|s| s.to_i > 20 }
|
@@ -17,7 +38,7 @@ Feature: Negative Symantic Predicates
|
|
17
38
|
| "17" | "17" |
|
18
39
|
| "42" | FAIL |
|
19
40
|
|
20
|
-
Scenario Outline:
|
41
|
+
Scenario Outline: Multi-capture sequence
|
21
42
|
Given a grammar with:
|
22
43
|
"""
|
23
44
|
%whitespace SPACE*
|
@@ -57,7 +78,7 @@ Feature: Negative Symantic Predicates
|
|
57
78
|
| "(17<23)" | ["(", "17", "<", "23", ")"] |
|
58
79
|
| "(23<17)" | FAIL |
|
59
80
|
|
60
|
-
Scenario Outline: Single
|
81
|
+
Scenario Outline: Single-capture sequence using "_"
|
61
82
|
Given a grammar with:
|
62
83
|
"""
|
63
84
|
expr <- @DIGIT+ !{ _.to_i > 20 }
|
@@ -70,7 +91,7 @@ Feature: Negative Symantic Predicates
|
|
70
91
|
| "17" | "17" |
|
71
92
|
| "42" | FAIL |
|
72
93
|
|
73
|
-
Scenario Outline:
|
94
|
+
Scenario Outline: Multi-capture sequence using "_"
|
74
95
|
Given a grammar with:
|
75
96
|
"""
|
76
97
|
%whitespace SPACE*
|
@@ -84,7 +105,7 @@ Feature: Negative Symantic Predicates
|
|
84
105
|
| "16 3" | ["16", "3"] |
|
85
106
|
| "3 16" | FAIL |
|
86
107
|
|
87
|
-
Scenario Outline:
|
108
|
+
Scenario Outline: Multi-capture sequence using "_" as a parameter name
|
88
109
|
Given a grammar with:
|
89
110
|
"""
|
90
111
|
%whitespace SPACE*
|
File without changes
|
@@ -1,10 +1,31 @@
|
|
1
1
|
Feature: Positive Semantic Predicates
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
Semantic predicates can be used to cause a parsing expression to either
|
4
|
+
continue or fail based on the result of a Ruby expression. With a positive
|
5
|
+
semantic predicate the expression is evaluated and if the result is truthy
|
6
|
+
the parsing expression continues, otherwise it fails at that point.
|
6
7
|
|
7
|
-
|
8
|
+
A positive semantic predicate is written as a "&" followed by curly braces
|
9
|
+
surrounding a Ruby expression.
|
10
|
+
|
11
|
+
Scenario: Truthy result
|
12
|
+
Given a grammar with:
|
13
|
+
"""
|
14
|
+
expr <- &{ 1 }
|
15
|
+
"""
|
16
|
+
When I parse "anything"
|
17
|
+
Then the parse result should be true
|
18
|
+
And the parse position should be 0
|
19
|
+
|
20
|
+
Scenario: False result
|
21
|
+
Given a grammar with:
|
22
|
+
"""
|
23
|
+
expr <- &{ false }
|
24
|
+
"""
|
25
|
+
When I parse "anything"
|
26
|
+
Then the parse should fail
|
27
|
+
|
28
|
+
Scenario Outline: Single-capture sequence
|
8
29
|
Given a grammar with:
|
9
30
|
"""
|
10
31
|
expr <- @DIGIT+ &{|s| s.to_i > 20 }
|
@@ -17,7 +38,7 @@ Feature: Positive Semantic Predicates
|
|
17
38
|
| "42" | "42" |
|
18
39
|
| "17" | FAIL |
|
19
40
|
|
20
|
-
Scenario Outline:
|
41
|
+
Scenario Outline: Multi-capture sequence
|
21
42
|
Given a grammar with:
|
22
43
|
"""
|
23
44
|
%whitespace SPACE*
|
@@ -57,7 +78,7 @@ Feature: Positive Semantic Predicates
|
|
57
78
|
| "(17<23)" | ["(", "17", "<", "23", ")"] |
|
58
79
|
| "(23<17)" | FAIL |
|
59
80
|
|
60
|
-
Scenario Outline: Single
|
81
|
+
Scenario Outline: Single-capture sequence using "_"
|
61
82
|
Given a grammar with:
|
62
83
|
"""
|
63
84
|
expr <- @DIGIT+ &{ _.to_i > 20 }
|
@@ -70,7 +91,7 @@ Feature: Positive Semantic Predicates
|
|
70
91
|
| "42" | "42" |
|
71
92
|
| "17" | FAIL |
|
72
93
|
|
73
|
-
Scenario Outline:
|
94
|
+
Scenario Outline: Multi-capture sequence using "_"
|
74
95
|
Given a grammar with:
|
75
96
|
"""
|
76
97
|
%whitespace SPACE*
|
@@ -84,7 +105,7 @@ Feature: Positive Semantic Predicates
|
|
84
105
|
| "3 16" | ["3", "16"] |
|
85
106
|
| "16 3" | FAIL |
|
86
107
|
|
87
|
-
Scenario Outline:
|
108
|
+
Scenario Outline: Multi-capture sequence using "_" as a parameter name
|
88
109
|
Given a grammar with:
|
89
110
|
"""
|
90
111
|
%whitespace SPACE*
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: Semantic Actions
|
2
2
|
|
3
|
-
A
|
3
|
+
A semantic action can be added between "{" and "}" following an expression.
|
4
4
|
It means to evaluate the action as a Ruby expression if the match succeeds
|
5
5
|
and use the result of the action as the final parse result. Parameters can be
|
6
6
|
specified like Ruby block parameters and are bound to the parse results from
|
@@ -0,0 +1,86 @@
|
|
1
|
+
Feature: Semantic Results
|
2
|
+
|
3
|
+
A semantic result can be used to add a synthetic parse result using a Ruby
|
4
|
+
expression. The expression is evaluated and the result is inserted like a
|
5
|
+
normal parse result. This can be used to insert implicit syntax nodes into
|
6
|
+
a parse tree, such as optional expression terminators. Note that a false
|
7
|
+
value with cause the parse to fail.
|
8
|
+
|
9
|
+
A semantic result is written as a "^" followed by curly braces surrounding a
|
10
|
+
Ruby expression.
|
11
|
+
|
12
|
+
Scenario: Lone result
|
13
|
+
Given a grammar with:
|
14
|
+
"""
|
15
|
+
expr <- ^{ ";" }
|
16
|
+
"""
|
17
|
+
When I parse "anything"
|
18
|
+
Then the parse result should be ";"
|
19
|
+
And the parse position should be 0
|
20
|
+
|
21
|
+
Scenario: False result
|
22
|
+
Given a grammar with:
|
23
|
+
"""
|
24
|
+
expr <- ^{ false }
|
25
|
+
"""
|
26
|
+
When I parse "anything"
|
27
|
+
Then the parse should fail
|
28
|
+
|
29
|
+
Scenario: Single-capture sequence
|
30
|
+
Given a grammar with:
|
31
|
+
"""
|
32
|
+
expr <- @DIGIT+ ^{|a| a.to_i }
|
33
|
+
"""
|
34
|
+
When I parse "23"
|
35
|
+
Then the parse result should be ["23", 23]
|
36
|
+
|
37
|
+
Scenario: Multi-capture sequence
|
38
|
+
Given a grammar with:
|
39
|
+
"""
|
40
|
+
%whitespace SPACE*
|
41
|
+
expr <- @DIGIT+ @DIGIT+ ^{|a,b| a.to_i * b.to_i }
|
42
|
+
"""
|
43
|
+
When I parse "3 16"
|
44
|
+
Then the parse result should be ["3", "16", 48]
|
45
|
+
|
46
|
+
Scenario: Sequence with non-capturing expressions
|
47
|
+
Given a grammar with:
|
48
|
+
"""
|
49
|
+
expr <- ~"(" @DIGIT+ ~"+" @DIGIT+ ~")" ^{|a,b| a.to_i + b.to_i }
|
50
|
+
"""
|
51
|
+
When I parse "(23+17)"
|
52
|
+
Then the parse result should be ["23", "17", 40]
|
53
|
+
|
54
|
+
Scenario: Sequence with labeled expressions
|
55
|
+
Given a grammar with:
|
56
|
+
"""
|
57
|
+
expr <- "(" l:@DIGIT+ "+" r:@DIGIT+ ")" ^{ l.to_i + r.to_i }
|
58
|
+
"""
|
59
|
+
When I parse "(17+29)"
|
60
|
+
Then the parse result should be ["(", "17", "+", "29", ")", 46]
|
61
|
+
|
62
|
+
Scenario: Single-capture sequence using "_"
|
63
|
+
Given a grammar with:
|
64
|
+
"""
|
65
|
+
expr <- @DIGIT+ ^{ _.to_i }
|
66
|
+
"""
|
67
|
+
When I parse "23"
|
68
|
+
Then the parse result should be ["23", 23]
|
69
|
+
|
70
|
+
Scenario: Multi-capture sequence using "_"
|
71
|
+
Given a grammar with:
|
72
|
+
"""
|
73
|
+
%whitespace SPACE*
|
74
|
+
expr <- @DIGIT+ @DIGIT+ ^{ _.reverse }
|
75
|
+
"""
|
76
|
+
When I parse "3 16"
|
77
|
+
Then the parse result should be ["3", "16", ["16", "3"]]
|
78
|
+
|
79
|
+
Scenario: Multi-capture sequence using "_" as a parameter name
|
80
|
+
Given a grammar with:
|
81
|
+
"""
|
82
|
+
%whitespace SPACE*
|
83
|
+
expr <- @DIGIT+ @DIGIT+ ^{|_| _.to_i }
|
84
|
+
"""
|
85
|
+
When I parse "3 16"
|
86
|
+
Then the parse result should be ["3", "16", 3]
|
@@ -1,19 +1,41 @@
|
|
1
1
|
Feature: Semantic side-effects
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
Semantic side effects can be used to set or change some state during a parse
|
4
|
+
using a Ruby expression without directly affecting the parse. The expression
|
5
|
+
is evaluated for effect and its result is discarded.
|
6
6
|
|
7
|
-
|
7
|
+
A semantic side-effect is written as a "~" followed by curly braces
|
8
|
+
surrounding a Ruby expression.
|
9
|
+
|
10
|
+
Scenario: Lone action
|
8
11
|
Given a grammar with:
|
9
12
|
"""
|
10
|
-
expr <-
|
13
|
+
expr <- ~{ $x = 42 }
|
11
14
|
"""
|
12
|
-
When I parse "
|
13
|
-
Then the parse result should be
|
15
|
+
When I parse "anything"
|
16
|
+
Then the parse result should be true
|
14
17
|
And $x should be 42
|
18
|
+
And the parse position should be 0
|
19
|
+
|
20
|
+
Scenario: False result
|
21
|
+
Given a grammar with:
|
22
|
+
"""
|
23
|
+
expr <- ~{ false }
|
24
|
+
"""
|
25
|
+
When I parse "anything"
|
26
|
+
Then the parse result should be true
|
27
|
+
And the parse position should be 0
|
15
28
|
|
16
|
-
Scenario:
|
29
|
+
Scenario: Single-capture sequence
|
30
|
+
Given a grammar with:
|
31
|
+
"""
|
32
|
+
expr <- @DIGIT+ ~{|a| $x = a.to_i }
|
33
|
+
"""
|
34
|
+
When I parse "23"
|
35
|
+
Then the parse result should be "23"
|
36
|
+
And $x should be 23
|
37
|
+
|
38
|
+
Scenario: Multi-capture sequence
|
17
39
|
Given a grammar with:
|
18
40
|
"""
|
19
41
|
%whitespace SPACE*
|
@@ -41,7 +63,7 @@ Feature: Semantic side-effects
|
|
41
63
|
Then the parse result should be ["(", "17", "+", "29", ")"]
|
42
64
|
And $x should be 46
|
43
65
|
|
44
|
-
Scenario: Single
|
66
|
+
Scenario: Single-capture sequence using "_"
|
45
67
|
Given a grammar with:
|
46
68
|
"""
|
47
69
|
expr <- @DIGIT+ ~{ $x = _.to_i }
|
@@ -50,7 +72,7 @@ Feature: Semantic side-effects
|
|
50
72
|
Then the parse result should be "23"
|
51
73
|
And $x should be 23
|
52
74
|
|
53
|
-
Scenario:
|
75
|
+
Scenario: Multi-capture sequence using "_"
|
54
76
|
Given a grammar with:
|
55
77
|
"""
|
56
78
|
%whitespace SPACE*
|
@@ -60,7 +82,7 @@ Feature: Semantic side-effects
|
|
60
82
|
Then the parse result should be ["3", "16"]
|
61
83
|
And $x should be ["16", "3"]
|
62
84
|
|
63
|
-
Scenario:
|
85
|
+
Scenario: Multi-capture sequence using "_" as a parameter name
|
64
86
|
Given a grammar with:
|
65
87
|
"""
|
66
88
|
%whitespace SPACE*
|
@@ -69,13 +91,3 @@ Feature: Semantic side-effects
|
|
69
91
|
When I parse "3 16"
|
70
92
|
Then the parse result should be ["3", "16"]
|
71
93
|
And $x should be 3
|
72
|
-
|
73
|
-
Scenario: Lone action
|
74
|
-
Given a grammar with:
|
75
|
-
"""
|
76
|
-
expr <- ~{ $x = 42 }
|
77
|
-
"""
|
78
|
-
When I parse "anything"
|
79
|
-
Then the parse result should be true
|
80
|
-
And $x should be 42
|
81
|
-
And the parse position should be 0
|