Permalink
Browse files

Allow functions named `true`, `false`, and `null`.

Closes #1090
  • Loading branch information...
nex3 committed Jan 24, 2014
1 parent b1c6225 commit 439db9283df51e5fbeb6f78a094d816551ef29e7
Showing with 23 additions and 20 deletions.
  1. +2 −0 doc-src/SASS_CHANGELOG.md
  2. +4 −17 lib/sass/script/lexer.rb
  3. +10 −3 lib/sass/script/parser.rb
  4. +7 −0 test/sass/script_test.rb
@@ -10,6 +10,8 @@
* Clean up file paths when importing to avoid errors for overlong path
names.
+* Parse calls to functions named `true`, `false`, and `null` as function calls.
+
## 3.2.13
* Numbers returned by user-defined functions now trigger division, just like
View
@@ -69,8 +69,7 @@ class Lexer
TOKEN_NAMES = Sass::Util.map_hash(OPERATORS_REVERSE) {|k, v| [k, v.inspect]}.merge({
:const => "variable (e.g. $foo)",
- :ident => "identifier (e.g. middle)",
- :bool => "boolean (e.g. true, false)",
+ :ident => "identifier (e.g. middle)"
})
# A list of operator strings ordered with longer names first
@@ -90,8 +89,6 @@ class Lexer
:ident => /(#{IDENT})(\()?/,
:number => /(-)?(?:(\d*\.\d+)|(\d+))([a-zA-Z%]+)?/,
:color => HEXCOLOR,
- :bool => /(true|false)\b/,
- :null => /null\b/,
:ident_op => %r{(#{Regexp.union(*IDENT_OP_NAMES.map{|s| Regexp.new(Regexp.escape(s) + "(?!#{NMCHAR}|\Z)")})})},
:op => %r{(#{Regexp.union(*OP_NAMES)})},
}
@@ -235,9 +232,9 @@ def token
return string(interp_type, true)
end
- variable || string(:double, false) || string(:single, false) || number ||
- color || bool || null || string(:uri, false) || raw(UNICODERANGE) ||
- special_fun || special_val || ident_op || ident || op
+ variable || string(:double, false) || string(:single, false) || number || color ||
+ string(:uri, false) || raw(UNICODERANGE) || special_fun || special_val || ident_op ||
+ ident || op
end
def variable
@@ -287,16 +284,6 @@ def color
[:color, Script::Color.new(value)]
end
- def bool
- return unless s = scan(REGULAR_EXPRESSIONS[:bool])
- [:bool, Script::Bool.new(s == 'true')]
- end
-
- def null
- return unless scan(REGULAR_EXPRESSIONS[:null])
- [:null, Script::Null.new]
- end
-
def special_fun
return unless str1 = scan(/((-[\w-]+-)?(calc|element)|expression|progid:[a-z\.]*)\(/i)
str2, _ = Sass::Shared.balance(@scanner, ?(, ?), 1)
View
@@ -321,9 +321,16 @@ def ident
name = @lexer.next
if color = Color::COLOR_NAMES[name.value.downcase]
- return node(Color.new(color))
+ node(Color.new(color))
+ elsif name.value == "true"
+ node(Script::Bool.new(true))
+ elsif name.value == "false"
+ node(Script::Bool.new(false))
+ elsif name.value == "null"
+ node(Script::Null.new)
+ else
+ node(Script::String.new(name.value, :identifier))
end
- node(Script::String.new(name.value, :identifier))
end
def funcall
@@ -453,7 +460,7 @@ def number
end
def literal
- (t = try_tok(:color, :bool, :null)) && (return t.value)
+ (t = try_tok(:color)) && (return t.value)
end
# It would be possible to have unified #assert and #try methods,
View
@@ -541,6 +541,13 @@ def test_funcall_has_higher_precedence_than_color_name
assert_equal "teal\\+bang(12)", resolve("teal\\+bang(12)")
end
+ def test_funcall_has_higher_precedence_than_true_false_null
+ assert_equal "teal(12)", resolve("teal(12)")
+ assert_equal "tealbang(12)", resolve("tealbang(12)")
+ assert_equal "teal-bang(12)", resolve("teal-bang(12)")
+ assert_equal "teal\\+bang(12)", resolve("teal\\+bang(12)")
+ end
+
def test_interpolation_after_hash
assert_equal "#2", resolve('"##{1 + 1}"')
end

0 comments on commit 439db92

Please sign in to comment.