about summary refs log tree commit diff stats
path: root/js/scripting-lang/lexer.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/lexer.js')
-rw-r--r--js/scripting-lang/lexer.js26
1 files changed, 22 insertions, 4 deletions
diff --git a/js/scripting-lang/lexer.js b/js/scripting-lang/lexer.js
index de87ac7..4c50b6e 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, FUNCTION_ARG
  * 
  * 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,9 @@ export const TokenType = {
     IO_IN: 'IO_IN',
     IO_OUT: 'IO_OUT',
     IO_ASSERT: 'IO_ASSERT',
-    FUNCTION_REF: 'FUNCTION_REF'
+    FUNCTION_REF: 'FUNCTION_REF',
+    FUNCTION_ARG: 'FUNCTION_ARG',
+    COMPOSE: 'COMPOSE'
 };
 
 /**
@@ -84,9 +88,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 = [];
@@ -168,11 +176,18 @@ export function lexer(input) {
             continue;
         }
         
-        // Function references (@function)
+        // Function references (@function) and function arguments (@(expression))
         if (char === '@') {
             current++; // Skip '@'
             column++;
             
+            // Check if this is @(expression) for function arguments
+            if (current < input.length && input[current] === '(') {
+                // This is @(expression) - mark as function argument
+                tokens.push({ type: TokenType.FUNCTION_ARG, line, column: column - 1 });
+                continue;
+            }
+            
             // Read the function name
             let functionName = '';
             while (current < input.length && /[a-zA-Z0-9_]/.test(input[current])) {
@@ -249,6 +264,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;