-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use post-parse JuliaSyntax.tokenize()
API
#306
Use post-parse JuliaSyntax.tokenize()
API
#306
Conversation
7094f3e
to
98a95b2
Compare
Note that the tests here won't work until JuliaLang/JuliaSyntax.jl#221 is merged and a new JuliaSyntax release is deployed. |
Going through the parser allows us to be more precise and complete. For example it automatically: * Determines when contextual keywords are keywords, vs identifiers. For example, the `outer` in `outer = 1` is an identifier, but a keyword in `for outer i = 1:10` * Validates numeric literals (eg, detecting overflow cases like `10e1000` and flagging as errors) * Splits or combines ambiguous tokens. For example, making the `...` in `import ...A` three separate `.` tokens.
98a95b2
to
0094fa0
Compare
I released JuliaSyntax-0.3.3 to make this work if you can kick off CI again. @KristofferC 0.3.3 contains your precompile changes and the new |
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #306 +/- ##
==========================================
+ Coverage 56.61% 56.69% +0.07%
==========================================
Files 15 15
Lines 1111 1113 +2
==========================================
+ Hits 629 631 +2
Misses 482 482
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
I need to update the colorschemes to show a nice red background on errors like in your screenshot. |
ef42ebf
to
1cd38d4
Compare
Oops, I'd broken the docs build with this. Hopefully that's fixed now. |
Cool yes updating the color schemes makes sense. I just have this in my startup.jl at the moment. cs = OhMyREPL.Passes.SyntaxHighlighter._create_distinguished()
OhMyREPL.Passes.SyntaxHighlighter.error!(cs,
OhMyREPL.Crayon(background = (120,50,50)))
OhMyREPL.Passes.SyntaxHighlighter.add!("myscheme", cs) We can maybe do better with the errors if we use the full parser but there's a bit of a balance there in terms of avoiding distracting the user when they haven't finished typing. (Might need some heuristic to not report errors due to incomplete syntax etc.) Something for another time anyway. |
Going through the parser allows us to be more precise and complete.
For example it automatically:
outer
inouter = 1
is an identifier, but a keyword infor outer i = 1:10
10e1000
and flagging as errors)...
inimport ...A
three separate.
tokens.Also uses
is_error
to detect error tokens and highlight them with the error color.Requires JuliaLang/JuliaSyntax.jl#221
As I was writing this, I noticed that the syntax highlighter has some heuristics in it to act a bit like a parser (just a very little bit!). For example, highlighting quoted symbols a different color.
So I'm not sure this is the best approach long term - maybe we should just be using the parsed
GreenTree
instead for highlighting. It would give us several options for richer highlighting. Also, if using the parser itself, we'd be able to highlight any syntax error ranges (not just token errors).Regardless of that, though, this is a straightforward modification we can do right away...
Screenshot showing
outer
andabstract
contextual keywords highlighted correctly and some token errors