parsing pattern matching
This commit is contained in:
parent
d81318333e
commit
7f94cfe8cd
4 changed files with 176 additions and 11 deletions
16
src/lexer.ts
16
src/lexer.ts
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue