-
Notifications
You must be signed in to change notification settings - Fork 51
Fixes a StackOverflow issue with the Lexer system. #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,11 @@ public bool MoveNext() | |
| { | ||
| case ' ': | ||
| case '\t': | ||
| while (offset < Source.Length && (Source.Span[offset] == ' ' || Source.Span[offset] == '\t')) | ||
| { | ||
| Advance(1); | ||
| } | ||
|
|
||
| return MoveNext(); | ||
| case '\n': | ||
| current = SyntaxToken.EndOfLine(position); | ||
|
|
@@ -110,16 +115,16 @@ public bool MoveNext() | |
| current = SyntaxToken.Addition(position); | ||
| return true; | ||
| case '-': | ||
| // comment | ||
| if (c2 == '-') | ||
| // handle comments iteratively | ||
| while (offset < span.Length && c2 == '-') | ||
| { | ||
| var pos = position; | ||
| Advance(1); | ||
| Advance(1); // consume first '-' | ||
|
|
||
| // block comment | ||
| if (span.Length > offset + 1 && span[offset] is '[' && span[offset + 1] is '[' or '=') | ||
| if (span.Length > offset + 1 && span[offset] == '[' && (span[offset + 1] == '[' || span[offset + 1] == '=')) | ||
| { | ||
| Advance(1); | ||
| Advance(1); // consume second '-' | ||
| var (_, _, isTerminated) = ReadUntilLongBracketEnd(ref span); | ||
| if (!isTerminated) | ||
| { | ||
|
|
@@ -131,13 +136,24 @@ public bool MoveNext() | |
| ReadUntilEOL(ref span, ref offset, out _); | ||
| } | ||
|
|
||
| return MoveNext(); | ||
| } | ||
| else | ||
| { | ||
| current = SyntaxToken.Subtraction(position); | ||
| return true; | ||
| // prepare for next iteration | ||
| if (offset < span.Length) | ||
| { | ||
| c2 = (offset + 1 < span.Length) ? span[offset + 1] : char.MinValue; | ||
| if (span[offset] != '-') break; // next char is not a comment, exit loop | ||
| } | ||
|
Comment on lines
119
to
144
|
||
| else | ||
| { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // after skipping comments, if we reached end, return false | ||
| if (offset >= span.Length) | ||
| return false; | ||
|
|
||
| current = SyntaxToken.Subtraction(position); // if single '-' remains | ||
| return true; | ||
|
Comment on lines
118
to
156
|
||
| case '*': | ||
| current = SyntaxToken.Multiplication(position); | ||
| return true; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline comments on the
Advance(1)calls are misleading. At this point the first'-'has already been consumed before theswitch, soAdvance(1)here consumes the second'-', and the subsequentAdvance(1)inside the block-comment branch consumes the'['that starts the long-bracket delimiter. Please update these comments to reflect what is actually being consumed to avoid future regressions.