rattler 0.2.0 → 0.2.1

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.
Files changed (38) hide show
  1. data/README.rdoc +2 -0
  2. data/bin/rtlr +8 -5
  3. data/bin/rtlr.bat +0 -0
  4. data/features/command_line/dest_option.feature +34 -0
  5. data/features/command_line/output_option.feature +31 -0
  6. data/features/command_line/parser_generator.feature +80 -0
  7. data/features/grammar/word_literal.feature +3 -3
  8. data/features/step_definitions/cli_steps.rb +3 -0
  9. data/features/step_definitions/{rattler_steps.rb → grammar_steps.rb} +0 -0
  10. data/features/support/env.rb +1 -0
  11. data/lib/rattler.rb +2 -2
  12. data/lib/rattler/back_end/parser_generator.rb +1 -0
  13. data/lib/rattler/back_end/parser_generator/one_or_more_generator.rb +17 -28
  14. data/lib/rattler/back_end/parser_generator/repeat_generating.rb +69 -0
  15. data/lib/rattler/back_end/parser_generator/rule_generator.rb +1 -1
  16. data/lib/rattler/back_end/parser_generator/zero_or_more_generator.rb +9 -63
  17. data/lib/rattler/grammar/grammar_parser.rb +1 -1
  18. data/lib/rattler/grammar/metagrammar.rb +63 -73
  19. data/lib/rattler/grammar/rattler.rtlr +5 -13
  20. data/lib/rattler/parsers/combining.rb +7 -0
  21. data/lib/rattler/parsers/match_joining.rb +7 -0
  22. data/lib/rattler/parsers/predicate.rb +7 -0
  23. data/lib/rattler/parsers/sequence.rb +1 -1
  24. data/lib/rattler/parsers/token.rb +1 -1
  25. data/lib/rattler/runner.rb +6 -0
  26. data/lib/rattler/runtime.rb +1 -1
  27. data/lib/rattler/runtime/extended_packrat_parser.rb +62 -0
  28. data/lib/rattler/runtime/packrat_parser.rb +46 -12
  29. data/lib/rattler/runtime/parse_failure.rb +1 -1
  30. data/lib/rattler/util/parser_spec_helper.rb +1 -0
  31. data/spec/rattler/back_end/parser_generator/one_or_more_generator_spec.rb +14 -4
  32. data/spec/rattler/back_end/parser_generator/zero_or_more_generator_spec.rb +12 -2
  33. data/spec/rattler/runtime/extended_packrat_parser_spec.rb +36 -0
  34. data/spec/rattler/runtime/packrat_parser_spec.rb +1 -1
  35. data/spec/rattler/runtime/shared_parser_examples.rb +29 -0
  36. metadata +462 -79
  37. data/lib/rattler/runtime/wdm_parser.rb +0 -83
  38. data/spec/rattler/runtime/wdm_parser_spec.rb +0 -21
@@ -1,83 +0,0 @@
1
- #
2
- # = rattler/runtime/recursive_descent_parser.rb
3
- #
4
- # Author:: Jason Arhart
5
- # Documentation:: Author
6
- #
7
-
8
- require 'rattler/runtime'
9
-
10
- module Rattler::Runtime
11
- #
12
- # +WDMParser+ implements the algorithm described by Alessandro Warth,
13
- # James R. Douglass, and Todd Millstein for extending packrat parsing to
14
- # support left-recursive grammars. It currently only implements the first
15
- # part to support direct left recursion.
16
- #
17
- # @author Jason Arhart
18
- #
19
- class WDMParser < RecursiveDescentParser
20
-
21
- # Create a new packrat parser to parse +source+.
22
- #
23
- # @param (see RecursiveDescentParser#initialize)
24
- # @option (see RecursiveDescentParser#initialize)
25
- #
26
- def initialize(*args)
27
- super
28
- @memo = {}
29
- end
30
-
31
- # @private
32
- alias_method :eval_rule, :apply
33
- private :eval_rule
34
-
35
- protected
36
-
37
- # Apply a rule by dispatching to the method associated with the given rule
38
- # name, which is named by <tt>"match_#{rule_name}"<tt>, and if the match
39
- # fails set a parse error. The result of applying the rule is memoized so
40
- # that the rule method is invoked at most once at a given parse position.
41
- #
42
- # @param (see RecursiveDescentParser#apply)
43
- # @return (see RecursiveDescentParser#apply)
44
- #
45
- def apply(rule_name)
46
- p = @scanner.pos
47
- key = [rule_name, p]
48
- if memo = @memo[key]
49
- if memo.size == 1
50
- memo[0] = true
51
- false
52
- else
53
- @scanner.pos = memo[1]
54
- memo[0]
55
- end
56
- else
57
- lr = @memo[key] = [false]
58
- result = eval_rule(rule_name)
59
- memo = @memo[key]
60
- memo[0] = result
61
- memo[1] = @scanner.pos
62
- result = grow_lr(rule_name, p, memo) if result and lr[0]
63
- result
64
- end
65
- end
66
-
67
- private
68
-
69
- def grow_lr(rule_name, p, memo)
70
- loop do
71
- @scanner.pos = p
72
- result = eval_rule(rule_name)
73
- if !result or @scanner.pos <= memo[1]
74
- @scanner.pos = memo[1]
75
- return memo[0]
76
- end
77
- memo[0] = result
78
- memo[1] = @scanner.pos
79
- end
80
- end
81
-
82
- end
83
- end
@@ -1,21 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/shared_parser_examples')
3
-
4
- describe Rattler::Runtime::WDMParser do
5
- include RuntimeParserSpecHelper
6
-
7
- it_behaves_like 'a recursive descent parser'
8
-
9
- describe '#match' do
10
- it 'supports left-recursive rules' do
11
- given_rules do
12
- rule :a do
13
- ( match(:a) & match(/\d/) \
14
- | match(/\d/) )
15
- end
16
- end.
17
- parsing('451a').as(:a).should result_in([['4', '5'], '1']).at(3)
18
- end
19
- end
20
-
21
- end