about summary refs log tree commit diff stats
path: root/js/scripting-lang/NEXT-STEPS.md
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/NEXT-STEPS.md')
-rw-r--r--js/scripting-lang/NEXT-STEPS.md229
1 files changed, 0 insertions, 229 deletions
diff --git a/js/scripting-lang/NEXT-STEPS.md b/js/scripting-lang/NEXT-STEPS.md
deleted file mode 100644
index 7cb1e75..0000000
--- a/js/scripting-lang/NEXT-STEPS.md
+++ /dev/null
@@ -1,229 +0,0 @@
-# Next Steps: Table Features Implementation
-
-## Current State Analysis
-
-### What Works ✅
-- Basic table creation: `{name: "Alice", age: 30}`
-- Simple table access: `person.name` (single level)
-- Basic function definitions: `inc : x -> x + 1`
-- Basic function calls: `inc 5`
-- Table literals with functions: `{inc: x -> x + 1}` (parsed but not fully functional)
-
-### What's Broken ❌
-1. **Chained table access**: `config.user.name` fails with "Unexpected dot (.) token"
-2. **Function calls from tables**: `m.inc 1` doesn't work
-3. **Functions in table literals**: May not be properly interpreted
-
-## Root Cause Analysis
-
-### Issue 1: Chained Table Access
-**Problem**: Parser encounters standalone DOT tokens when parsing `config.user.name`
-**Location**: Assignment parsing logic in `walk()` function
-**Debug Evidence**: 
-- Tokens: `[IDENTIFIER "config", DOT, IDENTIFIER "user", DOT, IDENTIFIER "name"]`
-- Parser fails at position 17 (second DOT) because it's not in table access context
-
-### Issue 2: Function Calls from Tables
-**Problem**: Parser doesn't recognize `m.inc 1` as a function call
-**Location**: Function call parsing logic
-**Expected**: Should parse as `FunctionCall` with `name: TableAccess` and `args: [1]`
-
-## Implementation Plan
-
-### Phase 1: Fix Chained Table Access Parser
-
-#### Step 1.1: Update Assignment Value Parsing
-**File**: `lang.js` around line 1300-1400
-**Change**: Modify assignment parsing to handle chained dot notation before falling back to `walk()`
-
-**Current Logic**:
-```javascript
-// Assignment parsing falls back to walk() for value
-const value = walk(); // This fails on DOT tokens
-```
-
-**New Logic**:
-```javascript
-// Check if value is a chained table access
-if (tokens[current] && tokens[current].type === TokenType.IDENTIFIER &&
-    tokens[current + 1] && tokens[current + 1].type === TokenType.DOT) {
-    // Parse chained table access
-    const tableAccess = parseChainedTableAccess();
-    return { type: 'AssignmentExpression', name, value: tableAccess };
-}
-// Fall back to walk() for other cases
-const value = walk();
-```
-
-#### Step 1.2: Create parseChainedTableAccess Helper
-**File**: `lang.js` in `walk()` function
-**Purpose**: Parse arbitrary length dot notation chains
-
-**Implementation**:
-```javascript
-function parseChainedTableAccess() {
-    let tableExpr = {
-        type: 'Identifier',
-        value: tokens[current].value
-    };
-    current++; // Skip first identifier
-    
-    while (tokens[current] && tokens[current].type === TokenType.DOT) {
-        current++; // Skip dot
-        if (tokens[current] && tokens[current].type === TokenType.IDENTIFIER) {
-            const key = {
-                type: 'StringLiteral',
-                value: tokens[current].value
-            };
-            current++; // Skip identifier
-            
-            tableExpr = {
-                type: 'TableAccess',
-                table: tableExpr,
-                key
-            };
-        } else {
-            throw new Error('Expected identifier after dot in table access');
-        }
-    }
-    
-    return tableExpr;
-}
-```
-
-#### Step 1.3: Update Function Call Parsing
-**File**: `lang.js` around line 600-700
-**Change**: Allow `TableAccess` nodes as function names
-
-**Current Logic**:
-```javascript
-// Only handles string function names
-func = globalScope[node.name];
-```
-
-**New Logic**:
-```javascript
-if (typeof node.name === 'string') {
-    func = globalScope[node.name];
-} else if (node.name.type === 'TableAccess') {
-    // Evaluate table access to get function
-    func = evalNode(node.name);
-    if (typeof func !== 'function') {
-        throw new Error('Table access did not resolve to a function');
-    }
-}
-```
-
-### Phase 2: Fix Function Calls from Tables
-
-#### Step 2.1: Update Function Call Detection
-**File**: `lang.js` in `parseFunctionCall()` function
-**Change**: Detect when a table access is followed by arguments
-
-**Current Logic**:
-```javascript
-// Only checks for identifier followed by arguments
-if (tokens[current + 1] && tokens[current + 1].type === TokenType.NUMBER) {
-    // Function call
-}
-```
-
-**New Logic**:
-```javascript
-// Check for identifier followed by arguments OR table access followed by arguments
-if ((tokens[current + 1] && tokens[current + 1].type === TokenType.NUMBER) ||
-    (tokens[current + 1] && tokens[current + 1].type === TokenType.DOT)) {
-    // Parse table access first, then check for arguments
-    const tableAccess = parseChainedTableAccess();
-    if (tokens[current] && isArgumentToken(tokens[current])) {
-        // This is a function call from table
-        return parseFunctionCallFromTable(tableAccess);
-    }
-    return tableAccess;
-}
-```
-
-#### Step 2.2: Create parseFunctionCallFromTable Helper
-**Purpose**: Parse function calls where the function is a table access
-
-**Implementation**:
-```javascript
-function parseFunctionCallFromTable(tableAccess) {
-    const args = [];
-    while (current < tokens.length && isArgumentToken(tokens[current])) {
-        args.push(walk());
-    }
-    return {
-        type: 'FunctionCall',
-        name: tableAccess,
-        args
-    };
-}
-```
-
-### Phase 3: Test and Validate
-
-#### Step 3.1: Create Comprehensive Test Suite
-**File**: `table_features_test.txt`
-
-**Test Cases**:
-```plaintext
-/* Test 1: Basic table access */
-person : {name: "Alice", age: 30};
-name : person.name;
-..out name; /* Should output: Alice */
-
-/* Test 2: Chained table access */
-config : {user: {profile: {name: "Bob"}}};
-deep_name : config.user.profile.name;
-..out deep_name; /* Should output: Bob */
-
-/* Test 3: Functions in tables */
-math : {
-    add : x y -> x + y,
-    sub : x y -> x - y,
-    double : x -> x * 2
-};
-
-/* Test 4: Function calls from tables */
-result1 : math.add 3 4;     /* Should be 7 */
-result2 : math.sub 10 3;    /* Should be 7 */
-result3 : math.double 5;    /* Should be 10 */
-..out result1;
-..out result2;
-..out result3;
-
-/* Test 5: Nested function calls from tables */
-nested : math.double(math.add 2 3); /* Should be 10 */
-..out nested;
-```
-
-#### Step 3.2: Debug and Fix Issues
-- Run tests and identify any remaining issues
-- Add debug logging as needed
-- Fix edge cases and error handling
-
-## Implementation Order
-
-1. **Phase 1.1**: Update assignment value parsing
-2. **Phase 1.2**: Create parseChainedTableAccess helper
-3. **Phase 1.3**: Update function call parsing
-4. **Phase 2.1**: Update function call detection
-5. **Phase 2.2**: Create parseFunctionCallFromTable helper
-6. **Phase 3.1**: Create comprehensive test suite
-7. **Phase 3.2**: Debug and validate
-
-## Success Criteria
-
-- ✅ `config.user.name` parses and evaluates correctly
-- ✅ `m.inc 1` parses and evaluates to 2
-- ✅ `m.inc(m.dec(5))` works with nested calls
-- ✅ Functions defined in table literals work correctly
-- ✅ No regression in existing functionality
-
-## Risk Mitigation
-
-- **Minimal changes**: Each change targets a specific issue
-- **Debug logging**: Keep debug output to trace issues
-- **Incremental testing**: Test each phase before proceeding
-- **Fallback logic**: Maintain existing `walk()` fallback for non-table cases 
\ No newline at end of file