Fix linked list insertValue operation losing nodes#50
Conversation
Co-authored-by: Silvan-M <39488325+Silvan-M@users.noreply.github.com>
Silvan-M
left a comment
There was a problem hiding this comment.
The fix works.
However, it reveals deeper rooted issues. The idea here would be to use .insertNode(index, nodeName) however:
- Currently there are no compile errors on unsupported types
- We don't supply any node name on linked lists for
insertValue()
Thus we have decided to:
Please update data-structures, and all other files with this:
- Support .insertNode a third optional parameter, e.g. we now have
.insertNode(index, name, value?) - We only support
.insertValue(index, value)for Arrays and Stacks. Not anymore LinkedLists or Graphs. - Now we want compiler errors for non supported types, currently that doesn't work, maybe you can update
languageConfig.js(which is also used by Monaco editor) and import it inside the compiler to check supported functions.
Here's an updated docs on everything that should or shouldn't be supported:
methods.md
Files need to update:
- merlinLite.ne (Syntax)
- languageConfig.js
- compiler.mjs
- reconstructor.mjs (make sure reconstructing compiled code works)
- dslUtils (maybe)
- commandUtils (maybe)
You might wanna verify syntax changes, for this see src/parser/tests/testGrammar.mjs for how to test grammar.
Important commands:
pnpm install // Install dependencies
pnpm run dev // Run dev server
nearleyc src/parser/merlinLite.ne -o src/parser/parser.js // Regenerate parser
node src/parser/tests/testAmbiguityExamples.mjs // At end of all parser tests check if this test runs with no ambiguities or errors
I've implemented the requested changes in commit a8027a0:
Key changes:
The parser regenerated successfully without ambiguities. All the requirements from your feedback have been addressed. |
The
insertValueoperation for linked lists was incorrectly causing nodes to disappear instead of adding new ones. When inserting a value into a linked list, only 3 nodes would be displayed instead of the expected 4.Problem
Consider this example from the issue:
Expected behavior: 4 nodes displayed after insert
Actual behavior: Only 3 nodes displayed, with one node disappearing
Root Cause
The
maintainArrayPropertyConsistencyfunction only synchronized["arrow", "color", "value", "hidden"]properties but ignored the"nodes"property. When inserting a value:["1", "2", "4"]→["1", 500, "2", "4"](length 4)[n0, n1, n2](still length 3)Solution
Added
generateNodeName()function - Intelligently generates node names following existing patterns:n0, n1, n2, n3...A, B, C, D...(falls back tonpattern after Z)Enhanced array consistency logic - Now includes
"nodes"in the properties list for linkedlist/tree/graph components and generates appropriate node names instead of nullsMaintained backward compatibility - Arrays, stacks, matrices, and text components are unaffected
Test Results
insertValue(1, 500)now correctly creates 4 nodesFixes #49.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.