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,31 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/effect_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 EffectCode < 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,414 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# = rattler/parsers/parser_dsl.rb
|
3
|
-
#
|
4
|
-
# Author:: Jason Arhart
|
5
|
-
# Documentation:: Author
|
6
|
-
#
|
7
|
-
|
8
|
-
require 'rattler/parsers'
|
9
|
-
|
10
|
-
module Rattler
|
11
|
-
module Parsers
|
12
|
-
#
|
13
|
-
# +ParserDSL+ defines a simple DSL for defining parsers.
|
14
|
-
#
|
15
|
-
# @author Jason Arhart
|
16
|
-
#
|
17
|
-
class ParserDSL
|
18
|
-
|
19
|
-
# Define parse rules with the given block
|
20
|
-
#
|
21
|
-
# @option options [Parser] ws (nil) a parser to be used to skip whitespace
|
22
|
-
#
|
23
|
-
# @return [Rattler::Parsers::RuleSet] a set of parse rules
|
24
|
-
#
|
25
|
-
def self.rules(options = {}, &block)
|
26
|
-
self.new(options).rules(&block)
|
27
|
-
end
|
28
|
-
|
29
|
-
# @private
|
30
|
-
def initialize(options = {}) #:nodoc:
|
31
|
-
@rules = options[:rules] || []
|
32
|
-
@options = options
|
33
|
-
@ws = options[:ws]
|
34
|
-
end
|
35
|
-
|
36
|
-
# @private
|
37
|
-
def with_options(options, &block) #:nodoc:
|
38
|
-
dsl = self.class.new(@options.merge(:rules => @rules).merge(options))
|
39
|
-
dsl.instance_exec(dsl, &block)
|
40
|
-
end
|
41
|
-
|
42
|
-
# Evaluate the given block using +ws+ to skip whitespace
|
43
|
-
#
|
44
|
-
# @param [Parser] ws the parser to be used to skip whitespace
|
45
|
-
def with_ws(ws, &block)
|
46
|
-
with_options(:ws => to_parser(ws), &block)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Evaluate the given block to define parse rules
|
50
|
-
#
|
51
|
-
# @return [RuleSet] the rules defined in the block
|
52
|
-
def rules(&block)
|
53
|
-
instance_exec(self, &block)
|
54
|
-
RuleSet[@rules]
|
55
|
-
end
|
56
|
-
|
57
|
-
# Evaluate the given block to define a parse rule
|
58
|
-
#
|
59
|
-
# @param [Symbol] name the name for the rule
|
60
|
-
#
|
61
|
-
# @return [Rule] the rule defined in the block
|
62
|
-
def rule(name, &block)
|
63
|
-
parser = instance_exec(self, &block)
|
64
|
-
@rules << Rule[name, (@ws ? parser.with_ws(@ws) : parser)]
|
65
|
-
@rules.last
|
66
|
-
end
|
67
|
-
|
68
|
-
# Create a new parser to match a pattern, literal, referenced parse rule,
|
69
|
-
# posix character class, EOF, or E.
|
70
|
-
#
|
71
|
-
# @overload match(pattern)
|
72
|
-
# @param [Regexp] pattern the pattern to match
|
73
|
-
# @return [Match] a new match parser
|
74
|
-
#
|
75
|
-
# @overload match(literal)
|
76
|
-
# @param [String] literal the literal to match
|
77
|
-
# @return [Match] a new match parser that matches exactly +literal+
|
78
|
-
#
|
79
|
-
# @overload match(rule_name)
|
80
|
-
# @param [Symbol] rule_name the rule name to match
|
81
|
-
# @return [Apply] a new apply-rule parser
|
82
|
-
#
|
83
|
-
# @overload match(posix_name)
|
84
|
-
# @param [Symbol] posix_name upper-case name of a posix character class
|
85
|
-
# @return [Match] a new match parser that matches the character class
|
86
|
-
#
|
87
|
-
# @overload match(:EOF)
|
88
|
-
# @param :EOF
|
89
|
-
# @return [Eof] the {Eof} singleton
|
90
|
-
#
|
91
|
-
# @overload match(:E)
|
92
|
-
# @param :E
|
93
|
-
# @return [ESymbol] the {ESymbol} singleton
|
94
|
-
#
|
95
|
-
def match(arg)
|
96
|
-
case arg
|
97
|
-
when Regexp then Match[arg]
|
98
|
-
when :EOF then eof
|
99
|
-
when :E then e
|
100
|
-
when :ALNUM then match /[[:alnum:]]/
|
101
|
-
when :ALPHA then match /[[:alpha:]]/
|
102
|
-
when :BLANK then match /[[:blank:]]/
|
103
|
-
when :CNTRL then match /[[:cntrl:]]/
|
104
|
-
when :DIGIT then match /[[:digit:]]/
|
105
|
-
when :GRAPH then match /[[:graph:]]/
|
106
|
-
when :LOWER then match /[[:lower:]]/
|
107
|
-
when :PRINT then match /[[:print:]]/
|
108
|
-
when :PUNCT then match /[[:punct:]]/
|
109
|
-
when :SPACE then match /[[:space:]]/
|
110
|
-
when :UPPER then match /[[:upper:]]/
|
111
|
-
when :XDIGIT then match /[[:xdigit:]]/
|
112
|
-
when :WORD then match /[[:alnum:]_]/
|
113
|
-
when Symbol then Apply[arg]
|
114
|
-
else match Regexp.new(Regexp.escape(arg.to_s))
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
# Create a new optional parser.
|
119
|
-
#
|
120
|
-
# @overload optional(parser)
|
121
|
-
# @return [Repeat] a new optional parser
|
122
|
-
# @overload optional(arg)
|
123
|
-
# @return [Repeat] a new optional parser using arg to define a match
|
124
|
-
# parser
|
125
|
-
# @see #match
|
126
|
-
def optional(arg)
|
127
|
-
Repeat[to_parser(arg), 0, 1]
|
128
|
-
end
|
129
|
-
|
130
|
-
# Create a new zero-or-more parser.
|
131
|
-
#
|
132
|
-
# @overload zero_or_more(parser)
|
133
|
-
# @return [Repeat] a new zero-or-more parser
|
134
|
-
# @overload zero_or_more(arg)
|
135
|
-
# @return [Repeat] a new zero-or-more parser using arg to define a
|
136
|
-
# match parser
|
137
|
-
# @see #match
|
138
|
-
def zero_or_more(arg)
|
139
|
-
Repeat[to_parser(arg), 0, nil]
|
140
|
-
end
|
141
|
-
|
142
|
-
alias_method :any, :zero_or_more
|
143
|
-
|
144
|
-
# Create a new one-or-more parser.
|
145
|
-
#
|
146
|
-
# @overload one_or_more(parser)
|
147
|
-
# @return [Repeat] a new one-or-more parser
|
148
|
-
# @overload one_or_more(arg)
|
149
|
-
# @return [Repeat] a new one-or-more parser using arg to define a match
|
150
|
-
# parser
|
151
|
-
# @see #match
|
152
|
-
def one_or_more(arg)
|
153
|
-
Repeat[to_parser(arg), 1, nil]
|
154
|
-
end
|
155
|
-
|
156
|
-
alias_method :some, :one_or_more
|
157
|
-
|
158
|
-
# Create a generalized repeat parser.
|
159
|
-
#
|
160
|
-
# @overload one_or_more(parser, min, max)
|
161
|
-
# @return [Repeat] a new repeat parser with the given bounds
|
162
|
-
# @overload one_or_more(arg, min, max)
|
163
|
-
# @return [Repeat] a new repeat parser using arg to define a match
|
164
|
-
# parser
|
165
|
-
# @see #match
|
166
|
-
def repeat(arg, min, max)
|
167
|
-
Repeat[to_parser(arg), min, max]
|
168
|
-
end
|
169
|
-
|
170
|
-
# Create a new list parser.
|
171
|
-
#
|
172
|
-
# @overload list(term_parser, sep_parser, min, max)
|
173
|
-
# @return [ListParser] a new list parser
|
174
|
-
# @overload list(term_arg, sep_arg, min, max)
|
175
|
-
# @return [ListParser] a new list parser using args to define a match parsers
|
176
|
-
# @see #match
|
177
|
-
def list(term_arg, sep_arg, min, max)
|
178
|
-
ListParser[to_parser(term_arg), to_parser(sep_arg), min, max]
|
179
|
-
end
|
180
|
-
|
181
|
-
# Create a new assert parser.
|
182
|
-
#
|
183
|
-
# @overload assert(parser)
|
184
|
-
# @return [Assert] a new assert parser
|
185
|
-
# @overload assert(arg)
|
186
|
-
# @return [Assert] a new assert parser using arg to define a match
|
187
|
-
# parser
|
188
|
-
# @see #match
|
189
|
-
def assert(arg)
|
190
|
-
Assert[to_parser(arg)]
|
191
|
-
end
|
192
|
-
|
193
|
-
# Create a new disallow parser.
|
194
|
-
#
|
195
|
-
# @overload disallow(parser)
|
196
|
-
# @return [Disallow] a new disallow parser
|
197
|
-
# @overload disallow(arg)
|
198
|
-
# @return [Disallow] a new disallow parser using arg to define a match
|
199
|
-
# parser
|
200
|
-
# @see #match
|
201
|
-
def disallow(arg)
|
202
|
-
Disallow[to_parser(arg)]
|
203
|
-
end
|
204
|
-
|
205
|
-
# @return the eof parser
|
206
|
-
def eof
|
207
|
-
Eof[]
|
208
|
-
end
|
209
|
-
|
210
|
-
# @return the "E" symbol parser
|
211
|
-
def e
|
212
|
-
ESymbol[]
|
213
|
-
end
|
214
|
-
|
215
|
-
# Create a new semantic action that dispatches to a method.
|
216
|
-
#
|
217
|
-
# @overload dispatch_action(parser)
|
218
|
-
# @return [DispatchAction] a new semantic action
|
219
|
-
# @overload dispatch_action(arg)
|
220
|
-
# @return [DispatchAction] a new semantic action using arg to define a
|
221
|
-
# match parser
|
222
|
-
# @see #match
|
223
|
-
def dispatch_action(arg, attrs={})
|
224
|
-
DispatchAction[to_parser(arg), attrs]
|
225
|
-
end
|
226
|
-
|
227
|
-
# Create a new semantic action that evaluates ruby code.
|
228
|
-
#
|
229
|
-
# @overload direct_action(parser, code)
|
230
|
-
# @return [DirectAction] a new semantic action
|
231
|
-
# @overload direct_action(arg, code)
|
232
|
-
# @return [DirectAction] a new semantic action using arg to define a
|
233
|
-
# match parser
|
234
|
-
# @see #match
|
235
|
-
def direct_action(arg, code)
|
236
|
-
DirectAction[to_parser(arg), code]
|
237
|
-
end
|
238
|
-
|
239
|
-
# Create a new semantic action that evaluates ruby code for effect.
|
240
|
-
#
|
241
|
-
# @overload side_effect(parser, code)
|
242
|
-
# @return [SideEffect] a new semantic action
|
243
|
-
# @overload side_effect(arg, code)
|
244
|
-
# @return [SideEffect] a new semantic action using arg to define a
|
245
|
-
# match parser
|
246
|
-
# @see #match
|
247
|
-
def side_effect(arg, code)
|
248
|
-
SideEffect[to_parser(arg), code]
|
249
|
-
end
|
250
|
-
|
251
|
-
# Create a new positive semantic predicate.
|
252
|
-
#
|
253
|
-
# @overload semantic_assert(parser, code)
|
254
|
-
# @return [SemanticAssert] a new positive Semantic predicate
|
255
|
-
# @overload semantic_assert(arg, code)
|
256
|
-
# @return [SemanticAssert] a new positive Semantic predicate using arg
|
257
|
-
# to define a match parser
|
258
|
-
# @see #match
|
259
|
-
def semantic_assert(arg, code)
|
260
|
-
SemanticAssert[to_parser(arg), code]
|
261
|
-
end
|
262
|
-
|
263
|
-
# Create a new negative semantic predicate.
|
264
|
-
#
|
265
|
-
# @overload semantic_disallow(parser, code)
|
266
|
-
# @return [SemanticDisallow] a new negative Semantic predicate
|
267
|
-
# @overload semantic_disallow(arg, code)
|
268
|
-
# @return [SemanticDisallow] a new negative Semantic predicate using
|
269
|
-
# arg to define a match parser
|
270
|
-
# @see #match
|
271
|
-
def semantic_disallow(arg, code)
|
272
|
-
SemanticDisallow[to_parser(arg), code]
|
273
|
-
end
|
274
|
-
|
275
|
-
# Create a new token parser or token rule.
|
276
|
-
#
|
277
|
-
# @overload token(rule_name, &block)
|
278
|
-
# @return [Rule] a new token rule
|
279
|
-
# @overload token(parser)
|
280
|
-
# @return [Token] a new token parser
|
281
|
-
# @overload token(arg)
|
282
|
-
# @return [Token] a new token parser using arg to define a match parser
|
283
|
-
# @see #match
|
284
|
-
def token(arg, &block)
|
285
|
-
if block_given?
|
286
|
-
rule(arg) { token(instance_exec(self, &block)) }
|
287
|
-
else
|
288
|
-
Token[to_parser(arg)]
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
# Create a new skip parser.
|
293
|
-
#
|
294
|
-
# @overload skip(parser)
|
295
|
-
# @return [Skip] a new skip parser
|
296
|
-
# @overload skip(arg)
|
297
|
-
# @return [Skip] a new skip parser using arg to define a match
|
298
|
-
# parser
|
299
|
-
# @see #match
|
300
|
-
def skip(arg)
|
301
|
-
Skip[to_parser(arg)]
|
302
|
-
end
|
303
|
-
|
304
|
-
# Create a new labeled parser.
|
305
|
-
#
|
306
|
-
# @overload label(parser)
|
307
|
-
# @return [Label] a new labeled parser
|
308
|
-
# @overload label(arg)
|
309
|
-
# @return [Label] a new labeled parser using arg to define a match
|
310
|
-
# parser
|
311
|
-
# @see #match
|
312
|
-
def label(name, arg)
|
313
|
-
Label[name, to_parser(arg)]
|
314
|
-
end
|
315
|
-
|
316
|
-
# @return [Fail] a parser that always fails
|
317
|
-
def fail(message)
|
318
|
-
Fail[:expr, message]
|
319
|
-
end
|
320
|
-
|
321
|
-
# @return [Fail] a parser that fails the entire rule
|
322
|
-
def fail_rule(message)
|
323
|
-
Fail[:rule, message]
|
324
|
-
end
|
325
|
-
|
326
|
-
# @return [Fail] a parser that fails the entire parse
|
327
|
-
def fail_parse(message)
|
328
|
-
Fail[:parse, message]
|
329
|
-
end
|
330
|
-
|
331
|
-
# @return [Match] a parser matching any character
|
332
|
-
def any
|
333
|
-
match /./
|
334
|
-
end
|
335
|
-
|
336
|
-
# @return [Match] a parser matching the POSIX +alnum+ character class
|
337
|
-
def alnum
|
338
|
-
match :ALNUM
|
339
|
-
end
|
340
|
-
|
341
|
-
# @return [Match] a parser matching the POSIX +alpha+ character class
|
342
|
-
def alpha
|
343
|
-
match :ALPHA
|
344
|
-
end
|
345
|
-
|
346
|
-
# @return [Match] a parser matching the POSIX +blank+ character class
|
347
|
-
def blank
|
348
|
-
match :BLANK
|
349
|
-
end
|
350
|
-
|
351
|
-
# @return [Match] a parser matching the POSIX +cntrl+ character class
|
352
|
-
def cntrl
|
353
|
-
match :CNTRL
|
354
|
-
end
|
355
|
-
|
356
|
-
# @return [Match] a parser matching the POSIX +digit+ character class
|
357
|
-
def digit
|
358
|
-
match :DIGIT
|
359
|
-
end
|
360
|
-
|
361
|
-
# @return [Match] a parser matching the POSIX +graph+ character class
|
362
|
-
def graph
|
363
|
-
match :GRAPH
|
364
|
-
end
|
365
|
-
|
366
|
-
# @return [Match] a parser matching the POSIX +lower+ character class
|
367
|
-
def lower
|
368
|
-
match :LOWER
|
369
|
-
end
|
370
|
-
|
371
|
-
# @return [Match] a parser matching the POSIX +print+ character class
|
372
|
-
def print
|
373
|
-
match :PRINT
|
374
|
-
end
|
375
|
-
|
376
|
-
# @return [Match] a parser matching the POSIX +punct+ character class
|
377
|
-
def punct
|
378
|
-
match :PUNCT
|
379
|
-
end
|
380
|
-
|
381
|
-
# @return [Match] a parser matching the POSIX +space+ character class
|
382
|
-
def space
|
383
|
-
match :SPACE
|
384
|
-
end
|
385
|
-
|
386
|
-
# @return [Match] a parser matching the POSIX +upper+ character class
|
387
|
-
def upper
|
388
|
-
match :UPPER
|
389
|
-
end
|
390
|
-
|
391
|
-
# @return [Match] a parser matching the POSIX +xdigit+ character class
|
392
|
-
def xdigit
|
393
|
-
match :XDIGIT
|
394
|
-
end
|
395
|
-
|
396
|
-
# @return [Match] a parser matching the +word+ character class
|
397
|
-
def word
|
398
|
-
match :WORD
|
399
|
-
end
|
400
|
-
|
401
|
-
private
|
402
|
-
|
403
|
-
def to_parser(o)
|
404
|
-
case o
|
405
|
-
when Parser then o
|
406
|
-
when nil then nil
|
407
|
-
when false then nil
|
408
|
-
else match(o)
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
end
|
413
|
-
end
|
414
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'rattler/parsers'
|
2
|
-
|
3
|
-
module Rattler::Parsers
|
4
|
-
#
|
5
|
-
# +SemanticAssert+ decorates a parser to peform a symantic action on success
|
6
|
-
# by evaluating ruby code and succeed if the result is a true value.
|
7
|
-
#
|
8
|
-
# @author Jason Arhart
|
9
|
-
#
|
10
|
-
class SemanticAssert < DirectAction
|
11
|
-
|
12
|
-
protected
|
13
|
-
|
14
|
-
def create_bindable_code
|
15
|
-
AssertCode.new(code)
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|