@@ -29,7 +29,6 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
29
29
]
30
30
31
31
SCANNER = /
32
- (?<space>\s *) # eat leading whitespace, just to make iteration of fluff easier
33
32
(?<fluff>(?m).*?) # eat content up until something we want
34
33
(?:
35
34
(?<funcname>
@@ -147,17 +146,19 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
147
146
148
147
def scan_tokens ( tokens , options )
149
148
# We use the block form of gsub instead of the StringScanner capabilities because StringScanner does not support named captures in 1.9
150
- match = nil
149
+ remainder_index = 0
150
+
151
+ boring_kinds = [ :space , :content ]
152
+ add_boring = -> ( fluff ) do
153
+ fluff . split ( /(\S +)/ ) . each . with_index do |text , i |
154
+ tokens . text_token ( text , boring_kinds [ i %2 ] ) unless text . empty?
155
+ end
156
+ end
157
+
151
158
string . gsub ( SCANNER ) do
152
159
match = $~
153
- tokens . text_token ( match [ :space ] , :space ) unless match [ :space ] . empty?
154
- unless match [ :fluff ] . empty?
155
- space = false
156
- match [ :fluff ] . split ( /(\s +)/ ) . each do |piece |
157
- tokens . text_token ( piece , space ? :space : :content )
158
- space = !space
159
- end
160
- end
160
+ remainder_index = match . offset ( 0 ) . last
161
+ add_boring [ match [ :fluff ] ]
161
162
if match [ :funcname ] && !match [ :funcname ] . empty?
162
163
f , s , n = match [ :funcname ] . split ( /(\s +)/ )
163
164
tokens . text_token ( f , :keyword )
@@ -177,7 +178,9 @@ def scan_tokens(tokens, options)
177
178
end
178
179
end
179
180
end
180
- tokens . text_token ( match . post_match , :content ) unless match . post_match . empty?
181
+ unless remainder_index >= string . length
182
+ add_boring [ string [ remainder_index ..-1 ] ]
183
+ end
181
184
tokens
182
185
end
183
186
0 commit comments