Skip to content

Commit f8d3e0c

Browse files
committed
feat: Implement the initial lexer (scanner) for ProXPL.
1 parent ea4103b commit f8d3e0c

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

include/scanner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ typedef enum {
117117
TOKEN_PROTECTED,
118118
TOKEN_ABSTRACT,
119119
TOKEN_NATIVE,
120+
TOKEN_NEW,
120121
TOKEN_VOID,
121122
TOKEN_DEFER,
122123

src/compiler/lexer/scanner.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ static PxTokenType identifierType(Scanner *scanner) {
306306
switch (scanner->start[1]) {
307307
case 'a':
308308
return checkKeyword(scanner, 2, 4, "tive", TOKEN_NATIVE);
309+
case 'e':
310+
return checkKeyword(scanner, 2, 1, "w", TOKEN_NEW);
309311
case 'u':
310312
return checkKeyword(scanner, 2, 2, "ll", TOKEN_NULL);
311313
}
@@ -323,7 +325,10 @@ static PxTokenType identifierType(Scanner *scanner) {
323325
case 'n':
324326
return checkKeyword(scanner, 4, 1, "t", TOKEN_PRINT);
325327
case 'v':
326-
return checkKeyword(scanner, 4, 3, "ate", TOKEN_PRIVATE);
328+
if (scanner->current - scanner->start > 4) {
329+
return checkKeyword(scanner, 4, 3, "ate", TOKEN_PRIVATE);
330+
}
331+
return checkKeyword(scanner, 4, 0, "", TOKEN_PRIVATE);
327332
}
328333
}
329334
break;
@@ -333,6 +338,17 @@ static PxTokenType identifierType(Scanner *scanner) {
333338
}
334339
break;
335340
case 'u':
341+
if (scanner->current - scanner->start > 2) {
342+
switch (scanner->start[2]) {
343+
case 'b':
344+
if (scanner->current - scanner->start > 3) {
345+
// publ...
346+
return checkKeyword(scanner, 4, 2, "ic", TOKEN_PUBLIC);
347+
}
348+
// pub
349+
return checkKeyword(scanner, 2, 1, "b", TOKEN_PUBLIC);
350+
}
351+
}
336352
return checkKeyword(scanner, 2, 4, "blic", TOKEN_PUBLIC);
337353
}
338354
}

0 commit comments

Comments
 (0)