Skip to content

Commit 7b862c5

Browse files
committed
Simplify option switching; add function name matching
1 parent 4a9f1fe commit 7b862c5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/coderay/scanners/lua.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
3030

3131
SCANNER = /
3232
(?<space>\s*) # eat leading whitespace, just to make iteration of fluff easier
33-
(?<fluff>(?m:.*?)) # eat content up until something we want
33+
(?<fluff>(?m).*?) # eat content up until something we want
3434
(?:
35+
(?<funcname>
36+
\bfunction\s+[^\(]+
37+
)
38+
|
3539
\b(?<keyword>#{KEYWORDS.join('|')})\b
3640
|
3741
(?: # strings
@@ -44,7 +48,7 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
4448
(?<s2q2>')
4549
|
4650
(?<s3q1>\[(?<stringequals>=*)\[)
47-
(?<s3>(?m:.*?))
51+
(?<s3>(?m).*?)
4852
(?<s3q2>\]\k<stringequals>\])
4953
)
5054
|
@@ -64,13 +68,13 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
6468
|
6569
\.\d+ # .3
6670
)
67-
(?:e[-+]?\d+)? # 3.1e-7
71+
(?:e[-+]?\d+)? # 3.1e-7
6872
)
6973
)\b
7074
|
7175
(?:
7276
(?<blockstart>--\[(?<blockequals>=*)\[)
73-
(?<blockmain>(?m:.*?))
77+
(?<blockmain>(?m).*?)
7478
(?<blockclose>\]\k<blockequals>\])
7579
)
7680
|
@@ -153,6 +157,12 @@ def scan_tokens(tokens, options)
153157
space = !space
154158
end
155159
end
160+
if match[:funcname] && !match[:funcname].empty?
161+
f,s,n = match[:funcname].split(/(\s+)/)
162+
tokens.text_token(f,:keyword)
163+
tokens.text_token(s,:space)
164+
tokens.text_token(n,:function)
165+
end
156166
CAPTURE_KINDS.each do |capture,kind|
157167
next unless match[capture] && !match[capture].empty?
158168
if kind.is_a? Hash

0 commit comments

Comments
 (0)