@@ -81,28 +81,28 @@ module Impl {
81
81
// https://doc.rust-lang.org/reference/tokens.html#integer-literals
82
82
private module IntegerLiteralRegexs {
83
83
bindingset [ s]
84
- string paren ( string s ) { result = "(" + s + ")" }
84
+ string paren ( string s ) { result = "(?: " + s + ")" }
85
85
86
86
string integerLiteral ( ) {
87
87
result =
88
88
paren ( paren ( decLiteral ( ) ) + "|" + paren ( binLiteral ( ) ) + "|" + paren ( octLiteral ( ) ) + "|" +
89
- paren ( hexLiteral ( ) ) ) + paren ( suffix ( ) ) + "?"
89
+ paren ( hexLiteral ( ) ) ) + "(" + suffix ( ) + ") ?"
90
90
}
91
91
92
92
private string suffix ( ) { result = "u8|i8|u16|i16|u32|i32|u64|i64|u128|i128|usize|isize" }
93
93
94
- string decLiteral ( ) { result = decDigit ( ) + "(" + decDigit ( ) + "|_)*" }
94
+ string decLiteral ( ) { result = decDigit ( ) + "(?: " + decDigit ( ) + "|_)*" }
95
95
96
96
string binLiteral ( ) {
97
- result = "0b(" + binDigit ( ) + "|_)*" + binDigit ( ) + "(" + binDigit ( ) + "|_)*"
97
+ result = "0b(?: " + binDigit ( ) + "|_)*" + binDigit ( ) + "(?: " + binDigit ( ) + "|_)*"
98
98
}
99
99
100
100
string octLiteral ( ) {
101
- result = "0o(" + octDigit ( ) + "|_)*" + octDigit ( ) + "(" + octDigit ( ) + "|_)*"
101
+ result = "0o(?: " + octDigit ( ) + "|_)*" + octDigit ( ) + "(?: " + octDigit ( ) + "|_)*"
102
102
}
103
103
104
104
string hexLiteral ( ) {
105
- result = "0x(" + hexDigit ( ) + "|_)*" + hexDigit ( ) + "(" + hexDigit ( ) + "|_)*"
105
+ result = "0x(?: " + hexDigit ( ) + "|_)*" + hexDigit ( ) + "(?: " + hexDigit ( ) + "|_)*"
106
106
}
107
107
108
108
string decDigit ( ) { result = "[0-9]" }
@@ -135,7 +135,7 @@ module Impl {
135
135
exists ( string s , string reg |
136
136
s = this .getTextValue ( ) and
137
137
reg = IntegerLiteralRegexs:: integerLiteral ( ) and
138
- result = s .regexpCapture ( reg , 13 )
138
+ result = s .regexpCapture ( reg , 1 )
139
139
)
140
140
}
141
141
@@ -153,24 +153,25 @@ module Impl {
153
153
}
154
154
155
155
string floatLiteralSuffix1 ( ) {
156
- result = decLiteral ( ) + "\\." + decLiteral ( ) + paren ( suffix ( ) ) + "?"
156
+ result = decLiteral ( ) + "\\." + decLiteral ( ) + "(" + suffix ( ) + ") ?"
157
157
}
158
158
159
159
string floatLiteralSuffix2 ( ) {
160
160
result =
161
- decLiteral ( ) + paren ( "\\." + decLiteral ( ) ) + "?" + paren ( exponent ( ) ) + paren ( suffix ( ) ) + "?"
161
+ decLiteral ( ) + paren ( "\\." + decLiteral ( ) ) + "?" + paren ( exponent ( ) ) + "(" + suffix ( ) + ") ?"
162
162
}
163
163
164
164
string integerSuffixLiteral ( ) {
165
165
result =
166
166
paren ( paren ( decLiteral ( ) ) + "|" + paren ( binLiteral ( ) ) + "|" + paren ( octLiteral ( ) ) + "|" +
167
- paren ( hexLiteral ( ) ) ) + paren ( suffix ( ) )
167
+ paren ( hexLiteral ( ) ) ) + "(" + suffix ( ) + ")"
168
168
}
169
169
170
170
private string suffix ( ) { result = "f32|f64" }
171
171
172
172
string exponent ( ) {
173
- result = "(e|E)(\\+|-)?(" + decDigit ( ) + "|_)*" + decDigit ( ) + "(" + decDigit ( ) + "|_)*"
173
+ result =
174
+ "(?:e|E)(?:\\+|-)?(?:" + decDigit ( ) + "|_)*" + decDigit ( ) + "(?:" + decDigit ( ) + "|_)*"
174
175
}
175
176
}
176
177
@@ -198,18 +199,13 @@ module Impl {
198
199
* For example, `42.0f32` has the suffix `f32`.
199
200
*/
200
201
string getSuffix ( ) {
201
- exists ( string s , string reg , int group |
202
- reg = FloatLiteralRegexs:: floatLiteralSuffix1 ( ) and
203
- group = 3
204
- or
205
- reg = FloatLiteralRegexs:: floatLiteralSuffix2 ( ) and
206
- group = 9
207
- or
208
- reg = FloatLiteralRegexs:: integerSuffixLiteral ( ) and
209
- group = 13
210
- |
202
+ exists ( string s , string reg |
203
+ reg =
204
+ IntegerLiteralRegexs:: paren ( FloatLiteralRegexs:: floatLiteralSuffix1 ( ) ) + "|" +
205
+ IntegerLiteralRegexs:: paren ( FloatLiteralRegexs:: floatLiteralSuffix2 ( ) ) + "|" +
206
+ IntegerLiteralRegexs:: paren ( FloatLiteralRegexs:: integerSuffixLiteral ( ) ) and
211
207
s = this .getTextValue ( ) and
212
- result = s .regexpCapture ( reg , group )
208
+ result = s .regexpCapture ( reg , [ 1 , 2 , 3 ] )
213
209
)
214
210
}
215
211
0 commit comments