Skip to content

Commit

Permalink
Merge pull request #6 from codemanyak/issue28
Browse files Browse the repository at this point in the history
Fixes ridencww#28 (update Parser.java)
  • Loading branch information
codemanyak committed Apr 15, 2024
2 parents 127ec80 + ad877d5 commit 0f12a2c
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,7 @@ public ParseMessage parse() {
inputTokens.push(read);

// Handle the case where an unterminated comment block consumes the entire program
// START KGU#1144 2024-04-10: Bugfix #28 With a line comment, we may tolerate EOF
//if (SymbolType.END.equals(read.getType()) && groupStack.size() > 0) {
if (SymbolType.END.equals(read.getType()) && groupStack.size() > 0
&& !(groupStack.size() == 1 && groupStack.peek().group.getEndingMode() == EndingMode.OPEN)) {
// END KGU#1144 2024-04-10
if (SymbolType.END.equals(read.getType()) && groupStack.size() > 0) {
// Runaway group
parseMessage = ParseMessage.GROUP_ERROR;
} else {
Expand All @@ -746,11 +742,7 @@ public ParseMessage parse() {
} else if (SymbolType.ERROR.equals(read.getType())) {
parseMessage = ParseMessage.LEXICAL_ERROR;
done = true;
// START KGU#1144 2024-04-10: Bugfix #28 With a line comment, we may tolerate EOF
//} else if (SymbolType.END.equals(read.getType()) && groupStack.size() > 0) {
} else if (SymbolType.END.equals(read.getType()) && groupStack.size() > 0
&& !(groupStack.size() == 1 && groupStack.peek().group.getEndingMode() == EndingMode.OPEN)) {
// END KGU #1144 2024-04-10
} else if (SymbolType.END.equals(read.getType()) && groupStack.size() > 0) {
// Runaway group
parseMessage = ParseMessage.GROUP_ERROR;
done = true;
Expand Down Expand Up @@ -973,7 +965,21 @@ protected Token produceToken() {
}
} else if (read.getType().equals(SymbolType.END)) {
// EOF always stops the loop. The caller method (parse) can flag a runaway group error.
token = read;
// START KGU#1144 2024-04-15: Bugfix #28 Save a line comment at end of file
//token = read;
// An open group (e.g. line comment) expecting just some NOISE, however, should be preserved
Token grp = null;
if (groupStack.size() == 1
&& (grp = groupStack.peek()).getGroup().getEndingMode() == EndingMode.OPEN
&& grp.getGroup().getEnd().getType().equals(SymbolType.NOISE)) {
groupStack.pop();
grp.setSymbol(grp.getGroup().getContainer());
token = grp;
}
else {
token = read;
}
// END KGU#1144 2024-04-15
done = true;
} else {
// We are in a group, Append to the Token on the top of the stack.
Expand Down

0 comments on commit 0f12a2c

Please sign in to comment.