-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fixes, improvements, optimization & refactoring before parser gen…
…eration (#288) * Fix bad float conformation error message + add coverage * Remove duplicit information from int/float conversion errors Both strconv.ParseInt and strconv.ParseFloat already report the input. The word invalid isn't always true - it could also just be out of range. The type is contained within the Parse* function being called. So as the extra context added nothing useful, I decided to remove it altogether, making things much easier for the generated parser. * Fix possible panic when optional groups are used within a capture If an optional group within a capture matches no input (either because of an unexpected token or EOF), obtaining partial AST can cause `setField` to be called with no tokens, causing a panic. Fixed by not doing anything. * Improve mismatch error message for negation & negative lookahead group It didn't properly escape the token, the error would be malformed if the token contained single quotes. It also used a custom error instead of `UnexpectedTokenError` for no good reason. * Improve the choice of error reporting after optional branches The last error in the added test explains the difference. Without this change, it would have been `1:15: unexpected token "(" (expected ";")`, which would be very confusing as '(' was actually allowed after the class name. After this change, it's `1:20: unexpected token ")" (expected <ident>)`, pointing out the real problem - that an identifier was expected after the comma. * Optimize string field accumulation to do fewer allocations * Optimize finding case insensitive tokens to be done at parser construction Optimize finding case insensitive tokens to be done at parser construction Doing it before each parsing was unnecessary. One could worry the results would be different if `ParseFromLexer` was called with a different lexer than used to build the grammar, but then case-insentive tokens would be the least of our problems - literal & reference would check agaist the wrong TokenType. * Avoid an allocation in newParseContext Not very significant for the reflective parser, more significant for the generated one. * Include explicit disjunction in the union node The generated parser would be the second place that would construct a temporary disjunction in the implementation, I think it might as well contain the disjunction directly. * Remove unused optional and repetition grammar nodes They could never be created and were private, so this certainly can't break anything. * Change the receiver name of lookaheadGroup from n to l It was n probably because I copied it from negation and assumed n was for node. Naming it l is more consistent with the convention for other nodes. * Keep track of the number of usages of a strct node * Allow specifying UnexpectedTokenError expected sequence as a string Co-authored-by: Peter Dolak <peter.dolak@exponea.com> Co-authored-by: Peter Dolak <peter.dolak@bloomreach.com>
- Loading branch information
1 parent
5adbb7c
commit 1f05da7
Showing
9 changed files
with
128 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.