diff options
author | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-08-14 17:08:54 -0700 |
---|---|---|
committer | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-08-23 15:54:31 -0700 |
commit | 9718d899f5284d726343f1b97f944f04a34f4d49 (patch) | |
tree | 9b77fe1f246450dd5c6bc048d5f48f4a402fdce1 | |
parent | 650fe58375f01bc960038a65ac1d33f39a0d9242 (diff) | |
download | pyscss-9718d899f5284d726343f1b97f944f04a34f4d49.tar.gz |
Avoid reparsing color literals.
-rw-r--r-- | scss/expression.parsley | 25 | ||||
-rw-r--r-- | scss/types.py | 3 |
2 files changed, 20 insertions, 8 deletions
diff --git a/scss/expression.parsley b/scss/expression.parsley index aad3878..e839ac0 100644 --- a/scss/expression.parsley +++ b/scss/expression.parsley @@ -95,19 +95,30 @@ atom = ( | < '!'? identifier >:word -> Literal(parse_bareword(word)) # Number - | number:number < '%' | letter+ >?:unit -> Literal(NumberValue(float(number), unit=unit)) + | number:number < '%' | letter+ >?:unit -> Literal(Number(float(number), unit=unit)) # String | string # Color literal - # TODO: stop making ColorValue finish this parsing - | < '#' ( + # DEVIATION: Sass doesn't support alpha in hex literals + | '#' ( <hex{2}>:red <hex{2}>:green <hex{2}>:blue - #-> Literal(ColorValue.from_rgb(int(red, 16) / 255., int(green, 16) / 255., int(blue, 16) / 255.)) - | hex:red hex:green hex:blue - #-> Literal(ColorValue.from_rgb(int(red, 16) / 15., int(green, 16) / 15., int(blue, 16) / 15.)) - ) >:color -> Literal(ColorValue(ParserValue(color))) + <hex{2}>?:alpha + -> Literal(Color.from_rgb( + int(red, 16) / 255., + int(green, 16) / 255., + int(blue, 16) / 255., + int(alpha or "ff", 16) / 255., + original_literal="#" + red + green + blue + (alpha or ''))) + | hex:red hex:green hex:blue hex?:alpha + -> Literal(Color.from_rgb( + int(red, 16) / 15., + int(green, 16) / 15., + int(blue, 16) / 15., + int(alpha or "f", 16) / 15., + original_literal="#" + red + green + blue + (alpha or ''))) + ) # Variable | variable:name -> Variable(name) diff --git a/scss/types.py b/scss/types.py index 1a8c654..32f0cce 100644 --- a/scss/types.py +++ b/scss/types.py @@ -657,9 +657,10 @@ class Color(Value): ### Alternate constructors @classmethod - def from_rgb(cls, red, green, blue, alpha=1.0): + def from_rgb(cls, red, green, blue, alpha=1.0, original_literal=None): self = cls.__new__(cls) # TODO self.tokens = None + self.original_literal = original_literal # TODO really should store these things internally as 0-1, but can't # until stuff stops examining .value directly self.value = (red * 255.0, green * 255.0, blue * 255.0, alpha) |