@@ -7,8 +7,6 @@ class Sass < CSS
7
7
register_for :sass
8
8
file_extension 'sass'
9
9
10
- SASS_FUNCTION = /(?:inline-image|linear-gradient|color-stops|mix|lighten|darken|rotate|image-url|image-width|image-height|sprite-url|sprite-path|sprite-file|sprite-map|sprite-position|sprite|unquote|join|round|ceil|floor|nth)/
11
-
12
10
STRING_CONTENT_PATTERN = {
13
11
"'" => /(?:[^\n \' \# ]+|\\ \n |#{ RE ::Escape } |#(?!\{ ))+/ ,
14
12
'"' => /(?:[^\n \" \# ]+|\\ \n |#{ RE ::Escape } |#(?!\{ ))+/ ,
@@ -26,10 +24,22 @@ def scan_tokens encoder, options
26
24
27
25
until eos?
28
26
29
- if match = scan ( /\s +/ )
27
+ if bol? && ( match = scan ( /(?>( +)?(\/ [\* \/ ])(.+)?)(?=\n )/ ) )
28
+ encoder . text_token self [ 1 ] , :space if self [ 1 ]
29
+ encoder . begin_group :comment
30
+ encoder . text_token self [ 2 ] , :delimiter
31
+ encoder . text_token self [ 3 ] , :content if self [ 3 ]
32
+ if match = scan ( /(?:\n +#{ self [ 1 ] } .*)+/ )
33
+ encoder . text_token match , :content
34
+ end
35
+ encoder . end_group :comment
36
+ elsif match = scan ( /\n |[^\n \S ]+\n ?/ )
30
37
encoder . text_token match , :space
31
- value_expected = false if match . index ( /\n / )
32
-
38
+ if match . index ( /\n / )
39
+ value_expected = false
40
+ states . pop if states . last == :include
41
+ end
42
+
33
43
elsif states . last == :sass_inline && ( match = scan ( /\} / ) )
34
44
encoder . text_token match , :inline_delimiter
35
45
encoder . end_group :inline
@@ -61,7 +71,11 @@ def scan_tokens encoder, options
61
71
elsif match = scan ( /(\= |@mixin +)#{ RE ::Ident } /o )
62
72
encoder . text_token match , :function
63
73
next
64
- elsif match = scan ( /@media/ )
74
+ elsif match = scan ( /@import\b / )
75
+ encoder . text_token match , :directive
76
+ states << :include
77
+ next
78
+ elsif match = scan ( /@media\b / )
65
79
encoder . text_token match , :directive
66
80
# states.push :media_before_name
67
81
next
@@ -90,13 +104,19 @@ def scan_tokens encoder, options
90
104
encoder . text_token match , :inline_delimiter
91
105
states . push :sass_inline
92
106
elsif match = scan ( / \\ | $ /x )
93
- encoder . end_group state
107
+ encoder . end_group :string
94
108
encoder . text_token match , :error unless match . empty?
95
109
states . pop
96
110
else
97
111
raise_inspect "else case #{ string_delimiter } reached; %p not handled." % peek ( 1 ) , encoder
98
112
end
99
113
114
+ when :include
115
+ if match = scan ( /[^\s '",]+/ )
116
+ encoder . text_token match , :include
117
+ next
118
+ end
119
+
100
120
else
101
121
#:nocov:
102
122
raise_inspect 'Unknown state' , encoder
@@ -148,9 +168,6 @@ def scan_tokens encoder, options
148
168
states . push :string
149
169
end
150
170
151
- elsif match = scan ( /#{ SASS_FUNCTION } /o )
152
- encoder . text_token match , :predefined
153
-
154
171
elsif match = scan ( /#{ RE ::Function } /o )
155
172
encoder . begin_group :function
156
173
start = match [ /^[-\w ]+\( / ]
@@ -163,6 +180,9 @@ def scan_tokens encoder, options
163
180
end
164
181
encoder . end_group :function
165
182
183
+ elsif match = scan ( /[a-z][-a-z_]*(?=\( )/o )
184
+ encoder . text_token match , :predefined
185
+
166
186
elsif match = scan ( /(?: #{ RE ::Dimension } | #{ RE ::Percentage } | #{ RE ::Num } )/ox )
167
187
encoder . text_token match , :float
168
188
0 commit comments