@@ -7,11 +7,6 @@ class Sass < CSS
7
7
register_for :sass
8
8
file_extension 'sass'
9
9
10
- STRING_CONTENT_PATTERN = {
11
- "'" => /(?:[^\n \' \# ]+|\\ \n |#{ RE ::Escape } |#(?!\{ ))+/ ,
12
- '"' => /(?:[^\n \" \# ]+|\\ \n |#{ RE ::Escape } |#(?!\{ ))+/ ,
13
- }
14
-
15
10
protected
16
11
17
12
def setup
@@ -20,7 +15,8 @@ def setup
20
15
21
16
def scan_tokens encoder , options
22
17
states = Array ( options [ :state ] || @state ) . dup
23
- string_delimiter = nil
18
+
19
+ encoder . begin_group :string if states . last == :sqstring || states . last == :dqstring
24
20
25
21
until eos?
26
22
@@ -91,24 +87,23 @@ def scan_tokens encoder, options
91
87
next
92
88
end
93
89
94
- when :string
95
- if match = scan ( STRING_CONTENT_PATTERN [ string_delimiter ] )
90
+ when :sqstring , :dqstring
91
+ if match = scan ( states . last == :sqstring ? /(?:[^ \n \' \# ]+| \\ \n | #{ RE :: Escape } |#(?! \{ ))+/o : /(?:[^ \n \" \# ]+| \\ \n | #{ RE :: Escape } |#(?! \{ ))+/o )
96
92
encoder . text_token match , :content
97
93
elsif match = scan ( /['"]/ )
98
94
encoder . text_token match , :delimiter
99
95
encoder . end_group :string
100
- string_delimiter = nil
101
96
states . pop
102
97
elsif match = scan ( /#\{ / )
103
98
encoder . begin_group :inline
104
99
encoder . text_token match , :inline_delimiter
105
100
states . push :sass_inline
106
101
elsif match = scan ( / \\ | $ /x )
107
- encoder . end_group :string
102
+ encoder . end_group states . last
108
103
encoder . text_token match , :error unless match . empty?
109
104
states . pop
110
105
else
111
- raise_inspect "else case #{ string_delimiter } reached; %p not handled." % peek ( 1 ) , encoder
106
+ raise_inspect "else case #{ states . last } reached; %p not handled." % peek ( 1 ) , encoder
112
107
end
113
108
114
109
when :include
@@ -157,15 +152,15 @@ def scan_tokens encoder, options
157
152
158
153
elsif match = scan ( /['"]/ )
159
154
encoder . begin_group :string
160
- string_delimiter = match
161
155
encoder . text_token match , :delimiter
162
156
if states . include? :sass_inline
163
- content = scan_until ( /(?=#{ string_delimiter } |\} |\z )/ )
157
+ # no nesting, just scan the string until delimiter
158
+ content = scan_until ( /(?=#{ match } |\} |\z )/ )
164
159
encoder . text_token content , :content unless content . empty?
165
- encoder . text_token string_delimiter , :delimiter if scan ( /#{ string_delimiter } / )
160
+ encoder . text_token match , :delimiter if scan ( /#{ match } / )
166
161
encoder . end_group :string
167
162
else
168
- states . push :string
163
+ states . push match == "'" ? :sqstring : :dqstring
169
164
end
170
165
171
166
elsif match = scan ( /#{ RE ::Function } /o )
@@ -221,7 +216,7 @@ def scan_tokens encoder, options
221
216
while state = states . pop
222
217
if state == :sass_inline
223
218
encoder . end_group :inline
224
- elsif state == :string
219
+ elsif state == :sqstring || state == :dqstring
225
220
encoder . end_group :string
226
221
end
227
222
end
0 commit comments