Skip to content

Commit

Permalink
Removed string-escaping to match the game's behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaumgarten committed Apr 12, 2022
1 parent 652bbd4 commit 382afdc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 31 deletions.
8 changes: 1 addition & 7 deletions examples/nolol/loops_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,5 @@ scripts:
cases:
- name: draw
outputs:
out: |
XXXXXX
X0000X
X0000X
X0000X
X0000X
XXXXXX
out: "XXXXXX\\nX0000X\\nX0000X\\nX0000X\\nX0000X\\nXXXXXX\\n"
out2: 5
23 changes: 1 addition & 22 deletions pkg/parser/ast/tokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,30 +313,9 @@ func (t *Tokenizer) getStringConstant() (*Token, int) {
if len(t.remaining) < 2 || t.remaining[0] != '"' {
return nil, 0
}
escaped := false

str := ""
for i, b := range t.remaining[1:] {
if b == '\\' {
escaped = true
continue
}
if escaped {
switch b {
case 'n':
str += "\n"
escaped = false
continue
case 't':
str += "\t"
escaped = false
continue
case '"':
str += "\""
escaped = false
continue
}
}

if b == '"' {
return t.newToken(TypeString, str), i + 2
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/parser/ast/tokenizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestTokenizer(t *testing.T) {
i++
a = 0 and 1
// comment 2
:var = "another\"test"
:var = "another--test"
:foo = (1+2.75)*3
:_=1
`
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestTokenizer(t *testing.T) {
Line: 9, Coloumn: 6, Type: Whitespace, Value: ' '
Line: 9, Coloumn: 7, Type: Symbol, Value: '='
Line: 9, Coloumn: 8, Type: Whitespace, Value: ' '
Line: 9, Coloumn: 9, Type: String, Value: 'another"test'
Line: 9, Coloumn: 9, Type: String, Value: 'another--test'
Line: 9, Coloumn: 24, Type: Newline
Line: 10, Coloumn: 1, Type: Whitespace, Value: ' '
Line: 10, Coloumn: 2, Type: ID, Value: ':foo'
Expand Down

0 comments on commit 382afdc

Please sign in to comment.