Skip to content

Conversation

@aaronjanse
Copy link
Member

Summary & Motivation

This adds helper methods for expecting a token, bumping only if it exists. Using these methods, I improved error handling in two ways:

  1. Expressions like { foo = 1 } // { bar = 2; } will now be parsed correctly, with the needed semicolon token simply missing (and appropriate error). Previously, this was parsed as one set with a large error node.
  2. Expressions like { foo = bar.; xyz = 1; } are parsed as missing an attractive path rather than having a large error node consuming most of the tokens.

Further context

Replaces #34. This PR is needed to implement autocomplete in rnix-lsp for expressions like foo.. I'm sure several other tools will find improved error handling helpful too.

@aaronjanse aaronjanse added the enhancement New feature or request label Jul 27, 2022
src/parser.rs Outdated
Comment on lines 335 to 342
match self.peek_any_or_missing(&[TOKEN_INTERPOL_START, TOKEN_STRING_START, TOKEN_IDENT]) {
Some(TOKEN_INTERPOL_START) => self.parse_dynamic(),
Some(TOKEN_STRING_START) => self.parse_string(),
Some(TOKEN_IDENT) => self.expect_ident(),
_ => {
break
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't love the repetition here, but I think it's not too bad?

@aaronjanse aaronjanse force-pushed the err-handling-take2 branch from 56ba050 to a556bb3 Compare July 27, 2022 05:32
@@ -0,0 +1 @@
{ foo = 1 bar = 2} // { xyz = 3; } No newline at end of file
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fun seeing how Github syntax highlighting, on the other hand, is not fault-tolerant

@aaronjanse
Copy link
Member Author

I now realize this duplicates work done by @oberblastmeister in #35

@aaronjanse aaronjanse closed this Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant