@@ -68,6 +68,12 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
68
68
)
69
69
)\b
70
70
|
71
+ (?:
72
+ (?<blockcommentstart>--\[ (?<commentequals>=*)\[ )
73
+ (?<blockcommentmain>[\d \D ]*?) # Not using multiline mode due to single-line comments
74
+ (?<blockcommentclose>\] \k <commentequals>\] )
75
+ )
76
+ |
71
77
(?<comment>
72
78
--(?!\[ ).+
73
79
)
@@ -88,12 +94,6 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
88
94
[<>]=?
89
95
)
90
96
|
91
- (?<blockcomment>
92
- --\[ (?<commentequals>=*)
93
- \[ [\d \D ]*? # Not using multiline mode due to single-line comments
94
- \] \k <commentequals>\]
95
- )
96
- |
97
97
(?<reserved>
98
98
\b _[A-Z]+\b # _VERSION
99
99
)
@@ -107,20 +107,34 @@ class CodeRay::Scanners::Lua < CodeRay::Scanners::Scanner
107
107
CAPTURE_KINDS = {
108
108
reserved : :reserved ,
109
109
comment : :comment ,
110
- blockcomment : :comment ,
110
+ blockcommentstart : {
111
+ _group : :comment ,
112
+ blockcommentstart : :delimiter ,
113
+ blockcommentmain : :content ,
114
+ blockcommentclose : :delimiter
115
+ } ,
111
116
keyword : :keyword ,
112
117
number : :float ,
113
118
constant : :"predefined-constant" ,
114
119
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
+ } ,
124
138
gotolabel : :label ,
125
139
operators : :operator ,
126
140
}
@@ -140,7 +154,16 @@ def scan_tokens(tokens, options)
140
154
end
141
155
end
142
156
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
144
167
end
145
168
end
146
169
tokens
0 commit comments