Skip to content

Commit ef83c13

Browse files
committed
Wrap strings and block comment delimiters in groups
1 parent e89c841 commit ef83c13

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

lib/coderay/scanners/lua.rb

+40-17
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
6868
)
6969
)\b
7070
|
71+
(?:
72+
(?<blockcommentstart>--\[(?<commentequals>=*)\[)
73+
(?<blockcommentmain>[\d\D]*?) # Not using multiline mode due to single-line comments
74+
(?<blockcommentclose>\]\k<commentequals>\])
75+
)
76+
|
7177
(?<comment>
7278
--(?!\[).+
7379
)
@@ -88,12 +94,6 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
8894
[<>]=?
8995
)
9096
|
91-
(?<blockcomment>
92-
--\[(?<commentequals>=*)
93-
\[[\d\D]*? # Not using multiline mode due to single-line comments
94-
\]\k<commentequals>\]
95-
)
96-
|
9797
(?<reserved>
9898
\b_[A-Z]+\b # _VERSION
9999
)
@@ -107,20 +107,34 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
107107
CAPTURE_KINDS = {
108108
reserved: :reserved,
109109
comment: :comment,
110-
blockcomment: :comment,
110+
blockcommentstart: {
111+
_group: :comment,
112+
blockcommentstart: :delimiter,
113+
blockcommentmain: :content,
114+
blockcommentclose: :delimiter
115+
},
111116
keyword: :keyword,
112117
number: :float,
113118
constant: :"predefined-constant",
114119
library: :predefined,
115-
s1q1: :delimiter,
116-
s1: :string,
117-
s1q2: :delimiter,
118-
s2q1: :delimiter,
119-
s2: :string,
120-
s2q2: :delimiter,
121-
s3q1: :delimiter,
122-
s3: :string,
123-
s3q2: :delimiter,
120+
s1q1: {
121+
_group: :string,
122+
s1q1: :delimiter,
123+
s1: :content,
124+
s1q2: :delimiter,
125+
},
126+
s2q1: {
127+
_group: :string,
128+
s2q1: :delimiter,
129+
s2: :content,
130+
s2q2: :delimiter,
131+
},
132+
s3q1: {
133+
_group: :string,
134+
s3q1: :delimiter,
135+
s3: :content,
136+
s3q2: :delimiter,
137+
},
124138
gotolabel: :label,
125139
operators: :operator,
126140
}
@@ -140,7 +154,16 @@ def scan_tokens(tokens, options)
140154
end
141155
end
142156
CAPTURE_KINDS.each do |capture,kind|
143-
tokens.text_token( match[capture], kind ) if match[capture] && !match[capture].empty?
157+
next unless match[capture] && !match[capture].empty?
158+
if kind.is_a? Hash
159+
tokens.begin_group(kind[:_group])
160+
kind.each do |c,k|
161+
tokens.text_token( match[c], k ) unless c==:_group
162+
end
163+
tokens.end_group(kind[:_group])
164+
else
165+
tokens.text_token( match[capture], kind )
166+
end
144167
end
145168
end
146169
tokens

0 commit comments

Comments
 (0)