public
Description: HTML Abstraction Markup Language - A Markup Haiku
Homepage: http://haml.hamptoncatlin.com
Clone URL: git://github.com/nex3/haml.git
Sass has a unary minus! Yay!


git-svn-id: svn://hamptoncatlin.com/haml/trunk@538 
7063305b-7217-0410-af8c-cdc13e5119b9
nex3 (author)
Mon Jun 25 01:00:21 -0700 2007
commit  af8ca8d0af0ea6e7bbff97e44f321b3de83dc95d
tree    305749c60b1aece9d9ade6914ac198942a59d101
parent  73cb2a4ba2225fb59b6cceb60145a1b8a2a51b56
...
105
106
107
 
 
 
 
 
 
 
108
109
110
 
111
112
113
...
137
138
139
140
 
141
142
143
144
145
 
 
 
 
 
 
 
 
 
 
 
 
 
146
147
148
...
159
160
161
162
163
 
164
165
 
 
 
166
167
168
169
170
171
172
 
 
 
 
 
 
 
173
174
175
...
105
106
107
108
109
110
111
112
113
114
115
 
 
116
117
118
119
...
143
144
145
 
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
...
178
179
180
 
 
181
182
 
183
184
185
186
187
188
189
 
 
 
190
191
192
193
194
195
196
197
198
199
0
@@ -105,9 +105,15 @@ module Sass
0
                 to_return << :concat
0
               end
0
 
0
+ # Time for a unary minus!
0
+ if negative_okay && symbol == :minus
0
+ negative_okay = true
0
+ to_return << :neg
0
+ next
0
+ end
0
+
0
               # Are we looking at an operator?
0
- if symbol && !(negative_okay && symbol == :minus) &&
0
- (str.empty? || symbol != :mod)
0
+ if symbol && (str.empty? || symbol != :mod)
0
                 str = reset_str.call
0
                 negative_okay = true
0
                 to_return << symbol
0
@@ -137,12 +143,25 @@ module Sass
0
         beginning = i
0
         token = value[i]
0
         
0
- while i < value_len && token != :close
0
+ while i < value_len && token != :close
0
           if token == :open
0
             to_return.push(*value[beginning...i])
0
             sub, i = parenthesize_helper(i + 1, value, value_len)
0
             beginning = i
0
             to_return << sub
0
+ elsif token == :neg
0
+ if value[i + 1].nil?
0
+ raise Sass::SyntaxError("Unterminated unary minus.")
0
+ elsif value[i + 1] == :open
0
+ to_return.push(*value[beginning...i])
0
+ sub, i = parenthesize_helper(i + 2, value, value_len)
0
+ beginning = i
0
+ to_return << [:neg, sub]
0
+ else
0
+ to_return.push(*value[beginning...i])
0
+ to_return << [:neg, value[i + 1]]
0
+ beginning = i = i + 2
0
+ end
0
           else
0
             i += 1
0
           end
0
@@ -159,17 +178,22 @@ module Sass
0
       #++
0
       def operationalize(value, constants)
0
         value = [value] unless value.is_a?(Array)
0
- length = value.length
0
- if length == 1
0
+ if value.length == 1
0
           value = value[0]
0
- if value.is_a? Operation
0
+ if value.is_a? Array
0
+ operationalize(value, constants)
0
+ elsif value.is_a? Operation
0
             value
0
           else
0
             Literal.parse(insert_constant(value, constants))
0
           end
0
- elsif length == 2
0
- raise SyntaxError.new("Constant arithmetic error")
0
- elsif length == 3
0
+ elsif value.length == 2
0
+ if value[0] == :neg
0
+ Operation.new(Sass::Constant::Number.new('0'), operationalize(value[1], constants), :minus)
0
+ else
0
+ raise SyntaxError.new("Constant arithmetic error")
0
+ end
0
+ elsif value.length == 3
0
           Operation.new(operationalize(value[0], constants), operationalize(value[2], constants), value[1])
0
         else
0
           if SECOND_ORDER.include?(value[1]) && FIRST_ORDER.include?(value[3])
...
16
17
18
19
20
21
22
23
24
 
 
 
 
 
 
25
26
27
...
16
17
18
 
 
 
 
 
 
19
20
21
22
23
24
25
26
27
0
@@ -16,12 +16,12 @@ class Sass::Constant::Literal # :nodoc:
0
   
0
   def self.parse(value)
0
     case value
0
- when NUMBER
0
- Sass::Constant::Number.new(value)
0
- when COLOR
0
- Sass::Constant::Color.new(value)
0
- else
0
- Sass::Constant::String.new(value)
0
+ when NUMBER
0
+ Sass::Constant::Number.new(value)
0
+ when COLOR
0
+ Sass::Constant::Color.new(value)
0
+ else
0
+ Sass::Constant::String.new(value)
0
     end
0
   end
0
   
...
3
4
5
6
 
7
8
9
...
3
4
5
 
6
7
8
9
0
@@ -3,7 +3,7 @@
0
 
0
 #plus { num-num: 7; num-num-un: 25em; num-num-un2: 23em; num-num-neg: 9.87; num-str: 100px; num-col: #b7b7b7; num-perc: 31%; str-str: hi there; str-str2: hi there; str-col: 14em solid #112233; str-num: times: 13; col-num: #ff7b9d; col-col: #5173ff; }
0
 
0
-#minus { num-num: 900; col-num: #f9f9f4; col-col: #000035; }
0
+#minus { num-num: 900; col-num: #f9f9f4; col-col: #000035; unary-num: -1; unary-const: 10; unary-paren: -11; }
0
 
0
 #times { num-num: 7; num-col: #7496b8; col-num: #092345; col-col: #243648; }
0
 
...
59
60
61
 
 
 
 
62
63
64
...
59
60
61
62
63
64
65
66
67
68
0
@@ -59,6 +59,10 @@
0
   :col
0
     :num= #fffffa - 5.2
0
     :col= #abcdef - #fedcba
0
+ :unary
0
+ :num= -1
0
+ :const= -!neg
0
+ :paren= -(5 + 6)
0
 
0
 #times
0
   :num

Comments

    No one has commented yet.