Open pherrymason opened 3 months ago
You can look at --test
which already prints out to a known format.
Here is an example output when running code with a semantic error:
Error|debugstuff.c3|9|'foo' could not be found, did you spell it right?
Great, for the errors that might work. Will try it and come with any feedback.
Any updates?
Yes! I'm missing the character position where the error is happening. See example:
Running c3c build
gives both line and character:
➜ test-c3 git:(main) ✗ c3c build
3: import app;
4:
5: fn void main() {
6: io::prin
^^^^
(/xxx/test-c3/src/main.c3:6:9) Error: Expected a type here.
Running with --test
:
➜ test-c3 git:(main) ✗ c3c build --test
Error|main.c3|6|Expected a type here. // <-- here I only get the line, I would need the character too
➜ test-c3 git:(main) ✗
Also, totally unrelated, but I cannot make the --path
argument of c3c build to work, it complains the folder not containing a project.json file.
Can you file the --path as a bug, and then file the extension of test as an enhancement request? It's easily fixed, I just need to track it to do it when I have time.
It would also help a lot if file would contain its path. I'm wondering if a relative to the root of the project would suffice. What do you think? Do you want me to open a ticket for it?
Anything else we need from this one?
The errors parts is solved. However, the full AST generation would be really useful for easier and better code analysis.
What kind of information would you want for that? There is a lot of info...
Ideally, position ranges together with the represented string + node type. But sincerely this can wait, I'm sure there are other more important stuff to be resolved or improved!
Let me give you some more context. For the LSP I'm currently using Treesitter's parser to get a CST (context syntax tree), this gives me structured info about the source code, but it is not a fully AST (It has too many details about the sourcecode itself that I don't need). Having an AST would simplify the structure I need to iterate and would allow me to improve some analysis I do in the LSP.
I'm currently trying to convert the CST to an AST in the LSP itself, that's why I said there is no urge in having this be solved by c3c
itself. I even still need to validate my assumptions working with an AST.
However, if validated, in the long term is not very sustainable to rely on the conversion of the treesitter's CST to AST, as any modification on the treesitter's grammar will require to adapt the conversion code, and that will be very tedious.
The c3c
beeing able to emit a full AST of the project would allow to evolve together with c3c
itself automatically, and avoid breaks every time treesitter grammar is updated.
Context: https://discord.com/channels/650345951868747808/830497607998242884/1253238870212874260
We need to define the output format of these two possible outputs
Output AST of source
Currently,
-P
argument returns only (If I'm not mistaken) declared symbols and is lacking some useful information to be able to cross it with original source code.Points of improvement:
int a = call(arg1,arg2,arg3);
Every symbol should have its position ranges attached:Posible example of ast tree:
Semantic Errors
Proposal: