A class I am in for university uses strudel a lot and we noticed that some of the error messaging was tough to read for beginner users. For my final project for the class I hope to fix this issue and contribute to the software. I was thinking of adding some more clearly defined error messages. For example, a missing paratheses currently reads in the error bar as "unexpected token at x:y". Changing it indiciate what character is missing for some syntax issue or possibly highlighting the location of the error for easier debugging for novice users. Would love and appreciate any feedback regarding on the feasibility of this as well as how best to go about this?? I have already taken a look around the repo and think I know where it would be best to work (Krill and/or code mirror packages).
I think highlighting of the location would be huge. I expect youβll mostly be working in the krill file, as you say. I wish you luck, I recently did some diving into there and it was not trivial! Happy to give help where I can
Would love some help! I am planning on starting to dive deeper into this in about a week. I would really appreciate some guidance!
So here is my plan so far
Background/overview:
- the mini notation for the parser in is βkrill-parser.jsβ
- this produced an error object called peg$SyntaxError with the fields, expected, found, and location
- this is then sent to the mini.mjs and reformatted
- in the JS transpilation
- uses a Acorn parser
- produces your basic stantard javascript SyntaxError
- in runtime eval
- errors is going thru repl.mjs via the evalError
- UI
- stored in UserFacingMessage.jsx
- just renders error.message
What is needed to be done
-
modify mini.mjs to improve the mini notation error messages
-
add some visual element to indicate where error is
-
change the error display component (maybe too much)
-
select the rule set
- notation (maybe best to just start here)
- missing brackets βbd [sdβ
- missing paren βbd(3,8β
- invalid char βbd $ sdβ
- unclosed angle bracket β<bd sdβ
- notation (maybe best to just start here)
-
build out the tests
First run thru
- errorHighlight.mjs
- codemirror extension adds the red highlight
- exports to the highlight error
- catches and just adds the region [from,to]
- bubbles up to strudlelmirror
restrictions, only shows first error.
Nice work so far!
Update!
-
Added findUnmatched bracket (mini.njs lines 193-225)
-
Scans through the mini notation code and when finding a closing bracket, check if matches most recent opener
-
Before it would highlight the parserβs position (end of string typically)
-
Now it checks for bracket issues
-
Missing closer would highlight the unclosed opening bracket
-
Extra closer would the extra closing bracket
-
Mismatching pair would highlight everything in between
-
-
-
Transpiler.mjs
-
Wrapped parse in a try catch
- Catches the acorn syntax error object and creates a new region field
-
This handles the case with a loose stray string
-
-
Runtime errors in evalute.mjs
-
Updates evaluate function to find region
-
Use case is where there might be something missed spelt like .rom(1)
AI Generated test cases below
//runtime errors
// === Mini Notation Bracket Errors ===
s("bd [sd hh") // Missing "]" β the "[" would be highlighted
s("bd {sd hh") // Missing "}" β the "{" would be highlighted
s("bd <sd hh") // Missing ">" β the "<" would be highlighted
s("bd sd]") // Extra "]" β the "]" would be highlighted
s("bd sd}") // Extra "}" β the "}" would be highlighted
s("bd sd>") // Extra ">" β the ">" would be highlighted
s("bd [sd}") // Mismatched "[" and "}" β range from "[" to "}" highlighted
s("[bd [sd hh]") // Nested, outer missing "]" β the first "[" highlighted
s("bd(3,8") // Missing ")" in euclidean β the "(" highlighted
// === JavaScript Syntax Errors ===
c
$: s("bd sd") // Stray "c" β the "c" would be highlighted
$: s("bd sd" // Missing ")" β the "(" would be highlighted
$: s(("bd sd") // Missing ")" β the first "(" would be highlighted
$: {s("bd sd") // Missing "}" β the "{" would be highlighted
$: s("bd sd") + // Incomplete expression β end of line highlighted
// === Runtime Errors (method/variable not found) ===
s("bd sd").rom(1) // rom is not a function β "rom" would be highlighted
s("bd sd").fsat(2) // fsat is not a function β "fsat" would be highlighted
s("bd sd").spede(2) // spede is not a function β "spede" would be highlighted
s("bd sd").nonExistent() // nonExistent is not a function β "nonExistent" highlighted
xyz // xyz is not defined β "xyz" would be highlighted
myFunc() // myFunc is not defined β "myFunc" would be highlighted
-
