about summary refs log tree commit diff stats
path: root/js/scripting-lang/lexer.js
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2025-07-27 12:28:44 -0400
committerelioat <elioat@tilde.institute>2025-07-27 12:28:44 -0400
commit59a4a649ad3038857dd091dcc69ca86bf993b3f6 (patch)
tree7db1cbbbbda88fb268ce91175bad2a31014c1d27 /js/scripting-lang/lexer.js
parent83ece970842db4ca0a619a0392a98b2b7445e482 (diff)
downloadtour-master.tar.gz
Diffstat (limited to 'js/scripting-lang/lexer.js')
-rw-r--r--js/scripting-lang/lexer.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/js/scripting-lang/lexer.js b/js/scripting-lang/lexer.js
index de87ac7..3fb300f 100644
--- a/js/scripting-lang/lexer.js
+++ b/js/scripting-lang/lexer.js
@@ -12,10 +12,12 @@
  * - Operators: PLUS, MINUS, MULTIPLY, DIVIDE, MODULO, POWER, etc.
  * - Keywords: WHEN, IS, THEN, FUNCTION, etc.
  * - Punctuation: LEFT_PAREN, RIGHT_PAREN, SEMICOLON, COMMA, etc.
- * - Special: IO_IN, IO_OUT, IO_ASSERT, FUNCTION_REF
+ * - Special: IO_IN, IO_OUT, IO_ASSERT, FUNCTION_REF, COMPOSE
  * 
  * This enumeration provides a centralized definition of all possible
- * token types, ensuring consistency between lexer and parser.
+ * token types, ensuring consistency between lexer and parser. The token
+ * types are designed to support the combinator-based architecture where
+ * all operations are translated to function calls.
  */
 export const TokenType = {
     NUMBER: 'NUMBER',
@@ -60,7 +62,8 @@ export const TokenType = {
     IO_IN: 'IO_IN',
     IO_OUT: 'IO_OUT',
     IO_ASSERT: 'IO_ASSERT',
-    FUNCTION_REF: 'FUNCTION_REF'
+    FUNCTION_REF: 'FUNCTION_REF',
+    COMPOSE: 'COMPOSE'
 };
 
 /**
@@ -84,9 +87,13 @@ export const TokenType = {
  * - Supports string literals with escape sequences
  * - Provides detailed position information for error reporting
  * - Cross-platform compatibility (Node.js, Bun, browser)
+ * - Supports function composition with 'via' keyword
+ * - Handles function references with '@' operator
  * 
  * The lexer is designed to be robust and provide clear error messages
  * for malformed input, making it easier to debug syntax errors in user code.
+ * It supports the combinator-based architecture by recognizing all operators
+ * and special tokens needed for function composition and application.
  */
 export function lexer(input) {
     const tokens = [];
@@ -249,6 +256,9 @@ export function lexer(input) {
                 case 'function':
                     tokens.push({ type: TokenType.FUNCTION, line, column: startColumn });
                     break;
+                case 'via':
+                    tokens.push({ type: TokenType.COMPOSE, line, column: startColumn });
+                    break;
                 case '_':
                     tokens.push({ type: TokenType.WILDCARD, line, column: startColumn });
                     break;