summaryrefslogtreecommitdiff
path: root/src/js-lang/core/lexer.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/js-lang/core/lexer.ts')
-rw-r--r--src/js-lang/core/lexer.ts46
1 files changed, 0 insertions, 46 deletions
diff --git a/src/js-lang/core/lexer.ts b/src/js-lang/core/lexer.ts
deleted file mode 100644
index 95e0e19..0000000
--- a/src/js-lang/core/lexer.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-import { TokenType, Lex, Token } from "../../ts-lang";
-
-const WHITESPACE_TOKENS = [
- TokenType.SPACE,
- TokenType.COMMA,
- TokenType.SEMICOLON,
-] as string[];
-
-export const lex = <const Raw extends string>(raw: Raw): Lex<Raw> => {
- let _raw: string = raw;
- let nameCollection = "";
- const tokens: Token[] = [];
-
- while (_raw) {
- const head = _raw[0];
- _raw = _raw.slice(1);
-
- const processNameCollection = () => {
- if (nameCollection) {
- tokens.push({ type: TokenType.NAME, name: nameCollection });
- nameCollection = "";
- }
- };
-
- if (WHITESPACE_TOKENS.includes(head)) {
- processNameCollection();
- continue;
- }
-
- if (head === TokenType.OPEN_PAREN) {
- processNameCollection();
- tokens.push({ type: TokenType.OPEN_PAREN, name: "" });
- continue;
- }
-
- if (head === TokenType.CLOSE_PAREN) {
- processNameCollection();
- tokens.push({ type: TokenType.CLOSE_PAREN, name: "" });
- continue;
- }
-
- nameCollection += head;
- }
-
- return tokens as Lex<Raw>;
-};