Skip to content

Commit

Permalink
Fixed #55
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborsch committed Apr 26, 2024
1 parent 300b2d6 commit d7f3ef8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion programs/tests/fixtures/comments/dots.rock
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ Burn it. (your_love = charFromCode⟨your_love⟩, i.e. space)
Your heart is a poison, (your_heart = the base for casting)

say your love,.:;
say your heart.
say your heart.

shout ";("
shout "what",,,.,.,., (?)
2 changes: 2 additions & 0 deletions programs/tests/fixtures/comments/dots.rock.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@

16
;(
what
Binary file modified rocky.jar
Binary file not shown.
16 changes: 14 additions & 2 deletions src/rockstar/parser/MultilineReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public Line readLine() throws IOException {
break;
}
}
while (!tokens.isEmpty()
&& tokens.get(tokens.size()-1).getValue().equals(",")) {
tokens.remove(tokens.size()-1);
}
return new Line(origLine.toString(), filename, startLnum, tokens);
}

Expand All @@ -73,7 +77,6 @@ private String readBuffer() throws IOException {
if (l != null) {
origLine.append(l);
lnum++;
l = l.replaceAll("[ .,;:!]+$", "").replaceAll("[ .,;:!]+\\(", " (");
}
return l;
}
Expand Down Expand Up @@ -123,6 +126,9 @@ private void processChar(char c) {
startToken();
break;
case ' ':
case ';':
case ':':
case '!':
case '\t':
case '\n':
case '\r':
Expand All @@ -138,7 +144,7 @@ private void processChar(char c) {
}
}
} else {
if (" \t\r\n".indexOf(c) >= 0) {
if (" .;:!\t\r\n".indexOf(c) >= 0) {
// terminal char
addToken(0);
} else if(",+-*/&".indexOf(c) >= 0) {
Expand Down Expand Up @@ -187,12 +193,18 @@ private void addToken(int offset) {
}
}
}
if (isInNumber && token.equals(".")) {
// a single dot is not a decimal number
skipThisToken = true;
}
if (! token.startsWith("\"")) {
// apos does not count in a non-string token
token = token.replaceAll("[']*", "");
}
if (token.equalsIgnoreCase("and")
&& !tokens.isEmpty()
&& ",".equals(tokens.get(tokens.size()-1).getValue())) {
// in case of ", and", the comma is skipped
skipThisToken = true;
}
if (! skipThisToken) {
Expand Down

0 comments on commit d7f3ef8

Please sign in to comment.