mail 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mail might be problematic. Click here for more details.

Files changed (129) hide show
  1. data/Rakefile +1 -1
  2. data/lib/mail.rb +2 -1
  3. data/lib/mail/version.rb +1 -1
  4. data/lib/vendor/treetop-1.4.3/History.txt +18 -0
  5. data/lib/vendor/treetop-1.4.3/LICENSE +19 -0
  6. data/lib/vendor/treetop-1.4.3/README.md +164 -0
  7. data/lib/vendor/treetop-1.4.3/Rakefile +23 -0
  8. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Snippets/grammar ___ end.tmSnippet +20 -0
  9. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Snippets/rule ___ end.tmSnippet +18 -0
  10. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/designable.nib +1524 -0
  11. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/keyedobjects.nib +0 -0
  12. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/syntax_tree_viewer.rb +117 -0
  13. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Syntaxes/Treetop Grammar.tmLanguage +251 -0
  14. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/info.plist +10 -0
  15. data/lib/vendor/treetop-1.4.3/benchmark/seqpar.gnuplot +15 -0
  16. data/lib/vendor/treetop-1.4.3/benchmark/seqpar.treetop +16 -0
  17. data/lib/vendor/treetop-1.4.3/benchmark/seqpar_benchmark.rb +107 -0
  18. data/lib/vendor/treetop-1.4.3/bin/tt +112 -0
  19. data/lib/vendor/treetop-1.4.3/doc/contributing_and_planned_features.markdown +103 -0
  20. data/lib/vendor/treetop-1.4.3/doc/grammar_composition.markdown +65 -0
  21. data/lib/vendor/treetop-1.4.3/doc/index.markdown +90 -0
  22. data/lib/vendor/treetop-1.4.3/doc/pitfalls_and_advanced_techniques.markdown +51 -0
  23. data/lib/vendor/treetop-1.4.3/doc/semantic_interpretation.markdown +189 -0
  24. data/lib/vendor/treetop-1.4.3/doc/site.rb +112 -0
  25. data/lib/vendor/treetop-1.4.3/doc/sitegen.rb +65 -0
  26. data/lib/vendor/treetop-1.4.3/doc/syntactic_recognition.markdown +100 -0
  27. data/lib/vendor/treetop-1.4.3/doc/using_in_ruby.markdown +21 -0
  28. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic.rb +551 -0
  29. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic.treetop +97 -0
  30. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_node_classes.rb +7 -0
  31. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb +54 -0
  32. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus +0 -0
  33. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus.rb +718 -0
  34. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus.treetop +132 -0
  35. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus_node_classes.rb +5 -0
  36. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus_test.rb +89 -0
  37. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/test_helper.rb +18 -0
  38. data/lib/vendor/treetop-1.4.3/lib/treetop.rb +17 -0
  39. data/lib/vendor/treetop-1.4.3/lib/treetop/bootstrap_gen_1_metagrammar.rb +45 -0
  40. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler.rb +6 -0
  41. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/grammar_compiler.rb +44 -0
  42. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/lexical_address_space.rb +17 -0
  43. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/metagrammar.rb +3366 -0
  44. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/metagrammar.treetop +436 -0
  45. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes.rb +20 -0
  46. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/anything_symbol.rb +18 -0
  47. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/atomic_expression.rb +14 -0
  48. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/character_class.rb +28 -0
  49. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/choice.rb +31 -0
  50. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/declaration_sequence.rb +24 -0
  51. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/grammar.rb +28 -0
  52. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/inline_module.rb +27 -0
  53. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/nonterminal.rb +13 -0
  54. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/optional.rb +19 -0
  55. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parenthesized_expression.rb +9 -0
  56. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parsing_expression.rb +146 -0
  57. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parsing_rule.rb +58 -0
  58. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/predicate.rb +45 -0
  59. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/predicate_block.rb +16 -0
  60. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb +55 -0
  61. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/sequence.rb +71 -0
  62. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/terminal.rb +20 -0
  63. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/transient_prefix.rb +9 -0
  64. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/treetop_file.rb +9 -0
  65. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/ruby_builder.rb +113 -0
  66. data/lib/vendor/treetop-1.4.3/lib/treetop/ruby_extensions.rb +2 -0
  67. data/lib/vendor/treetop-1.4.3/lib/treetop/ruby_extensions/string.rb +42 -0
  68. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime.rb +5 -0
  69. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/compiled_parser.rb +110 -0
  70. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list.rb +4 -0
  71. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/head_node.rb +15 -0
  72. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb +200 -0
  73. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/node.rb +164 -0
  74. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/syntax_node.rb +114 -0
  75. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/terminal_parse_failure.rb +16 -0
  76. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/terminal_syntax_node.rb +17 -0
  77. data/lib/vendor/treetop-1.4.3/lib/treetop/version.rb +9 -0
  78. data/lib/vendor/treetop-1.4.3/script/generate_metagrammar.rb +14 -0
  79. data/lib/vendor/treetop-1.4.3/script/svnadd +11 -0
  80. data/lib/vendor/treetop-1.4.3/script/svnrm +11 -0
  81. data/lib/vendor/treetop-1.4.3/spec/compiler/and_predicate_spec.rb +36 -0
  82. data/lib/vendor/treetop-1.4.3/spec/compiler/anything_symbol_spec.rb +44 -0
  83. data/lib/vendor/treetop-1.4.3/spec/compiler/character_class_spec.rb +276 -0
  84. data/lib/vendor/treetop-1.4.3/spec/compiler/choice_spec.rb +80 -0
  85. data/lib/vendor/treetop-1.4.3/spec/compiler/circular_compilation_spec.rb +28 -0
  86. data/lib/vendor/treetop-1.4.3/spec/compiler/failure_propagation_functional_spec.rb +21 -0
  87. data/lib/vendor/treetop-1.4.3/spec/compiler/grammar_compiler_spec.rb +84 -0
  88. data/lib/vendor/treetop-1.4.3/spec/compiler/grammar_spec.rb +41 -0
  89. data/lib/vendor/treetop-1.4.3/spec/compiler/multibyte_chars_spec.rb +46 -0
  90. data/lib/vendor/treetop-1.4.3/spec/compiler/nonterminal_symbol_spec.rb +40 -0
  91. data/lib/vendor/treetop-1.4.3/spec/compiler/not_predicate_spec.rb +38 -0
  92. data/lib/vendor/treetop-1.4.3/spec/compiler/one_or_more_spec.rb +35 -0
  93. data/lib/vendor/treetop-1.4.3/spec/compiler/optional_spec.rb +37 -0
  94. data/lib/vendor/treetop-1.4.3/spec/compiler/parenthesized_expression_spec.rb +19 -0
  95. data/lib/vendor/treetop-1.4.3/spec/compiler/parsing_rule_spec.rb +61 -0
  96. data/lib/vendor/treetop-1.4.3/spec/compiler/repeated_subrule_spec.rb +29 -0
  97. data/lib/vendor/treetop-1.4.3/spec/compiler/semantic_predicate_spec.rb +175 -0
  98. data/lib/vendor/treetop-1.4.3/spec/compiler/sequence_spec.rb +115 -0
  99. data/lib/vendor/treetop-1.4.3/spec/compiler/terminal_spec.rb +81 -0
  100. data/lib/vendor/treetop-1.4.3/spec/compiler/terminal_symbol_spec.rb +37 -0
  101. data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar.treetop +7 -0
  102. data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar.tt +7 -0
  103. data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar_do.treetop +7 -0
  104. data/lib/vendor/treetop-1.4.3/spec/compiler/tt_compiler_spec.rb +216 -0
  105. data/lib/vendor/treetop-1.4.3/spec/compiler/zero_or_more_spec.rb +56 -0
  106. data/lib/vendor/treetop-1.4.3/spec/composition/a.treetop +11 -0
  107. data/lib/vendor/treetop-1.4.3/spec/composition/b.treetop +11 -0
  108. data/lib/vendor/treetop-1.4.3/spec/composition/c.treetop +10 -0
  109. data/lib/vendor/treetop-1.4.3/spec/composition/d.treetop +10 -0
  110. data/lib/vendor/treetop-1.4.3/spec/composition/f.treetop +17 -0
  111. data/lib/vendor/treetop-1.4.3/spec/composition/grammar_composition_spec.rb +40 -0
  112. data/lib/vendor/treetop-1.4.3/spec/composition/subfolder/e_includes_c.treetop +15 -0
  113. data/lib/vendor/treetop-1.4.3/spec/ruby_extensions/string_spec.rb +32 -0
  114. data/lib/vendor/treetop-1.4.3/spec/runtime/compiled_parser_spec.rb +101 -0
  115. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/delete_spec.rb +147 -0
  116. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/expire_range_spec.rb +349 -0
  117. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/insert_and_delete_node.rb +385 -0
  118. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/insert_spec.rb +660 -0
  119. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +6175 -0
  120. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +58 -0
  121. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/palindromic_fixture.rb +23 -0
  122. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +164 -0
  123. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/spec_helper.rb +84 -0
  124. data/lib/vendor/treetop-1.4.3/spec/runtime/syntax_node_spec.rb +77 -0
  125. data/lib/vendor/treetop-1.4.3/spec/spec_helper.rb +110 -0
  126. data/lib/vendor/treetop-1.4.3/spec/spec_suite.rb +4 -0
  127. data/lib/vendor/treetop-1.4.3/treetop.gemspec +18 -0
  128. data/lib/vendor/treetop.rb +5 -0
  129. metadata +126 -11
@@ -0,0 +1,18 @@
1
+ module Treetop
2
+ module Compiler
3
+ class AnythingSymbol < AtomicExpression
4
+ def compile(address, builder, parent_expression = nil)
5
+ super
6
+ builder.if__ "index < input_length" do
7
+ assign_result "instantiate_node(#{node_class_name},input, index...(index + 1))"
8
+ extend_result_with_inline_module
9
+ builder << "@index += 1"
10
+ end
11
+ builder.else_ do
12
+ builder << 'terminal_parse_failure("any character")'
13
+ assign_result 'nil'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ module Treetop
2
+ module Compiler
3
+ class AtomicExpression < ParsingExpression
4
+ def inline_modules
5
+ []
6
+ end
7
+
8
+ def single_quote(string)
9
+ # Double any backslashes, then backslash any single-quotes:
10
+ "'#{string.gsub(/\\/) { '\\\\' }.gsub(/'/) { "\\'"}}'"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ module Treetop
2
+ module Compiler
3
+ class CharacterClass < AtomicExpression
4
+ def compile(address, builder, parent_expression = nil)
5
+ super
6
+
7
+ builder.if__ "has_terminal?(#{grounded_regexp(text_value)}, true, index)" do
8
+ if address == 0 || decorated?
9
+ assign_result "instantiate_node(#{node_class_name},input, index...(index + 1))"
10
+ extend_result_with_inline_module
11
+ else
12
+ assign_lazily_instantiated_node
13
+ end
14
+ builder << "@index += 1"
15
+ end
16
+ builder.else_ do
17
+ # "terminal_parse_failure(#{single_quote(characters)})"
18
+ assign_result 'nil'
19
+ end
20
+ end
21
+
22
+ def grounded_regexp(string)
23
+ # Double any backslashes, then backslash any single-quotes:
24
+ "'\\G#{string.gsub(/\\/) { '\\\\' }.gsub(/'/) { "\\'"}}'"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ module Treetop
2
+ module Compiler
3
+ class Choice < ParsingExpression
4
+ def compile(address, builder, parent_expression = nil)
5
+ super
6
+ begin_comment(self)
7
+ use_vars :result, :start_index
8
+ compile_alternatives(alternatives)
9
+ end_comment(self)
10
+ end
11
+
12
+ def compile_alternatives(alternatives)
13
+ obtain_new_subexpression_address
14
+ alternatives.first.compile(subexpression_address, builder)
15
+ builder.if__ subexpression_success? do
16
+ assign_result subexpression_result_var
17
+ extend_result_with_declared_module
18
+ extend_result_with_inline_module
19
+ end
20
+ builder.else_ do
21
+ if alternatives.size == 1
22
+ reset_index
23
+ assign_failure start_index_var
24
+ else
25
+ compile_alternatives(alternatives[1..-1])
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ module Treetop
2
+ module Compiler
3
+ class DeclarationSequence < Runtime::SyntaxNode
4
+
5
+ def compile(builder)
6
+ unless rules.empty?
7
+ builder.method_declaration("root") do
8
+ builder << "@root || :#{rules.first.name}"
9
+ end
10
+ builder.newline
11
+ end
12
+
13
+ declarations.each do |declaration|
14
+ declaration.compile(builder)
15
+ builder.newline
16
+ end
17
+ end
18
+
19
+ def rules
20
+ declarations.select { |declaration| declaration.instance_of?(ParsingRule) }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module Treetop
2
+ module Compiler
3
+ class Grammar < Runtime::SyntaxNode
4
+ def compile
5
+ builder = RubyBuilder.new
6
+
7
+ builder.module_declaration "#{grammar_name.text_value}" do
8
+ builder.in(indent_level) # account for initial indentation of grammar declaration
9
+ builder << "include Treetop::Runtime"
10
+ builder.newline
11
+ declaration_sequence.compile(builder)
12
+ end
13
+ builder.newline
14
+ builder.class_declaration "#{parser_name} < Treetop::Runtime::CompiledParser" do
15
+ builder << "include #{grammar_name.text_value}"
16
+ end
17
+ end
18
+
19
+ def indent_level
20
+ input.column_of(interval.begin) - 1
21
+ end
22
+
23
+ def parser_name
24
+ grammar_name.text_value + 'Parser'
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ module Treetop
2
+ module Compiler
3
+ module InlineModuleMixin
4
+ attr_reader :module_name
5
+
6
+ def compile(index, builder, rule)
7
+ @module_name = "#{rule.name.treetop_camelize}#{index}"
8
+ end
9
+ end
10
+
11
+ class InlineModule < Runtime::SyntaxNode
12
+
13
+ include InlineModuleMixin
14
+
15
+ def compile(index, builder, rule)
16
+ super
17
+ builder.module_declaration(module_name) do
18
+ builder << ruby_code.gsub(/\A\n/, '').rstrip
19
+ end
20
+ end
21
+
22
+ def ruby_code
23
+ elements[1].text_value
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ module Treetop
2
+ module Compiler
3
+ class Nonterminal < AtomicExpression
4
+ def compile(address, builder, parent_expression = nil)
5
+ super
6
+ use_vars :result
7
+ assign_result text_value == 'super' ? 'super' : "_nt_#{text_value}"
8
+ extend_result_with_declared_module
9
+ extend_result_with_inline_module
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ module Treetop
2
+ module Compiler
3
+ class Optional < ParsingExpression
4
+ def compile(address, builder, parent_expression)
5
+ super
6
+ use_vars :result
7
+ obtain_new_subexpression_address
8
+ parent_expression.atomic.compile(subexpression_address, builder)
9
+
10
+ builder.if__ subexpression_success? do
11
+ assign_result subexpression_result_var
12
+ end
13
+ builder.else_ do
14
+ assign_result epsilon_node
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module Treetop
2
+ module Compiler
3
+ class ParenthesizedExpression < ParsingExpression
4
+ def compile(address, builder, parent_expression = nil)
5
+ elements[2].compile(address, builder, parent_expression)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,146 @@
1
+ module Treetop
2
+ module Compiler
3
+ class ParsingExpression < Runtime::SyntaxNode
4
+ attr_reader :address, :builder, :subexpression_address, :var_symbols, :parent_expression
5
+
6
+ def compile(address, builder, parent_expression)
7
+ @address = address
8
+ @builder = builder
9
+ @parent_expression = parent_expression
10
+ end
11
+
12
+ def node_class_name
13
+ parent_expression && parent_expression.node_class_name || 'SyntaxNode'
14
+ end
15
+
16
+ def declared_module_name
17
+ parent_expression && parent_expression.node_class_name
18
+ end
19
+
20
+ def inline_module_name
21
+ parent_expression && parent_expression.inline_module_name
22
+ end
23
+
24
+ def decorated?
25
+ parent_expression && (parent_expression.node_class_name || parent_expression.node_class_name || parent_expression.inline_module_name)
26
+ end
27
+
28
+ def optional_arg(arg)
29
+ if arg
30
+ ", #{arg}"
31
+ else
32
+ ''
33
+ end
34
+ end
35
+
36
+ def use_vars(*var_symbols)
37
+ @var_symbols = var_symbols
38
+ builder << var_initialization
39
+ end
40
+
41
+ def result_var
42
+ var(:result)
43
+ end
44
+
45
+ def accumulator_var
46
+ var(:accumulator)
47
+ end
48
+
49
+ def start_index_var
50
+ var(:start_index)
51
+ end
52
+
53
+ def subexpression_result_var
54
+ "r#{subexpression_address}"
55
+ end
56
+
57
+ def subexpression_success?
58
+ subexpression_result_var
59
+ end
60
+
61
+ def obtain_new_subexpression_address
62
+ @subexpression_address = builder.next_address
63
+ end
64
+
65
+ def accumulate_subexpression_result
66
+ builder.accumulate accumulator_var, subexpression_result_var
67
+ end
68
+
69
+ def assign_result(value_ruby)
70
+ builder.assign result_var, value_ruby
71
+ end
72
+
73
+ def extend_result(module_name)
74
+ builder.extend result_var, module_name
75
+ end
76
+
77
+ def extend_result_with_declared_module
78
+ extend_result declared_module_name if declared_module_name
79
+ end
80
+
81
+ def extend_result_with_inline_module
82
+ extend_result inline_module_name if inline_module_name
83
+ end
84
+
85
+ def reset_index
86
+ builder.assign '@index', start_index_var
87
+ end
88
+
89
+ def epsilon_node
90
+ "instantiate_node(SyntaxNode,input, index...index)"
91
+ end
92
+
93
+ def assign_failure(start_index_var)
94
+ assign_result("nil")
95
+ end
96
+
97
+ def assign_lazily_instantiated_node
98
+ assign_result("true")
99
+ end
100
+
101
+ def var_initialization
102
+ left, right = [], []
103
+ var_symbols.each do |symbol|
104
+ if init_value(symbol)
105
+ left << var(symbol)
106
+ right << init_value(symbol)
107
+ end
108
+ end
109
+ if left.empty?
110
+ ""
111
+ else
112
+ left.join(', ') + ' = ' + right.join(', ')
113
+ end
114
+ end
115
+
116
+ def var(var_symbol)
117
+ case var_symbol
118
+ when :result then "r#{address}"
119
+ when :accumulator then "s#{address}"
120
+ when :start_index then "i#{address}"
121
+ else raise "Unknown var symbol #{var_symbol}."
122
+ end
123
+ end
124
+
125
+ def init_value(var_symbol)
126
+ case var_symbol
127
+ when :accumulator then '[]'
128
+ when :start_index then 'index'
129
+ else nil
130
+ end
131
+ end
132
+
133
+ def begin_comment(expression)
134
+ #builder << "# begin #{on_one_line(expression)}"
135
+ end
136
+
137
+ def end_comment(expression)
138
+ #builder << "# end #{on_one_line(expression)}"
139
+ end
140
+
141
+ def on_one_line(expression)
142
+ expression.text_value.tr("\n", ' ')
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,58 @@
1
+ module Treetop
2
+ module Compiler
3
+ class ParsingRule < Runtime::SyntaxNode
4
+
5
+ def compile(builder)
6
+ compile_inline_module_declarations(builder)
7
+ generate_method_definition(builder)
8
+ end
9
+
10
+ def compile_inline_module_declarations(builder)
11
+ parsing_expression.inline_modules.each_with_index do |inline_module, i|
12
+ inline_module.compile(i, builder, self)
13
+ builder.newline
14
+ end
15
+ end
16
+
17
+ def generate_method_definition(builder)
18
+ builder.reset_addresses
19
+ expression_address = builder.next_address
20
+ result_var = "r#{expression_address}"
21
+
22
+ builder.method_declaration(method_name) do
23
+ builder.assign 'start_index', 'index'
24
+ generate_cache_lookup(builder)
25
+ builder.newline
26
+ parsing_expression.compile(expression_address, builder)
27
+ builder.newline
28
+ generate_cache_storage(builder, result_var)
29
+ builder.newline
30
+ builder << result_var
31
+ end
32
+ end
33
+
34
+ def generate_cache_lookup(builder)
35
+ builder.if_ "node_cache[:#{name}].has_key?(index)" do
36
+ builder.assign 'cached', "node_cache[:#{name}][index]"
37
+ builder.if_ "cached" do
38
+ builder << 'cached = SyntaxNode.new(input, index...(index + 1)) if cached == true'
39
+ builder << '@index = cached.interval.end'
40
+ end
41
+ builder << 'return cached'
42
+ end
43
+ end
44
+
45
+ def generate_cache_storage(builder, result_var)
46
+ builder.assign "node_cache[:#{name}][start_index]", result_var
47
+ end
48
+
49
+ def method_name
50
+ "_nt_#{name}"
51
+ end
52
+
53
+ def name
54
+ nonterminal.text_value
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,45 @@
1
+ module Treetop
2
+ module Compiler
3
+ class Predicate < ParsingExpression
4
+ def compile(address, builder, parent_expression)
5
+ super
6
+ begin_comment(parent_expression)
7
+ use_vars :result, :start_index
8
+ obtain_new_subexpression_address
9
+ parent_expression.prefixed_expression.compile(subexpression_address, builder)
10
+ builder.if__(subexpression_success?) { when_success }
11
+ builder.else_ { when_failure }
12
+ end_comment(parent_expression)
13
+ end
14
+
15
+ def assign_failure
16
+ super(start_index_var)
17
+ end
18
+
19
+ def assign_success
20
+ reset_index
21
+ assign_result epsilon_node
22
+ end
23
+ end
24
+
25
+ class AndPredicate < Predicate
26
+ def when_success
27
+ assign_success
28
+ end
29
+
30
+ def when_failure
31
+ assign_failure
32
+ end
33
+ end
34
+
35
+ class NotPredicate < Predicate
36
+ def when_success
37
+ assign_failure
38
+ end
39
+
40
+ def when_failure
41
+ assign_success
42
+ end
43
+ end
44
+ end
45
+ end