zom-lang / zom

Zom is a Ahead Of Time compiled system programming language.
Other
4 stars 2 forks source link

Parsing Error need to point to the code #4

Closed Larsouille25 closed 1 year ago

Larsouille25 commented 1 year ago

Is your feature request related to a problem? Please describe. Add error that clearly point to the code.

Describe the solution you'd like

After that the token stream has the location in the code.

Larsouille25 commented 1 year ago

The new struct shouldn't pass a Position to the new struct but instead a much lighter one without the filename and filetext parameters. But instead put those parameters in the new struct.

Larsouille25 commented 1 year ago

I'm definitely not happy with the result, I think I need to found a new implementation, it's too bulky. I've two ideas how to do it more efficiently :

  1. Create a new method (or function) to the lexer that retokenize the text and return the position of the token that as issue with. The prototype looks like that get_pos_token(&mut self, tok_idx: usize) -> Option<(Position, Position)> with the first Position be the start and the second, the end.
  2. Or a function, with a vec of tokens recreate the text an then, because it recreates the text, it knows where the token was and return a tuple of Position (like the first idea) with the text that it recreates and the filename doesn't change. Both function / method will only be call when there is an error.
Larsouille25 commented 1 year ago

This is done.

Larsouille25 commented 1 year ago

The "reverse lexer" is just dumb, we can instead store a span in tokens, and in the AST