summaryrefslogtreecommitdiff
path: root/src/lib/core/common.ts
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2025-10-28 22:49:46 -0700
committerKai Stevenson <kai@kaistevenson.com>2025-10-28 22:49:46 -0700
commit8896b33a652563d90cb211a85dd2f7213f42e5d1 (patch)
treee9adf51a2ccf91e58f5e8edae4d3d6a4bb03e986 /src/lib/core/common.ts
parse, lex works
Diffstat (limited to 'src/lib/core/common.ts')
-rw-r--r--src/lib/core/common.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/lib/core/common.ts b/src/lib/core/common.ts
new file mode 100644
index 0000000..1283000
--- /dev/null
+++ b/src/lib/core/common.ts
@@ -0,0 +1,45 @@
+export enum TokenType {
+ OPEN_PAREN = "(",
+ CLOSE_PAREN = ")",
+ SPACE = " ",
+ SEMICOLON = ";",
+ COMMA = ",",
+ UNIQUE_SYMBOL = "UNIQUE_SYMBOL",
+}
+
+export type Token<
+ Type extends TokenType = TokenType,
+ Name extends string = string
+> = {
+ type: Type;
+ name: Name;
+};
+
+export type LexerCtx = {
+ next: string;
+ nameCollection: string;
+ tokens: readonly Token[];
+};
+
+export enum NodeType {
+ ROOT = "ROOT",
+ LITERAL = "LITERAL",
+ CALL = "CALL",
+ PARSER_ERROR = "PARSER_ERROR",
+}
+
+export type ASTNode<
+ Type extends NodeType = NodeType,
+ Name extends string = string,
+ Children extends ASTNode[] = ASTNode<NodeType, string, any>[]
+> = {
+ type: Type;
+ name: Name;
+ children: Children;
+};
+
+export type ParserCtx = {
+ remainingTokens: readonly Token[];
+ lastName: string | null;
+ stack: readonly ASTNode[];
+};