parsing pattern matching

This commit is contained in:
Dustin Swan 2026-02-01 18:42:50 -07:00
parent d81318333e
commit 7f94cfe8cd
No known key found for this signature in database
GPG key ID: 30D46587E2100467
4 changed files with 176 additions and 11 deletions

View file

@ -48,6 +48,7 @@ export function tokenize(source: string): Token[] {
continue;
}
// Comments
if (char === '#') {
while (i < source.length && source[i] !== '\n') {
i++;
@ -76,7 +77,7 @@ export function tokenize(source: string): Token[] {
continue;
}
// Idents
// Idents & Wildcard
if (/[A-Za-z_]/.test(char)) {
let str = '';
while (i < source.length && /[A-Za-z0-9_!-]/.test(source[i])) {
@ -84,11 +85,16 @@ export function tokenize(source: string): Token[] {
i++;
}
const isType = /[A-Z]/.test(str[0]);
if (str === '_') {
// Wildcards
tokens.push({ kind: 'underscore' });
} else {
const isType = /[A-Z]/.test(str[0]);
tokens.push(isType
? { kind: 'type-ident', value: str }
: { kind: 'ident', value: str });
tokens.push(isType
? { kind: 'type-ident', value: str }
: { kind: 'ident', value: str });
}
continue;
}