Skip to content

Commit 4a9f1fe

Browse files
committed
Use inline option switching for simpler regex
1 parent ef83c13 commit 4a9f1fe

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

lib/coderay/scanners/lua.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ 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>[\d\D]*?) # eat content up until something we want
33+
(?<fluff>(?m:.*?)) # eat content up until something we want
3434
(?:
3535
\b(?<keyword>#{KEYWORDS.join('|')})\b
3636
|
@@ -44,34 +44,34 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
4444
(?<s2q2>')
4545
|
4646
(?<s3q1>\[(?<stringequals>=*)\[)
47-
(?<s3>[\d\D]*?) # Not using multiline mode due to single-line comments
47+
(?<s3>(?m:.*?))
4848
(?<s3q2>\]\k<stringequals>\])
4949
)
5050
|
5151
\b(?<number>
5252
-? # Allows -2 to be properly highlighted, but makes 10-5 show -5 as a single number
53-
(?:
54-
0[xX]
53+
(?i:
54+
0x
5555
(?:
56-
[\da-fA-F]+\.?[\da-fA-F]* # 0xA and 0xA. and 0xA.1
56+
[\da-f]+\.?[\da-f]* # 0xA and 0xA. and 0xA.1
5757
|
58-
\.[\da-fA-F]+ # 0x.A
58+
\.[\da-f]+ # 0x.A
5959
)
60-
(?:[pP][-+]?\d+)? # 0xA.1p-3
60+
(?:p[-+]?\d+)? # 0xA.1p-3
6161
|
6262
(?:
63-
\d+\.?\d* # 3 and 3. and 3.14
63+
\d+\.?\d* # 3 and 3. and 3.14
6464
|
65-
\.\d+ # .3
65+
\.\d+ # .3
6666
)
67-
(?:[eE][-+]?\d+)? # 3.1e-7
67+
(?:e[-+]?\d+)? # 3.1e-7
6868
)
6969
)\b
7070
|
7171
(?:
72-
(?<blockcommentstart>--\[(?<commentequals>=*)\[)
73-
(?<blockcommentmain>[\d\D]*?) # Not using multiline mode due to single-line comments
74-
(?<blockcommentclose>\]\k<commentequals>\])
72+
(?<blockstart>--\[(?<blockequals>=*)\[)
73+
(?<blockmain>(?m:.*?))
74+
(?<blockclose>\]\k<blockequals>\])
7575
)
7676
|
7777
(?<comment>
@@ -99,19 +99,19 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
9999
)
100100
|
101101
(?<gotolabel>
102-
::[a-zA-Z_]\w*::
102+
(?i:::[a-z_]\w*::)
103103
)
104104
)
105105
/x
106106

107107
CAPTURE_KINDS = {
108108
reserved: :reserved,
109109
comment: :comment,
110-
blockcommentstart: {
110+
blockstart: {
111111
_group: :comment,
112-
blockcommentstart: :delimiter,
113-
blockcommentmain: :content,
114-
blockcommentclose: :delimiter
112+
blockstart: :delimiter,
113+
blockmain: :content,
114+
blockclose: :delimiter
115115
},
116116
keyword: :keyword,
117117
number: :float,

0 commit comments

Comments
 (0)