ruuda / pris

A language for designing slides
https://docs.ruuda.nl/pris/
GNU General Public License v3.0
116 stars 5 forks source link

Keep track of source locations in AST #4

Open ruuda opened 7 years ago

ruuda commented 7 years ago

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

tvincent2 commented 5 years ago

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?

ruuda commented 5 years ago

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.