@@ -15,44 +15,41 @@ class CSS < Scanner
15
15
16
16
module RE # :nodoc:
17
17
Hex = /[0-9a-fA-F]/
18
- Unicode = /\\ #{ Hex } {1,6}(?:\r \n |\s )?/ # differs from standard because it allows uppercase hex too
19
- Escape = /#{ Unicode } |\\ [^\r \n \f 0-9a-fA-F]/
20
- NMChar = /[-_a-zA-Z0-9]|#{ Escape } /
21
- NMStart = /[_a-zA-Z]|#{ Escape } /
22
- NL = /\r \n |\r |\n |\f /
23
- String1 = /"(?:[^\n \r \f \\ "]|\\ #{ NL } |#{ Escape } )*"?/ # TODO: buggy regexp
24
- String2 = /'(?:[^\n \r \f \\ ']|\\ #{ NL } |#{ Escape } )*'?/ # TODO: buggy regexp
18
+ Unicode = /\\ #{ Hex } {1,6}\b / # differs from standard because it allows uppercase hex too
19
+ Escape = /#{ Unicode } |\\ [^\n 0-9a-fA-F]/
20
+ NMChar = /[-_a-zA-Z0-9]/
21
+ NMStart = /[_a-zA-Z]/
22
+ String1 = /"(?:[^\n \\ "]+|\\ \n |#{ Escape } )*"?/ # TODO: buggy regexp
23
+ String2 = /'(?:[^\n \\ ']+|\\ \n |#{ Escape } )*'?/ # TODO: buggy regexp
25
24
String = /#{ String1 } |#{ String2 } /
26
25
27
26
HexColor = /#(?:#{ Hex } {6}|#{ Hex } {3})/
28
- Color = /#{ HexColor } /
29
27
30
- Num = /-?(?:[0-9]+| [0-9]* \. [0-9]+)/
28
+ Num = /-?(?:[0-9]* \. [0-9]+| [0-9]+)/
31
29
Name = /#{ NMChar } +/
32
30
Ident = /-?#{ NMStart } #{ NMChar } */
33
31
AtKeyword = /@#{ Ident } /
34
32
Percentage = /#{ Num } %/
35
33
36
34
reldimensions = %w[ em ex px ]
37
35
absdimensions = %w[ in cm mm pt pc ]
38
- Unit = Regexp . union ( *( reldimensions + absdimensions + %w[ s ] ) )
36
+ Unit = Regexp . union ( *( reldimensions + absdimensions + %w[ s dpi dppx deg ] ) )
39
37
40
38
Dimension = /#{ Num } #{ Unit } /
41
39
42
- Comment = %r! /\* (?: .*? \* / | .* ) !mx
43
- Function = /(?:url|alpha|attr|counters?)\( (?:[^)\n \r \f ]|\\ \) )*\) ?/
40
+ Function = /(?:url|alpha|attr|counters?)\( (?:[^)\n ]|\\ \) )*\) ?/
44
41
45
- Id = /##{ Name } /
42
+ Id = /(?! #{ HexColor } \b (?!-)) ##{ Name } /
46
43
Class = /\. #{ Name } /
47
- PseudoClass = /:#{ Name } /
44
+ PseudoClass = /::? #{ Ident } /
48
45
AttributeSelector = /\[ [^\] ]*\] ?/
49
46
end
50
47
51
48
protected
52
49
53
50
def setup
54
51
@state = :initial
55
- @value_expected = nil
52
+ @value_expected = false
56
53
end
57
54
58
55
def scan_tokens encoder , options
@@ -158,7 +155,7 @@ def scan_tokens encoder, options
158
155
elsif match = scan ( /(?: #{ RE ::Dimension } | #{ RE ::Percentage } | #{ RE ::Num } )/ox )
159
156
encoder . text_token match , :float
160
157
161
- elsif match = scan ( /#{ RE ::Color } /o )
158
+ elsif match = scan ( /#{ RE ::HexColor } /o )
162
159
encoder . text_token match , :color
163
160
164
161
elsif match = scan ( /! *important/ )
@@ -170,7 +167,7 @@ def scan_tokens encoder, options
170
167
elsif match = scan ( RE ::AtKeyword )
171
168
encoder . text_token match , :directive
172
169
173
- elsif match = scan ( / [+>:;,.=()\/ ] /x )
170
+ elsif match = scan ( / [+>~ :;,.=()\/ ] /x )
174
171
if match == ':'
175
172
value_expected = true
176
173
elsif match == ';'
0 commit comments