cloudhead-less 1.0.13 → 1.0.16

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/lib/less.rb CHANGED
@@ -67,6 +67,21 @@ class Object
67
67
  def error!(s) raise Exception, s end
68
68
  end
69
69
 
70
+ class Array
71
+ def dissolve
72
+ ary = flatten.compact
73
+ case ary.size
74
+ when 0 then []
75
+ when 1 then first
76
+ else ary
77
+ end
78
+ end
79
+
80
+ def one?
81
+ size == 1
82
+ end
83
+ end
84
+
70
85
  class Class
71
86
  def to_sym
72
87
  self.to_s.to_sym
@@ -4,13 +4,9 @@ module Treetop
4
4
  def compile(address, builder, parent_expression = nil)
5
5
  super
6
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
7
+ builder.if__ "has_terminal?(#{grounded_regexp(text_value)}, true, index)" do
8
+ assign_result "instantiate_node(#{node_class_name},input, index...(index + 1))"
9
+ extend_result_with_inline_module
14
10
  builder << "@index += 1"
15
11
  end
16
12
  builder.else_ do
@@ -18,6 +14,11 @@ module Treetop
18
14
  assign_result 'nil'
19
15
  end
20
16
  end
17
+
18
+ def grounded_regexp(string)
19
+ # Double any backslashes, then backslash any single-quotes:
20
+ "'\\G#{string.gsub(/\\/) { '\\\\' }.gsub(/'/) { "\\'"}}'"
21
+ end
21
22
  end
22
23
  end
23
24
  end
@@ -21,10 +21,6 @@ module Treetop
21
21
  parent_expression && parent_expression.inline_module_name
22
22
  end
23
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
24
  def optional_arg(arg)
29
25
  if arg
30
26
  ", #{arg}"
@@ -93,10 +89,6 @@ module Treetop
93
89
  def assign_failure(start_index_var)
94
90
  assign_result("nil")
95
91
  end
96
-
97
- def assign_lazily_instantiated_node
98
- assign_result("true")
99
- end
100
92
 
101
93
  def var_initialization
102
94
  left, right = [], []
@@ -3,7 +3,7 @@ module Treetop
3
3
  class CompiledParser
4
4
  include Treetop::Runtime
5
5
 
6
- attr_reader :input, :index, :max_terminal_failure_index
6
+ attr_reader :input, :index, :terminal_failures, :max_terminal_failure_index
7
7
  attr_writer :root
8
8
  attr_accessor :consume_all_input
9
9
  alias :consume_all_input? :consume_all_input
@@ -25,26 +25,22 @@ module Treetop
25
25
  end
26
26
 
27
27
  def failure_line
28
- @terminal_failures && input.line_of(failure_index)
28
+ terminal_failures && input.line_of(failure_index)
29
29
  end
30
30
 
31
31
  def failure_column
32
- @terminal_failures && input.column_of(failure_index)
32
+ terminal_failures && input.column_of(failure_index)
33
33
  end
34
34
 
35
35
  def failure_reason
36
36
  return nil unless (tf = terminal_failures) && tf.size > 0
37
- "Expected " +
38
- (tf.size == 1 ?
39
- tf[0].expected_string :
40
- "one of #{tf.map{|f| f.expected_string}.uniq*', '}"
41
- ) +
42
- " at line #{failure_line}, column #{failure_column} (byte #{failure_index+1})" +
43
- " after #{input[index...failure_index]}"
44
- end
45
-
46
- def terminal_failures
47
- @terminal_failures.map! {|tf_ary| TerminalParseFailure.new(*tf_ary) }
37
+ "Expected " +
38
+ (tf.size == 1 ?
39
+ tf[0].expected_string :
40
+ "one of #{tf.map{|f| f.expected_string}.uniq*', '}"
41
+ ) +
42
+ " at line #{failure_line}, column #{failure_column} (byte #{failure_index+1})" +
43
+ " after #{input[index...failure_index]}"
48
44
  end
49
45
 
50
46
 
@@ -91,7 +87,7 @@ module Treetop
91
87
  rx = @regexps[terminal] ||= Regexp.new(terminal)
92
88
  input.index(rx, index) == index
93
89
  else
94
- input[index] == terminal[0] && input.index(terminal, index) == index
90
+ input[index, terminal.size] == terminal
95
91
  end
96
92
  end
97
93
 
@@ -101,7 +97,7 @@ module Treetop
101
97
  @max_terminal_failure_index = index
102
98
  @terminal_failures = []
103
99
  end
104
- @terminal_failures << [index, expected_string]
100
+ terminal_failures << TerminalParseFailure.new(index, expected_string)
105
101
  return nil
106
102
  end
107
103
  end
@@ -1,33 +1,19 @@
1
1
  module Treetop
2
2
  module Runtime
3
3
  class SyntaxNode
4
- attr_reader :input, :interval
4
+ attr_reader :input, :interval, :elements
5
5
  attr_accessor :parent
6
6
 
7
7
  def initialize(input, interval, elements = nil)
8
8
  @input = input
9
9
  @interval = interval
10
10
  if @elements = elements
11
- @comprehensive_elements = @elements unless @elements.delete(true)
12
- @elements.each do |element|
11
+ elements.each do |element|
13
12
  element.parent = self
14
13
  end
15
14
  end
16
15
  end
17
16
 
18
- def elements
19
- return @elements if terminal?
20
- # fill in any gaps in the sequence (lazy instantiation) if needed
21
- @comprehensive_elements ||= interval.inject(@elements) do |elements, index|
22
- unless @elements.any? {|element| element.interval.include?(index) }
23
- node = SyntaxNode.new(input, index...(index + 1))
24
- node.parent = self
25
- elements << node
26
- end
27
- elements
28
- end.sort
29
- end
30
-
31
17
  def terminal?
32
18
  @elements.nil?
33
19
  end
@@ -43,10 +29,6 @@ module Treetop
43
29
  def empty?
44
30
  interval.first == interval.last && interval.exclude_end?
45
31
  end
46
-
47
- def <=>(other)
48
- self.interval.first <=> other.interval.first
49
- end
50
32
 
51
33
  def extension_modules
52
34
  local_extensions =
@@ -1,8 +1,8 @@
1
1
  module Treetop #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
- MINOR = 2
5
- TINY = 6
4
+ MINOR = 3
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -69,18 +69,6 @@ module CharacterClassSpec
69
69
  parse(' 1', :index => 1).should be_nil
70
70
  end
71
71
  end
72
-
73
- describe "a character class followed by a node class declaration and a block" do
74
-
75
- testing_expression "[A-Z] <CharacterClassSpec::Foo>"
76
-
77
- it "actively generates nodes for the character when it is the primary node" do
78
- result = parse('A')
79
- result.should be_a(Treetop::Runtime::SyntaxNode)
80
- result.elements.should be_nil
81
- end
82
-
83
- end
84
72
 
85
73
  describe "A character class containing quotes" do
86
74
  testing_expression "[\"']"
@@ -190,58 +178,5 @@ module CharacterClassSpec
190
178
  parse("0").should be_nil
191
179
  end
192
180
  end
193
-
194
- describe "a character class" do
195
- testing_expression "[A-Z]"
196
- it "actively generates a node for the character because it is the primary node" do
197
- result = parse('A')
198
- result.should be_a(Treetop::Runtime::SyntaxNode)
199
- result.elements.should be_nil
200
- end
201
- end
202
-
203
- describe "a character class mixed with other expressions" do
204
- testing_expression '[A-Z] "a"'
205
- it "lazily instantiates a node for the character" do
206
- result = parse('Aa')
207
- result.instance_variable_get("@elements").size.should == 1
208
- result.elements.size.should == 2
209
- end
210
- end
211
-
212
- describe "a character class with a node class declaration mixed with other expressions" do
213
- testing_expression '([A-Z] <CharacterClassSpec::Foo>) "a"'
214
- it "actively generates a node for the character because it has a node class declared" do
215
- result = parse('Aa')
216
- result.instance_variable_get("@elements").size.should == 2
217
- result.elements.size.should == 2
218
- end
219
- end
220
-
221
- describe "a character class with a node module declaration mixed with other expressions" do
222
- testing_expression '([A-Z] <CharacterClassSpec::ModFoo>) "a"'
223
- it "actively generates a node for the character because it has a node module declared" do
224
- result = parse('Aa')
225
- result.instance_variable_get("@elements").size.should == 2
226
- result.elements.size.should == 2
227
- end
228
- end
229
-
230
- describe "a character class with an inline block mixed with other expressions" do
231
- testing_expression '([A-Z] { def a_method; end }) "a"'
232
- it "actively generates a node for the character because it has an inline block" do
233
- result = parse('Aa')
234
- result.instance_variable_get("@elements").size.should == 2
235
- result.elements.size.should == 2
236
- end
237
- end
238
-
239
- describe "a character class with a label mixed with other expressions" do
240
- testing_expression 'upper:([A-Z]) "b"'
241
- it "returns the correct element for the labeled expression" do
242
- result = parse('Ab')
243
- result.upper.text_value.should == "A"
244
- end
245
- end
246
181
 
247
182
  end
@@ -50,19 +50,4 @@ module SyntaxNodeSpec
50
50
  end
51
51
  end
52
52
  end
53
-
54
- describe "A new nonterminal syntax node with all children lazily instantiated" do
55
- attr_reader :node
56
-
57
- before do
58
- @input = 'test input'
59
- @node = Runtime::SyntaxNode.new('input', 0...3, [true, true, true])
60
- end
61
-
62
- it "should lazily instantiate its child nodes" do
63
- node.elements.size.should == 3
64
- node.elements.first.interval.should == (0...1)
65
- node.elements.first.parent.should == @node
66
- end
67
- end
68
53
  end
@@ -7,7 +7,7 @@ $gemspec = Gem::Specification.new do |s|
7
7
  s.homepage = "http://functionalform.blogspot.com"
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.summary = "A Ruby-based text parsing and interpretation DSL"
10
- s.files = ["README", "Rakefile", "{test,lib,bin,doc,examples}/**/*"].map{|p| Dir[p]}.flatten
10
+ s.files = ["LICENSE", "README", "Rakefile", "{test,lib,bin,doc,examples}/**/*"].map{|p| Dir[p]}.flatten
11
11
  s.bindir = "bin"
12
12
  s.executables = ["tt"]
13
13
  s.require_path = "lib"
@@ -0,0 +1,7 @@
1
+ .parens {
2
+ border: 2px solid black;
3
+ margin: 1px 3px 16 3;
4
+ width: 36;
5
+ padding: 2px 36px;
6
+ }
7
+ .more-parens { padding: 8 4 4 4px; }
data/spec/engine_spec.rb CHANGED
@@ -54,6 +54,10 @@ describe Less::Engine do
54
54
  lessify(:scope).should == css(:scope)
55
55
  end
56
56
 
57
+ it "should parse parens" do
58
+ lessify(:parens).should == css(:parens)
59
+ end
60
+
57
61
  it "should parse strings" do
58
62
  lessify(:strings).should == css(:strings)
59
63
  end
@@ -36,4 +36,4 @@
36
36
  color: 2 * #111; // #222222
37
37
  border-color: #333333 / 3 + #111; // #222222
38
38
  }
39
- }
39
+ }
@@ -0,0 +1,15 @@
1
+ .parens {
2
+ @var: 1px;
3
+ border: (@var * 2) solid black;
4
+ margin: (@var * 1) (@var + 2) (4 * 4) 3;
5
+ width: (6 * 6);
6
+ padding: 2px (6px * 6px);
7
+ }
8
+
9
+ .more-parens {
10
+ @var: (2 * 2);
11
+ padding: (2 * @var) 4 4 (@var * 1px);
12
+ //width: (@var * @var) * 6;
13
+ //margin: (6 * 6)px;
14
+ //height: (7 * 7) + (8 * 8);
15
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudhead-less
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.13
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - cloudhead
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-20 00:00:00 -07:00
12
+ date: 2009-07-23 00:00:00 -07:00
13
13
  default_executable: lessc
14
14
  dependencies: []
15
15
 
@@ -147,6 +147,7 @@ files:
147
147
  - spec/css/mixins-args.css
148
148
  - spec/css/mixins.css
149
149
  - spec/css/operations.css
150
+ - spec/css/parens.css
150
151
  - spec/css/rulesets.css
151
152
  - spec/css/scope.css
152
153
  - spec/css/selectors.css
@@ -173,6 +174,7 @@ files:
173
174
  - spec/less/mixins-args.less
174
175
  - spec/less/mixins.less
175
176
  - spec/less/operations.less
177
+ - spec/less/parens.less
176
178
  - spec/less/rulesets.less
177
179
  - spec/less/scope.less
178
180
  - spec/less/selectors.less