is there a different grammar like <http://kotlinla...
# scripting
n
is there a different grammar like http://kotlinlang.org/docs/reference/grammar.html for kts files? or.. closer to what i want.. how can i parse a file into Psi to then use for highlighting ?
g
what are you actually asking for? They're the same grammar
n
i tried to use kastree and the issue ended up not being the grammar but some parts of the grammar not having converters defined for them, i added those and managed to convert it
and that kastree did not expect KtScriptInitializer at all
g
not sure what kastree is
do you just want syntax highlighting based on the ANTLR grammar?
n
thats the idea, atm i am trying to get the KtFile when the script is compiled and use the already existing data
g
well, what do you need the grammar for?
The actual parsing frontend is handwritten IIRC
I suppose what you're concerned with is the difference in how scripts vs files are parsed, and not in the grammar: https://github.com/JetBrains/kotlin/blob/master/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinParsing.java#L165-L185
i
The grammar itself should be correct for scripts as well, although it may contain some bugs. But the approach of parsing scripts yourself seems quite brave to me. Even more so - creating a PSI out of it. I do not believe that it is the easy way to achieve anything. And these are compiler internals which we’ll feel free to change and brake at any moment. So, I’d recommend to reconsider the approach. What are you actually trying to achieve?
g
If syntax highlighting is your only concern, I think it makes sense to use the provided grammars + the ANTLR API to walk the parse tree and do your syntax highlighting based on the token stream.
n
i changed the approach, i use he KtFile and KtScript that is already getting computed during script evaluation, i store them and try to use the PSI for syntax highlighting, but the display component i ry to use (richtextfx0 is annoying me, so i might switch tasks soon and go for easier things
g
I don't think it makes sense to do syntax highlighting based on the PSI
can you show an example of what you're actually trying to do?
n
well based on a pure AST (like kastree provides) its even harder because i lose the positions of tokens
g
kastree just looks like a simple wrapper over PSI elements
and the PSI tree is lossless
but again, you don't need a handle on the AST to do syntax highlighting