Repository navigation
A line comment may end the input (#1039) - #1049
Merged
Merged
Conversation
`COMMENT`'s `//` alternative required a newline after it, so a comment on the last line never matched and its first `/` reached the parser as an operator: `x + 1 // done` was `extraneous input '/'` while `x + 1 /* done */` was `x + 1`. The end of the input is where a comment is most likely to be written -- the last line of a file, or a single-line string handed to `FromString` -- and the block form carried no such condition, so this was a missing optional rather than a decision. The newline is now optional. Regenerated with the vendored ANTLR 4.13.1 and the post-processor that makes the generated classes internal, per `Docs/Contributing/ImproveParser.md`. Only the lexer changes: the listener and parser diffs were the accessibility churn alone and come back byte-identical. `"//"` on its own is still an error, and its reported position moves from `line 1:0` to `line 1:2`. That is the convention the neighbouring rows already follow -- `" "` is `line 1:2` and `"/**/"` is `line 1:4`, both pointing at the end of the skipped text -- so it stops being the one row that pointed at a character the lexer was supposed to have consumed. `SyntaxDocumentedTest` pinned the old behaviour with the issue against it; it now pins the fix across five spellings, plus a case for a comment being the whole input, which is a parse error because nothing is left rather than because the comment failed to match. Part of #746 item 8. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bjumi5K7fg8yx6UK1mZTQd
…-end-of-input # Conflicts: # BREAKING-CHANGES.md
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1039.
COMMENTinAngouriMath.gwasso the
//alternative only matched when a newline followed. A comment on the last line nevermatched at all and its first
/reached the parser as an operator. The end of the input is where acomment is most likely to be written — the last line of a file, or a single-line string handed to
FromString— and the block form carries no such condition, so this reads as a missing optionalrather than a decision.
Measured on a build of this branch:
x + 1 // doneUnhandledParseException: extraneous input '/'x + 1x + 1 //x + 1x + 1 // a // bx + 1x + 1 // done\nx + 1x + 1x + 1 // done\r\nx + 1x + 1x + 1 /* done */x + 1x + 1x + // c\n 1x + 1x + 1x / 1x / 1x / 1// nothingon its own is still a parse error — the comment is skipped and an empty input is not anexpression, which is the same reason
""is an error.Regeneration
Per
Docs/Contributing/ImproveParser.md: the vendoredantlr-4.13.1-complete.jar, then theAntlrPostProcessorReplacePublicWithInternalstep that makes the generated classes internal. Worthnoting for review — only the lexer changes. Regeneration first rewrites
AngouriMathListener.cs,AngouriMathBaseListener.csandAngouriMathParser.cswithpublicin place ofinternal, and thepost-processor puts them back byte-identical, so the diff is the grammar,
AngouriMathLexer.csandAngouriMathLexer.interpand nothing else.One behaviour change beyond the fix
"//"on its own is still an error, and its reported position moves fromline 1:0toline 1:2.That is the convention the neighbouring
FromStringTestrows already follow —" "isline 1:2,"/**/"isline 1:4, both pointing at the end of the skipped text — so//stops being the onerow that pointed at a character the lexer was meant to have consumed. The row is updated with a
comment saying why.
Tests
SyntaxDocumentedTest.ALineCommentNeedsItsNewlinepinned the old behaviour, with #1039 linkedagainst it. It becomes
ACommentMayEndTheInputover six spellings, plusACommentIsNotAnExpressionOnItsOwn.Docs/Usage/Syntax.mdsaid the newline was required and nowsays it is not, keeping the issue reference for anyone reading an older version.
Suite: 8107 passed, 0 failed, 14 skipped.
Part of #746 item 8 — this was found while deriving what the grammar accepts.