Skip to content

Commit 8b41364

Browse files
committed
Don't treat whitespace as content; numbers in variable names are not considered numbers
1 parent a92f44c commit 8b41364

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

lib/coderay/scanners/lua.rb

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
2828
]
2929

3030
SCANNER = /
31+
(?<space>\s*) # eat leading whitespace, just to make iteration of fluff easier
3132
(?<fluff>[\d\D]*?) # eat content up until something we want
3233
(?:
3334
\b(?<keyword>#{KEYWORDS.join('|')})\b
@@ -48,19 +49,25 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
4849
--(?!\[).+
4950
)
5051
|
51-
(?<number>
52+
\b(?<number>
5253
-? # Allows -2 to be properly highlighted, but makes 10-5 show -5 as a single number
5354
(?:
54-
0[xX][\da-fA-F]+
55+
0[xX]
56+
(?:
57+
[\da-fA-F]+\.?[\da-fA-F]*
58+
|
59+
[\da-fA-F]*\.[\da-fA-F]+
60+
)
61+
(?:[pP][-+]?\d+)?
5562
|
5663
(?:
5764
\d+\.?\d*
5865
|
59-
\d*\.?\d+
66+
\d*\.\d+
6067
)
6168
(?:[eE][-+]?\d+)?
6269
)
63-
)
70+
)\b
6471
|
6572
\b(?<constant>#{PREDEFINED_CONSTANTS.join('|')})\b
6673
|
@@ -77,7 +84,6 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
7784
/x
7885

7986
CAPTURE_KINDS = {
80-
fluff: :content,
8187
reserved: :reserved,
8288
comment: :comment,
8389
blockcomment: :comment,
@@ -101,8 +107,17 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
101107

102108
def scan_tokens(tokens, options)
103109
string.gsub(SCANNER) do
110+
match = $~
111+
tokens.text_token( match[:space], :space ) unless match[:space].empty?
112+
unless match[:fluff].empty?
113+
space = false
114+
match[:fluff].split(/(\s+)/).each do |piece|
115+
tokens.text_token(piece, space ? :space : :content)
116+
space = !space
117+
end
118+
end
104119
CAPTURE_KINDS.each do |capture,kind|
105-
tokens.text_token( $~[capture], kind ) if $~[capture] && !$~[capture].empty?
120+
tokens.text_token( match[capture], kind ) if match[capture] && !match[capture].empty?
106121
end
107122
end
108123
tokens

0 commit comments

Comments
 (0)