less 0.8.13 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. data/README.md +10 -1
  2. data/Rakefile +21 -3
  3. data/VERSION +1 -1
  4. data/bin/lessc +0 -8
  5. data/less.gemspec +138 -15
  6. data/lib/less.rb +67 -11
  7. data/lib/less/command.rb +24 -25
  8. data/lib/less/engine.rb +36 -140
  9. data/lib/less/engine/builder.rb +8 -0
  10. data/lib/less/engine/less.tt +374 -0
  11. data/lib/less/engine/nodes.rb +8 -0
  12. data/lib/less/engine/nodes/element.rb +150 -0
  13. data/lib/less/engine/nodes/entity.rb +73 -0
  14. data/lib/less/engine/nodes/function.rb +82 -0
  15. data/lib/less/engine/nodes/literal.rb +135 -0
  16. data/lib/less/engine/nodes/property.rb +112 -0
  17. data/lib/less/engine/nodes/selector.rb +39 -0
  18. data/lib/less/engine/parser.rb +3860 -0
  19. data/lib/vendor/treetop/.gitignore +7 -0
  20. data/lib/vendor/treetop/LICENSE +19 -0
  21. data/lib/vendor/treetop/README +164 -0
  22. data/lib/vendor/treetop/Rakefile +19 -0
  23. data/lib/vendor/treetop/benchmark/seqpar.gnuplot +15 -0
  24. data/lib/vendor/treetop/benchmark/seqpar.treetop +16 -0
  25. data/lib/vendor/treetop/benchmark/seqpar_benchmark.rb +107 -0
  26. data/lib/vendor/treetop/bin/tt +28 -0
  27. data/lib/vendor/treetop/lib/treetop.rb +8 -0
  28. data/lib/vendor/treetop/lib/treetop/bootstrap_gen_1_metagrammar.rb +45 -0
  29. data/lib/vendor/treetop/lib/treetop/compiler.rb +6 -0
  30. data/lib/vendor/treetop/lib/treetop/compiler/grammar_compiler.rb +42 -0
  31. data/lib/vendor/treetop/lib/treetop/compiler/lexical_address_space.rb +17 -0
  32. data/lib/vendor/treetop/lib/treetop/compiler/metagrammar.rb +3097 -0
  33. data/lib/vendor/treetop/lib/treetop/compiler/metagrammar.treetop +408 -0
  34. data/lib/vendor/treetop/lib/treetop/compiler/node_classes.rb +19 -0
  35. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/anything_symbol.rb +18 -0
  36. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/atomic_expression.rb +14 -0
  37. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb +23 -0
  38. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/choice.rb +31 -0
  39. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/declaration_sequence.rb +24 -0
  40. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/grammar.rb +28 -0
  41. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/inline_module.rb +27 -0
  42. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/nonterminal.rb +13 -0
  43. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/optional.rb +19 -0
  44. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parenthesized_expression.rb +9 -0
  45. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_expression.rb +146 -0
  46. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_rule.rb +55 -0
  47. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/predicate.rb +45 -0
  48. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/repetition.rb +55 -0
  49. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/sequence.rb +68 -0
  50. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/terminal.rb +20 -0
  51. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/transient_prefix.rb +9 -0
  52. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/treetop_file.rb +9 -0
  53. data/lib/vendor/treetop/lib/treetop/compiler/ruby_builder.rb +113 -0
  54. data/lib/vendor/treetop/lib/treetop/ruby_extensions.rb +2 -0
  55. data/lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb +42 -0
  56. data/lib/vendor/treetop/lib/treetop/runtime.rb +5 -0
  57. data/lib/vendor/treetop/lib/treetop/runtime/compiled_parser.rb +109 -0
  58. data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list.rb +4 -0
  59. data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/head_node.rb +15 -0
  60. data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb +200 -0
  61. data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/node.rb +164 -0
  62. data/lib/vendor/treetop/lib/treetop/runtime/syntax_node.rb +90 -0
  63. data/lib/vendor/treetop/lib/treetop/runtime/terminal_parse_failure.rb +16 -0
  64. data/lib/vendor/treetop/lib/treetop/runtime/terminal_syntax_node.rb +17 -0
  65. data/lib/vendor/treetop/lib/treetop/version.rb +9 -0
  66. data/lib/vendor/treetop/spec/compiler/and_predicate_spec.rb +36 -0
  67. data/lib/vendor/treetop/spec/compiler/anything_symbol_spec.rb +44 -0
  68. data/lib/vendor/treetop/spec/compiler/character_class_spec.rb +247 -0
  69. data/lib/vendor/treetop/spec/compiler/choice_spec.rb +80 -0
  70. data/lib/vendor/treetop/spec/compiler/circular_compilation_spec.rb +28 -0
  71. data/lib/vendor/treetop/spec/compiler/failure_propagation_functional_spec.rb +21 -0
  72. data/lib/vendor/treetop/spec/compiler/grammar_compiler_spec.rb +84 -0
  73. data/lib/vendor/treetop/spec/compiler/grammar_spec.rb +41 -0
  74. data/lib/vendor/treetop/spec/compiler/nonterminal_symbol_spec.rb +40 -0
  75. data/lib/vendor/treetop/spec/compiler/not_predicate_spec.rb +38 -0
  76. data/lib/vendor/treetop/spec/compiler/one_or_more_spec.rb +35 -0
  77. data/lib/vendor/treetop/spec/compiler/optional_spec.rb +37 -0
  78. data/lib/vendor/treetop/spec/compiler/parenthesized_expression_spec.rb +19 -0
  79. data/lib/vendor/treetop/spec/compiler/parsing_rule_spec.rb +32 -0
  80. data/lib/vendor/treetop/spec/compiler/sequence_spec.rb +115 -0
  81. data/lib/vendor/treetop/spec/compiler/terminal_spec.rb +81 -0
  82. data/lib/vendor/treetop/spec/compiler/terminal_symbol_spec.rb +37 -0
  83. data/lib/vendor/treetop/spec/compiler/test_grammar.treetop +7 -0
  84. data/lib/vendor/treetop/spec/compiler/test_grammar.tt +7 -0
  85. data/lib/vendor/treetop/spec/compiler/test_grammar_do.treetop +7 -0
  86. data/lib/vendor/treetop/spec/compiler/zero_or_more_spec.rb +56 -0
  87. data/lib/vendor/treetop/spec/composition/a.treetop +11 -0
  88. data/lib/vendor/treetop/spec/composition/b.treetop +11 -0
  89. data/lib/vendor/treetop/spec/composition/c.treetop +10 -0
  90. data/lib/vendor/treetop/spec/composition/d.treetop +10 -0
  91. data/lib/vendor/treetop/spec/composition/f.treetop +17 -0
  92. data/lib/vendor/treetop/spec/composition/grammar_composition_spec.rb +40 -0
  93. data/lib/vendor/treetop/spec/composition/subfolder/e_includes_c.treetop +15 -0
  94. data/lib/vendor/treetop/spec/ruby_extensions/string_spec.rb +32 -0
  95. data/lib/vendor/treetop/spec/runtime/compiled_parser_spec.rb +101 -0
  96. data/lib/vendor/treetop/spec/runtime/interval_skip_list/delete_spec.rb +147 -0
  97. data/lib/vendor/treetop/spec/runtime/interval_skip_list/expire_range_spec.rb +349 -0
  98. data/lib/vendor/treetop/spec/runtime/interval_skip_list/insert_and_delete_node.rb +385 -0
  99. data/lib/vendor/treetop/spec/runtime/interval_skip_list/insert_spec.rb +660 -0
  100. data/lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +6175 -0
  101. data/lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +58 -0
  102. data/lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture.rb +23 -0
  103. data/lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +164 -0
  104. data/lib/vendor/treetop/spec/runtime/interval_skip_list/spec_helper.rb +84 -0
  105. data/lib/vendor/treetop/spec/runtime/syntax_node_spec.rb +68 -0
  106. data/lib/vendor/treetop/spec/spec_helper.rb +106 -0
  107. data/lib/vendor/treetop/spec/spec_suite.rb +4 -0
  108. data/lib/vendor/treetop/treetop.gemspec +17 -0
  109. data/spec/command_spec.rb +2 -6
  110. data/spec/css/accessors-1.0.css +18 -0
  111. data/spec/css/big-1.0.css +3768 -0
  112. data/spec/css/comments-1.0.css +9 -0
  113. data/spec/css/css-1.0.css +40 -0
  114. data/spec/css/functions-1.0.css +6 -0
  115. data/spec/css/import-1.0.css +11 -0
  116. data/spec/css/mixins-1.0.css +28 -0
  117. data/spec/css/operations-1.0.css +28 -0
  118. data/spec/css/rulesets-1.0.css +17 -0
  119. data/spec/css/scope-1.0.css +14 -0
  120. data/spec/css/strings-1.0.css +12 -0
  121. data/spec/css/variables-1.0.css +6 -0
  122. data/spec/css/whitespace-1.0.css +9 -0
  123. data/spec/engine_spec.rb +66 -18
  124. data/spec/less/accessors-1.0.less +20 -0
  125. data/spec/less/big-1.0.less +4810 -0
  126. data/spec/less/colors-1.0.less +0 -0
  127. data/spec/less/comments-1.0.less +46 -0
  128. data/spec/less/css-1.0.less +84 -0
  129. data/spec/less/exceptions/mixed-units-error.less +3 -0
  130. data/spec/less/exceptions/name-error-1.0.less +3 -0
  131. data/spec/less/exceptions/syntax-error-1.0.less +3 -0
  132. data/spec/less/functions-1.0.less +6 -0
  133. data/spec/less/import-1.0.less +7 -0
  134. data/spec/less/import/import-test-a.less +2 -0
  135. data/spec/less/import/import-test-b.less +8 -0
  136. data/spec/less/import/import-test-c.less +5 -0
  137. data/spec/less/mixins-1.0.less +43 -0
  138. data/spec/less/operations-1.0.less +39 -0
  139. data/spec/less/rulesets-1.0.less +30 -0
  140. data/spec/less/scope-1.0.less +33 -0
  141. data/spec/less/strings-1.0.less +14 -0
  142. data/spec/less/variables-1.0.less +18 -0
  143. data/spec/less/whitespace-1.0.less +21 -0
  144. data/spec/spec.css +79 -24
  145. data/spec/spec.less +2 -3
  146. data/spec/spec_helper.rb +4 -1
  147. metadata +136 -13
  148. data/lib/less/tree.rb +0 -82
  149. data/spec/css/less-0.8.10.css +0 -30
  150. data/spec/css/less-0.8.11.css +0 -31
  151. data/spec/css/less-0.8.12.css +0 -28
  152. data/spec/css/less-0.8.5.css +0 -24
  153. data/spec/css/less-0.8.6.css +0 -24
  154. data/spec/css/less-0.8.7.css +0 -24
  155. data/spec/css/less-0.8.8.css +0 -25
  156. data/spec/tree_spec.rb +0 -5
@@ -0,0 +1,23 @@
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?(#{single_quote(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
+ end
22
+ end
23
+ 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,55 @@
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 << '@index = cached.interval.end if cached'
38
+ builder << 'return cached'
39
+ end
40
+ end
41
+
42
+ def generate_cache_storage(builder, result_var)
43
+ builder.assign "node_cache[:#{name}][start_index]", result_var
44
+ end
45
+
46
+ def method_name
47
+ "_nt_#{name}"
48
+ end
49
+
50
+ def name
51
+ nonterminal.text_value
52
+ end
53
+ end
54
+ end
55
+ 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
@@ -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