2
2
3
3
use std:: ops;
4
4
5
- use pgt_lexer_new :: tokenize;
5
+ use pgt_tokenizer :: tokenize;
6
6
7
7
use crate :: SyntaxKind ;
8
8
@@ -109,7 +109,7 @@ impl<'a> Converter<'a> {
109
109
}
110
110
}
111
111
112
- fn extend_token ( & mut self , kind : & pgt_lexer_new :: TokenKind , token_text : & str ) {
112
+ fn extend_token ( & mut self , kind : & pgt_tokenizer :: TokenKind , token_text : & str ) {
113
113
// A note on an intended tradeoff:
114
114
// We drop some useful information here (see patterns with double dots `..`)
115
115
// Storing that info in `SyntaxKind` is not possible due to its layout requirements of
@@ -118,22 +118,22 @@ impl<'a> Converter<'a> {
118
118
119
119
let syntax_kind = {
120
120
match kind {
121
- pgt_lexer_new :: TokenKind :: LineComment => SyntaxKind :: COMMENT ,
122
- pgt_lexer_new :: TokenKind :: BlockComment { terminated } => {
121
+ pgt_tokenizer :: TokenKind :: LineComment => SyntaxKind :: COMMENT ,
122
+ pgt_tokenizer :: TokenKind :: BlockComment { terminated } => {
123
123
if !terminated {
124
124
err = "Missing trailing `*/` symbols to terminate the block comment" ;
125
125
}
126
126
SyntaxKind :: COMMENT
127
127
}
128
128
129
129
// whitespace
130
- pgt_lexer_new :: TokenKind :: Space => SyntaxKind :: SPACE ,
131
- pgt_lexer_new :: TokenKind :: Tab => SyntaxKind :: TAB ,
132
- pgt_lexer_new :: TokenKind :: Newline => SyntaxKind :: NEWLINE ,
133
- pgt_lexer_new :: TokenKind :: CarriageReturn => SyntaxKind :: CARRIAGE_RETURN ,
134
- pgt_lexer_new :: TokenKind :: VerticalTab => SyntaxKind :: VERTICAL_TAB ,
135
- pgt_lexer_new :: TokenKind :: FormFeed => SyntaxKind :: FORM_FEED ,
136
- pgt_lexer_new :: TokenKind :: Ident => {
130
+ pgt_tokenizer :: TokenKind :: Space => SyntaxKind :: SPACE ,
131
+ pgt_tokenizer :: TokenKind :: Tab => SyntaxKind :: TAB ,
132
+ pgt_tokenizer :: TokenKind :: Newline => SyntaxKind :: NEWLINE ,
133
+ pgt_tokenizer :: TokenKind :: CarriageReturn => SyntaxKind :: CARRIAGE_RETURN ,
134
+ pgt_tokenizer :: TokenKind :: VerticalTab => SyntaxKind :: VERTICAL_TAB ,
135
+ pgt_tokenizer :: TokenKind :: FormFeed => SyntaxKind :: FORM_FEED ,
136
+ pgt_tokenizer :: TokenKind :: Ident => {
137
137
// TODO: check for max identifier length
138
138
//
139
139
// see: https://www.postgresql.org/docs/16/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
@@ -146,43 +146,43 @@ impl<'a> Converter<'a> {
146
146
// see: https://github.com/postgres/postgres/blob/e032e4c7ddd0e1f7865b246ec18944365d4f8614/src/include/pg_config_manual.h#L29
147
147
SyntaxKind :: from_keyword ( token_text) . unwrap_or ( SyntaxKind :: IDENT )
148
148
}
149
- pgt_lexer_new :: TokenKind :: Literal { kind, .. } => {
149
+ pgt_tokenizer :: TokenKind :: Literal { kind, .. } => {
150
150
self . extend_literal ( token_text. len ( ) , kind) ;
151
151
return ;
152
152
}
153
- pgt_lexer_new :: TokenKind :: Semi => SyntaxKind :: SEMICOLON ,
154
- pgt_lexer_new :: TokenKind :: Comma => SyntaxKind :: COMMA ,
155
- pgt_lexer_new :: TokenKind :: Dot => SyntaxKind :: DOT ,
156
- pgt_lexer_new :: TokenKind :: OpenParen => SyntaxKind :: L_PAREN ,
157
- pgt_lexer_new :: TokenKind :: CloseParen => SyntaxKind :: R_PAREN ,
158
- pgt_lexer_new :: TokenKind :: OpenBracket => SyntaxKind :: L_BRACK ,
159
- pgt_lexer_new :: TokenKind :: CloseBracket => SyntaxKind :: R_BRACK ,
160
- pgt_lexer_new :: TokenKind :: At => SyntaxKind :: AT ,
161
- pgt_lexer_new :: TokenKind :: Pound => SyntaxKind :: POUND ,
162
- pgt_lexer_new :: TokenKind :: Tilde => SyntaxKind :: TILDE ,
163
- pgt_lexer_new :: TokenKind :: Question => SyntaxKind :: QUESTION ,
164
- pgt_lexer_new :: TokenKind :: Colon => SyntaxKind :: COLON ,
165
- pgt_lexer_new :: TokenKind :: Eq => SyntaxKind :: EQ ,
166
- pgt_lexer_new :: TokenKind :: Bang => SyntaxKind :: BANG ,
167
- pgt_lexer_new :: TokenKind :: Lt => SyntaxKind :: L_ANGLE ,
168
- pgt_lexer_new :: TokenKind :: Gt => SyntaxKind :: R_ANGLE ,
169
- pgt_lexer_new :: TokenKind :: Minus => SyntaxKind :: MINUS ,
170
- pgt_lexer_new :: TokenKind :: And => SyntaxKind :: AMP ,
171
- pgt_lexer_new :: TokenKind :: Or => SyntaxKind :: PIPE ,
172
- pgt_lexer_new :: TokenKind :: Plus => SyntaxKind :: PLUS ,
173
- pgt_lexer_new :: TokenKind :: Star => SyntaxKind :: STAR ,
174
- pgt_lexer_new :: TokenKind :: Slash => SyntaxKind :: SLASH ,
175
- pgt_lexer_new :: TokenKind :: Caret => SyntaxKind :: CARET ,
176
- pgt_lexer_new :: TokenKind :: Percent => SyntaxKind :: PERCENT ,
177
- pgt_lexer_new :: TokenKind :: Unknown => SyntaxKind :: ERROR ,
178
- pgt_lexer_new :: TokenKind :: UnknownPrefix => {
153
+ pgt_tokenizer :: TokenKind :: Semi => SyntaxKind :: SEMICOLON ,
154
+ pgt_tokenizer :: TokenKind :: Comma => SyntaxKind :: COMMA ,
155
+ pgt_tokenizer :: TokenKind :: Dot => SyntaxKind :: DOT ,
156
+ pgt_tokenizer :: TokenKind :: OpenParen => SyntaxKind :: L_PAREN ,
157
+ pgt_tokenizer :: TokenKind :: CloseParen => SyntaxKind :: R_PAREN ,
158
+ pgt_tokenizer :: TokenKind :: OpenBracket => SyntaxKind :: L_BRACK ,
159
+ pgt_tokenizer :: TokenKind :: CloseBracket => SyntaxKind :: R_BRACK ,
160
+ pgt_tokenizer :: TokenKind :: At => SyntaxKind :: AT ,
161
+ pgt_tokenizer :: TokenKind :: Pound => SyntaxKind :: POUND ,
162
+ pgt_tokenizer :: TokenKind :: Tilde => SyntaxKind :: TILDE ,
163
+ pgt_tokenizer :: TokenKind :: Question => SyntaxKind :: QUESTION ,
164
+ pgt_tokenizer :: TokenKind :: Colon => SyntaxKind :: COLON ,
165
+ pgt_tokenizer :: TokenKind :: Eq => SyntaxKind :: EQ ,
166
+ pgt_tokenizer :: TokenKind :: Bang => SyntaxKind :: BANG ,
167
+ pgt_tokenizer :: TokenKind :: Lt => SyntaxKind :: L_ANGLE ,
168
+ pgt_tokenizer :: TokenKind :: Gt => SyntaxKind :: R_ANGLE ,
169
+ pgt_tokenizer :: TokenKind :: Minus => SyntaxKind :: MINUS ,
170
+ pgt_tokenizer :: TokenKind :: And => SyntaxKind :: AMP ,
171
+ pgt_tokenizer :: TokenKind :: Or => SyntaxKind :: PIPE ,
172
+ pgt_tokenizer :: TokenKind :: Plus => SyntaxKind :: PLUS ,
173
+ pgt_tokenizer :: TokenKind :: Star => SyntaxKind :: STAR ,
174
+ pgt_tokenizer :: TokenKind :: Slash => SyntaxKind :: SLASH ,
175
+ pgt_tokenizer :: TokenKind :: Caret => SyntaxKind :: CARET ,
176
+ pgt_tokenizer :: TokenKind :: Percent => SyntaxKind :: PERCENT ,
177
+ pgt_tokenizer :: TokenKind :: Unknown => SyntaxKind :: ERROR ,
178
+ pgt_tokenizer :: TokenKind :: UnknownPrefix => {
179
179
err = "unknown literal prefix" ;
180
180
SyntaxKind :: IDENT
181
181
}
182
- pgt_lexer_new :: TokenKind :: Eof => SyntaxKind :: EOF ,
183
- pgt_lexer_new :: TokenKind :: Backtick => SyntaxKind :: BACKTICK ,
184
- pgt_lexer_new :: TokenKind :: PositionalParam => SyntaxKind :: POSITIONAL_PARAM ,
185
- pgt_lexer_new :: TokenKind :: QuotedIdent { terminated } => {
182
+ pgt_tokenizer :: TokenKind :: Eof => SyntaxKind :: EOF ,
183
+ pgt_tokenizer :: TokenKind :: Backtick => SyntaxKind :: BACKTICK ,
184
+ pgt_tokenizer :: TokenKind :: PositionalParam => SyntaxKind :: POSITIONAL_PARAM ,
185
+ pgt_tokenizer :: TokenKind :: QuotedIdent { terminated } => {
186
186
if !terminated {
187
187
err = "Missing trailing \" to terminate the quoted identifier"
188
188
}
@@ -195,17 +195,17 @@ impl<'a> Converter<'a> {
195
195
self . push ( syntax_kind, token_text. len ( ) , err) ;
196
196
}
197
197
198
- fn extend_literal ( & mut self , len : usize , kind : & pgt_lexer_new :: LiteralKind ) {
198
+ fn extend_literal ( & mut self , len : usize , kind : & pgt_tokenizer :: LiteralKind ) {
199
199
let mut err = "" ;
200
200
201
201
let syntax_kind = match * kind {
202
- pgt_lexer_new :: LiteralKind :: Int { empty_int, base : _ } => {
202
+ pgt_tokenizer :: LiteralKind :: Int { empty_int, base : _ } => {
203
203
if empty_int {
204
204
err = "Missing digits after the integer base prefix" ;
205
205
}
206
206
SyntaxKind :: INT_NUMBER
207
207
}
208
- pgt_lexer_new :: LiteralKind :: Float {
208
+ pgt_tokenizer :: LiteralKind :: Float {
209
209
empty_exponent,
210
210
base : _,
211
211
} => {
@@ -214,43 +214,43 @@ impl<'a> Converter<'a> {
214
214
}
215
215
SyntaxKind :: FLOAT_NUMBER
216
216
}
217
- pgt_lexer_new :: LiteralKind :: Str { terminated } => {
217
+ pgt_tokenizer :: LiteralKind :: Str { terminated } => {
218
218
if !terminated {
219
219
err = "Missing trailing `'` symbol to terminate the string literal" ;
220
220
}
221
221
// TODO: rust analzyer checks for un-escaped strings, we should too
222
222
SyntaxKind :: STRING
223
223
}
224
- pgt_lexer_new :: LiteralKind :: ByteStr { terminated } => {
224
+ pgt_tokenizer :: LiteralKind :: ByteStr { terminated } => {
225
225
if !terminated {
226
226
err = "Missing trailing `'` symbol to terminate the hex bit string literal" ;
227
227
}
228
228
// TODO: rust analzyer checks for un-escaped strings, we should too
229
229
SyntaxKind :: BYTE_STRING
230
230
}
231
- pgt_lexer_new :: LiteralKind :: BitStr { terminated } => {
231
+ pgt_tokenizer :: LiteralKind :: BitStr { terminated } => {
232
232
if !terminated {
233
233
err = "Missing trailing `\' ` symbol to terminate the bit string literal" ;
234
234
}
235
235
// TODO: rust analzyer checks for un-escaped strings, we should too
236
236
SyntaxKind :: BIT_STRING
237
237
}
238
- pgt_lexer_new :: LiteralKind :: DollarQuotedString { terminated } => {
238
+ pgt_tokenizer :: LiteralKind :: DollarQuotedString { terminated } => {
239
239
if !terminated {
240
240
// TODO: we could be fancier and say the ending string we're looking for
241
241
err = "Unterminated dollar quoted string literal" ;
242
242
}
243
243
// TODO: rust analzyer checks for un-escaped strings, we should too
244
244
SyntaxKind :: DOLLAR_QUOTED_STRING
245
245
}
246
- pgt_lexer_new :: LiteralKind :: UnicodeEscStr { terminated } => {
246
+ pgt_tokenizer :: LiteralKind :: UnicodeEscStr { terminated } => {
247
247
if !terminated {
248
248
err = "Missing trailing `'` symbol to terminate the unicode escape string literal" ;
249
249
}
250
250
// TODO: rust analzyer checks for un-escaped strings, we should too
251
251
SyntaxKind :: BYTE_STRING
252
252
}
253
- pgt_lexer_new :: LiteralKind :: EscStr { terminated } => {
253
+ pgt_tokenizer :: LiteralKind :: EscStr { terminated } => {
254
254
if !terminated {
255
255
err = "Missing trailing `\' ` symbol to terminate the escape string literal" ;
256
256
}
0 commit comments