ruuda / pris

A language for designing slides

Home Page:https://docs.ruuda.nl/pris/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keep track of source locations in AST

ruuda opened this issue · comments

To report at which location in the source file an error occurred, this information needs to be tracked in every AST node.

Hi!

I think a good first step would be to report the lines where lexical errors occur. I will try to implement that by adding the line number in the Lexer struct in lexer.rs so it can be used in errors. Then I will also add it to the Span struct in lexer.rs so it can be used later during the parsing.

What do you think about it?

Span is sufficient to track source code locations, it can be translated back into line numbers, and the lexer already reports errors in that way. The challenge is to add spans to AST nodes and keep them around, without them getting in the way everywhere. The first thing that comes to mind is to add a Span to every AST node, but that means having to update every match, so it is very invasive, and it also pollutes the matches with this span field that you usually don’t care about. I am not aware of an elegant solution, but I also haven’t researched or thought about this extensively yet.