// Empty lines are OK.
this.currentLine = this.currentLine.nextLine;
this.currentIndex = this.currentLine.offset; <----
this.currentLine = this.currentLine.nextLine;
if ( this.currentLine.content == null ) <---
{
throw this.parseException( "No closing ] found" );
}
Yes, it's just for the "abrupt line termination" (or just "there's not as many characters as we expect")In what circumstances do you expect to see IndexOutOfBounds? That actually only occurs in the case of "line abruptly terminates after \x" and similar, which will never actually trigger for the octal handling, as far as I can tell.
?which will never actually trigger for the octal handling, as far as I can tell.
It's not "harm", per se, but it's redundant logic that needs to be altered in the future to accommodate one of the incoming changes, meaning the change would need to be applied twice, while there's no need for it.But beyond that: is there any harm in keeping parsePostCall around?
Wouldn't anonymous functions still just go in parseValue? Just like how parseInvoke and parseCall are two different methods? it would just be "parseAnonymousFunction", meaning it would still be followed by parseValue's post-value handling?Right now, that relies on parseCall / parseInvoke always being invoked in a certain place in parseValue. If we wanted to change this in the future (say, to add support for anonymous functions), then that assumption would break.
Huh, I learned a new meaning to the word "outstanding"...Are there any other outstanding patches other than the two in this post? (I'll get to those momentarily.)
Maybe, maybe not.Wouldn't anonymous functions still just go in parseValue?
int() makeClosure(int x) {
return int() { return x; };
}
makeClosure(5)();
I have two diffs if anyone wants to take a look:
- ParserWithManyTests.patch is basically your changes, plus my tweaks, diffed against head.
- ParserPatch.patch is basically the diff of my tweaks vs your changes. Mostly minor changes in Parser (wording, formatting, the occasional logic change). And... 48 test cases, by my count (plus the ones you had provided earlier but commented out. And one new one that's commented out because it doesn't work).
--- C:/Users/Frederic/Desktop/KoLmafia-workspace2/kolmafia/src/net/sourceforge/kolmafia/textui/Parser.java lun. août 23 21:29:44 2021
+++ C:/Users/Frederic/Desktop/KoLmafia-workspace/kolmafia/src/net/sourceforge/kolmafia/textui/Parser.java lun. août 23 21:19:24 2021
@@ -1358,4 +1357,0 @@ public class Parser
- if ( this.currentToken().equals( ";" ) )
- {
- throw this.parseException( "Missing index token" );
- }
@@ -1403 +1399 @@ public class Parser
- else
+ else if ( this.parseIdentifier( this.currentToken().content ) )
@@ -1436,0 +1433,4 @@ public class Parser
+ else
+ {
+ throw this.parseException( "Missing index token" );
+ }
if (x)
{
[...]
break;
}
if (y)
{
[...]
break;
}
[...]
if (x)
{
[...]
}
else if (y)
{
[...]
}
else
{
[...]
}
[...]
if ( somethingBad )
{
throw errorXYZ;
}
doSomething();
doSomethingElse();
[...]
if ( !somethingBad )
{
doSomething();
}
else
{
throw errorXYZ;
}
doSomethingElse();
[...]
if ( !somethingBad )
{
doSomething();
}
else
{
saveThatThereWasErrorXYZ();
doAnAlternativeThing();
}
doSomethingElse();
This should be the end of the "first" major step for the language server. Onto the second and third.
Second and third are:
- Always reach the end of the file.
I.e. even if there's an error, continue parsing while trying to get our bearings back.