pris icon indicating copy to clipboard operation
pris copied to clipboard

Keep track of source locations in AST

Open ruuda opened this issue 7 years ago • 2 comments

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

ruuda avatar Apr 20 '17 12:04 ruuda

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?

tvincent2 avatar Oct 11 '19 22:10 tvincent2

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.

ruuda avatar Oct 12 '19 12:10 ruuda