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,16 @@
1
+ module Treetop
2
+ module Compiler
3
+ class PredicateBlock < ParsingExpression
4
+ def compile(index, builder, parent_expression = nil)
5
+ super
6
+ # REVISIT: This is distinctly dodgey, but since we can only be called from
7
+ # two contexts, and it works in both those, I'm going with it for now, as
8
+ # opposed to doing the major refactor of providing a proper way of accessing
9
+ # the parent's accumulator variable.
10
+ p = parent
11
+ p = p.parent while p && !p.respond_to?(:accumulator_var)
12
+ assign_result "lambda #{text_value}.call(#{p ? p.accumulator_var : ""})"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,55 @@
1
+ module Treetop
2
+ module Compiler
3
+ class Repetition < ParsingExpression
4
+ def compile(address, builder, parent_expression)
5
+ super
6
+ repeated_expression = parent_expression.atomic
7
+ begin_comment(parent_expression)
8
+ use_vars :result, :accumulator, :start_index
9
+
10
+ builder.loop do
11
+ obtain_new_subexpression_address
12
+ repeated_expression.compile(subexpression_address, builder)
13
+ builder.if__ subexpression_success? do
14
+ accumulate_subexpression_result
15
+ end
16
+ builder.else_ do
17
+ builder.break
18
+ end
19
+ end
20
+ end
21
+
22
+ def inline_module_name
23
+ parent_expression.inline_module_name
24
+ end
25
+
26
+ def assign_and_extend_result
27
+ assign_result "instantiate_node(#{node_class_name},input, #{start_index_var}...index, #{accumulator_var})"
28
+ extend_result_with_inline_module
29
+ end
30
+ end
31
+
32
+
33
+ class ZeroOrMore < Repetition
34
+ def compile(address, builder, parent_expression)
35
+ super
36
+ assign_and_extend_result
37
+ end_comment(parent_expression)
38
+ end
39
+ end
40
+
41
+ class OneOrMore < Repetition
42
+ def compile(address, builder, parent_expression)
43
+ super
44
+ builder.if__ "#{accumulator_var}.empty?" do
45
+ reset_index
46
+ assign_failure start_index_var
47
+ end
48
+ builder.else_ do
49
+ assign_and_extend_result
50
+ end
51
+ end_comment(parent_expression)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,71 @@
1
+ module Treetop
2
+ module Compiler
3
+ class Sequence < ParsingExpression
4
+ def compile(address, builder, parent_expression = nil)
5
+ super
6
+ begin_comment(self)
7
+ use_vars :result, :start_index, :accumulator
8
+ compile_sequence_elements(sequence_elements)
9
+ builder.if__ "#{accumulator_var}.last" do
10
+ assign_result "instantiate_node(#{node_class_name},input, #{start_index_var}...index, #{accumulator_var})"
11
+ extend_result sequence_element_accessor_module_name if sequence_element_accessor_module_name
12
+ extend_result_with_inline_module
13
+ end
14
+ builder.else_ do
15
+ reset_index
16
+ assign_failure start_index_var
17
+ end
18
+ end_comment(self)
19
+ end
20
+
21
+ def node_class_name
22
+ node_class_declarations.node_class_name || 'SyntaxNode'
23
+ end
24
+
25
+ def compile_sequence_elements(elements)
26
+ obtain_new_subexpression_address
27
+ elements.first.compile(subexpression_address, builder)
28
+ accumulate_subexpression_result
29
+ if elements.size > 1
30
+ builder.if_ subexpression_success? do
31
+ compile_sequence_elements(elements[1..-1])
32
+ end
33
+ end
34
+ end
35
+
36
+ def sequence_element_accessor_module
37
+ @sequence_element_accessor_module ||= SequenceElementAccessorModule.new(sequence_elements)
38
+ end
39
+
40
+ def sequence_element_accessor_module_name
41
+ sequence_element_accessor_module.module_name
42
+ end
43
+ end
44
+
45
+ class SequenceElementAccessorModule
46
+ include InlineModuleMixin
47
+ attr_reader :sequence_elements
48
+
49
+ def initialize(sequence_elements)
50
+ @sequence_elements = sequence_elements
51
+ end
52
+
53
+ def compile(index, builder, rule)
54
+ super
55
+ builder.module_declaration(module_name) do
56
+ elements_by_name = sequence_elements.inject({}){|h,e| (h[e.label_name.to_s] ||= []) << e; h}
57
+ sequence_elements.each_with_index do |element, index|
58
+ if element.label_name
59
+ repetitions = elements_by_name[element.label_name.to_s]
60
+ label_name = element.label_name + (repetitions.size > 1 ? (repetitions.index(element)+1).to_s : "")
61
+ builder.method_declaration(label_name) do
62
+ builder << "elements[#{index}]"
63
+ end
64
+ builder.newline unless index == sequence_elements.size - 1
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,20 @@
1
+ module Treetop
2
+ module Compiler
3
+ class Terminal < AtomicExpression
4
+ def compile(address, builder, parent_expression = nil)
5
+ super
6
+ string_length = eval(text_value).length
7
+
8
+ builder.if__ "has_terminal?(#{text_value}, false, index)" do
9
+ assign_result "instantiate_node(#{node_class_name},input, index...(index + #{string_length}))"
10
+ extend_result_with_inline_module
11
+ builder << "@index += #{string_length}"
12
+ end
13
+ builder.else_ do
14
+ builder << "terminal_parse_failure(#{text_value})"
15
+ assign_result 'nil'
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ module Treetop
2
+ module Compiler
3
+ class TransientPrefix < ParsingExpression
4
+ def compile(address, builder, parent_expression)
5
+ parent_expression.prefixed_expression.compile(address, builder)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Treetop
2
+ module Compiler
3
+ class TreetopFile < Runtime::SyntaxNode
4
+ def compile
5
+ (elements.map {|elt| elt.compile}).join
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,113 @@
1
+ module Treetop
2
+ module Compiler
3
+ class RubyBuilder
4
+
5
+ attr_reader :level, :address_space, :ruby
6
+
7
+ def initialize
8
+ @level = 0
9
+ @address_space = LexicalAddressSpace.new
10
+ @ruby = ""
11
+ end
12
+
13
+ def <<(ruby_line)
14
+ return if ruby_line.blank?
15
+ ruby << ruby_line.tabto(level) << "\n"
16
+ end
17
+
18
+ def newline
19
+ ruby << "\n"
20
+ end
21
+
22
+ def indented(depth = 2)
23
+ self.in(depth)
24
+ yield
25
+ self.out(depth)
26
+ end
27
+
28
+ def class_declaration(name, &block)
29
+ self << "class #{name}"
30
+ indented(&block)
31
+ self << "end"
32
+ end
33
+
34
+ def module_declaration(name, &block)
35
+ self << "module #{name}"
36
+ indented(&block)
37
+ self << "end"
38
+ end
39
+
40
+ def method_declaration(name, &block)
41
+ self << "def #{name}"
42
+ indented(&block)
43
+ self << "end"
44
+ end
45
+
46
+ def assign(left, right)
47
+ if left.instance_of? Array
48
+ self << "#{left.join(', ')} = #{right.join(', ')}"
49
+ else
50
+ self << "#{left} = #{right}"
51
+ end
52
+ end
53
+
54
+ def extend(var, module_name)
55
+ self << "#{var}.extend(#{module_name})"
56
+ end
57
+
58
+ def accumulate(left, right)
59
+ self << "#{left} << #{right}"
60
+ end
61
+
62
+ def if__(condition, &block)
63
+ self << "if #{condition}"
64
+ indented(&block)
65
+ end
66
+
67
+ def if_(condition, &block)
68
+ if__(condition, &block)
69
+ self << 'end'
70
+ end
71
+
72
+ def else_(&block)
73
+ self << 'else'
74
+ indented(&block)
75
+ self << 'end'
76
+ end
77
+
78
+ def loop(&block)
79
+ self << 'loop do'
80
+ indented(&block)
81
+ self << 'end'
82
+ end
83
+
84
+ def break
85
+ self << 'break'
86
+ end
87
+
88
+ def in(depth = 2)
89
+ @level += depth
90
+ self
91
+ end
92
+
93
+ def out(depth = 2)
94
+ @level -= depth
95
+ self
96
+ end
97
+
98
+ def next_address
99
+ address_space.next_address
100
+ end
101
+
102
+ def reset_addresses
103
+ address_space.reset_addresses
104
+ end
105
+
106
+ private
107
+
108
+ def indent
109
+ " " * level
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,2 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/ruby_extensions/string"
@@ -0,0 +1,42 @@
1
+ class String
2
+ def column_of(index)
3
+ return 1 if index == 0
4
+ newline_index = rindex("\n", index - 1)
5
+ if newline_index
6
+ index - newline_index
7
+ else
8
+ index + 1
9
+ end
10
+ end
11
+
12
+ def line_of(index)
13
+ self[0...index].count("\n") + 1
14
+ end
15
+
16
+ unless method_defined?(:blank?)
17
+ def blank?
18
+ self == ""
19
+ end
20
+ end
21
+
22
+ # The following methods are lifted from Facets 2.0.2
23
+ def tabto(n)
24
+ if self =~ /^( *)\S/
25
+ indent(n - $1.length)
26
+ else
27
+ self
28
+ end
29
+ end
30
+
31
+ def indent(n)
32
+ if n >= 0
33
+ gsub(/^/, ' ' * n)
34
+ else
35
+ gsub(/^ {0,#{-n}}/, "")
36
+ end
37
+ end
38
+
39
+ def treetop_camelize
40
+ to_s.gsub(/\/(.?)/){ "::" + $1.upcase }.gsub(/(^|_)(.)/){ $2.upcase }
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/runtime/compiled_parser"
3
+ require "#{dir}/runtime/syntax_node"
4
+ require "#{dir}/runtime/terminal_parse_failure"
5
+ require "#{dir}/runtime/interval_skip_list"
@@ -0,0 +1,110 @@
1
+ module Treetop
2
+ module Runtime
3
+ class CompiledParser
4
+ include Treetop::Runtime
5
+
6
+ attr_reader :input, :index, :max_terminal_failure_index
7
+ attr_writer :root
8
+ attr_accessor :consume_all_input
9
+ alias :consume_all_input? :consume_all_input
10
+
11
+ def initialize
12
+ self.consume_all_input = true
13
+ end
14
+
15
+ def parse(input, options = {})
16
+ prepare_to_parse(input)
17
+ @index = options[:index] if options[:index]
18
+ result = send("_nt_#{root}")
19
+ return nil if (consume_all_input? && index != input.size)
20
+ return SyntaxNode.new(input, index...(index + 1)) if result == true
21
+ return result
22
+ end
23
+
24
+ def failure_index
25
+ max_terminal_failure_index
26
+ end
27
+
28
+ def failure_line
29
+ @terminal_failures && input.line_of(failure_index)
30
+ end
31
+
32
+ def failure_column
33
+ @terminal_failures && input.column_of(failure_index)
34
+ end
35
+
36
+ def failure_reason
37
+ return nil unless (tf = terminal_failures) && tf.size > 0
38
+ "Expected " +
39
+ (tf.size == 1 ?
40
+ tf[0].expected_string :
41
+ "one of #{tf.map{|f| f.expected_string}.uniq*', '}"
42
+ ) +
43
+ " at line #{failure_line}, column #{failure_column} (byte #{failure_index+1})" +
44
+ " after #{input[index...failure_index]}"
45
+ end
46
+
47
+ def terminal_failures
48
+ @terminal_failures.map! {|tf_ary| TerminalParseFailure.new(*tf_ary) }
49
+ end
50
+
51
+
52
+ protected
53
+
54
+ attr_reader :node_cache, :input_length
55
+ attr_writer :index
56
+
57
+ def prepare_to_parse(input)
58
+ @input = input
59
+ @input_length = input.length
60
+ reset_index
61
+ @node_cache = Hash.new {|hash, key| hash[key] = Hash.new}
62
+ @regexps = {}
63
+ @terminal_failures = []
64
+ @max_terminal_failure_index = 0
65
+ end
66
+
67
+ def reset_index
68
+ @index = 0
69
+ end
70
+
71
+ def parse_anything(node_class = SyntaxNode, inline_module = nil)
72
+ if index < input.length
73
+ result = instantiate_node(node_class,input, index...(index + 1))
74
+ result.extend(inline_module) if inline_module
75
+ @index += 1
76
+ result
77
+ else
78
+ terminal_parse_failure("any character")
79
+ end
80
+ end
81
+
82
+ def instantiate_node(node_type,*args)
83
+ if node_type.respond_to? :new
84
+ node_type.new(*args)
85
+ else
86
+ SyntaxNode.new(*args).extend(node_type)
87
+ end
88
+ end
89
+
90
+ def has_terminal?(terminal, regex, index)
91
+ if regex
92
+ rx = @regexps[terminal] ||= Regexp.new(terminal)
93
+ input.index(rx, index) == index
94
+ else
95
+ input[index, terminal.size] == terminal
96
+ end
97
+ end
98
+
99
+ def terminal_parse_failure(expected_string)
100
+ return nil if index < max_terminal_failure_index
101
+ if index > max_terminal_failure_index
102
+ @max_terminal_failure_index = index
103
+ @terminal_failures = []
104
+ end
105
+ @terminal_failures << [index, expected_string]
106
+ return nil
107
+ end
108
+ end
109
+ end
110
+ end