Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions parser/lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,17 @@ func (l *lexer) scanString(quote rune) (n int) {
}
return
}

func (l *lexer) scanRawString(quote rune) (n int) {
ch := l.next() // read character after back tick
for ch != quote {
if ch == eof {
l.error("literal not terminated")
return
}
ch = l.next()
n++
}
l.emitValue(String, l.input[l.start+1:l.end-1])
return
}
13 changes: 13 additions & 0 deletions parser/lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ func TestLex(t *testing.T) {
{Kind: EOF},
},
},
{
"`backtick` `hello\u263Aworld` `hello\n\tworld` `hello\"world'` `\xC3\xBF\u263A\U000003A8` `❤️`",
[]Token{
{Kind: String, Value: `backtick`},
{Kind: String, Value: `hello☺world`},
{Kind: String, Value: `hello
world`},
{Kind: String, Value: `hello"world'`},
{Kind: String, Value: `ÿ☺Ψ`},
{Kind: String, Value: "❤️"},
{Kind: EOF},
},
},
{
"a and orb().val #.",
[]Token{
Expand Down
2 changes: 2 additions & 0 deletions parser/lexer/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func root(l *lexer) stateFn {
l.error("%v", err)
}
l.emitValue(String, str)
case r == '`':
l.scanRawString(r)
case '0' <= r && r <= '9':
l.backup()
return number
Expand Down
5 changes: 5 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func TestParse(t *testing.T) {
`"str"`,
&StringNode{Value: "str"},
},
{
"`hello\nworld`",
&StringNode{Value: `hello
world`},
},
{
"3",
&IntegerNode{Value: 3},
Expand Down