From 12255afcd001649e8faddbe96d8d94646a7c18a9 Mon Sep 17 00:00:00 2001 From: nex3 Date: Sun, 24 Dec 2006 22:31:49 +0000 Subject: [PATCH] Smoothing out a few more constant parsing bugs. git-svn-id: svn://hamptoncatlin.com/haml/trunk@260 7063305b-7217-0410-af8c-cdc13e5119b9 --- lib/sass/constant.rb | 29 +++++++++++++++++++---------- test/sass/results/constants.css | 2 +- test/sass/templates/constants.sass | 2 ++ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/sass/constant.rb b/lib/sass/constant.rb index 16823c87..80c10a64 100644 --- a/lib/sass/constant.rb +++ b/lib/sass/constant.rb @@ -84,37 +84,46 @@ module Sass beginning = i token = value[i] - while i < value_len && token != :close - i += 1 - token = value[i] - + while i < value_len && token != :close if token == :open to_return.push(*value[beginning...i]) sub, i = parenthesize_helper(i + 1, value, value_len) beginning = i - token = value[i] to_return << sub + else + i += 1 end + + token = value[i] end to_return.push(*value[beginning...i]) return to_return, i + 1 end + #-- + # TODO: Don't pass around original value; + # have Constant.parse automatically add it to exception. + #++ def operationalize(value, original, constants) value = [value] unless value.is_a?(Array) length = value.length if length == 1 - Literal.parse(insert_constant(value[0], constants)) + value = value[0] + if value.is_a? Operation + value + else + Literal.parse(insert_constant(value, constants)) + end elsif length == 2 - raise "Improperly formatted script:\n#{original}" + raise "Syntax error:\n#{original}" elsif length == 3 Operation.new(operationalize(value[0], original, constants), operationalize(value[2], original, constants), value[1]) else - raise "Improperly formatted script:\n#{original}" unless length >= 5 && length % 2 == 1 + raise "Syntax error:\n#{original}" unless length >= 5 && length % 2 == 1 if SECOND_ORDER.include?(value[1]) && FIRST_ORDER.include?(value[3]) - operationalize([value[1], value[2], operationalize(value[3..5]), *value[6..-1]], original, constants) + operationalize([value[1], value[2], operationalize(value[3..5], original, constants), *value[6..-1]], original, constants) else - operationalize([operationalize(value[0..2]), *value[4..-1]], original, constants) + operationalize([operationalize(value[0..2], original, constants), *value[3..-1]], original, constants) end end end diff --git a/test/sass/results/constants.css b/test/sass/results/constants.css index 0f94feb1..b535a664 100644 --- a/test/sass/results/constants.css +++ b/test/sass/results/constants.css @@ -1,4 +1,4 @@ #main { width: 30; background-color: #000; color: #ffffaf; } -#main #sidebar { background-color: #00ff98; num-normal: 10; num-dec: 10.2; num-dec0: 99; num-neg: -10; esc: 10+12; } +#main #sidebar { background-color: #00ff98; num-normal: 10; num-dec: 10.2; num-dec0: 99; num-neg: -10; esc: 10+12; many: 6; complex: 18#3a8b9fhi4; } #plus { num-num: 7; num-str: 100px; num-col: 13#ffffff; str-str: hi there; str-num: times: 13; col-num: #ff8aaa; col-col: #5f80ff; } diff --git a/test/sass/templates/constants.sass b/test/sass/templates/constants.sass index baa411b3..47b6ec3d 100644 --- a/test/sass/templates/constants.sass +++ b/test/sass/templates/constants.sass @@ -19,6 +19,8 @@ :dec0= !dec_0 :neg= !neg :esc= !esc + :many= 1 + 2 + 3 + :complex= ((1 + 2) + 15)+#3a8b9f + (hi+(1 +1+ 2)) #plus :num