From 4d947531a76e5f38cee9dc81b18506a68fcafc5d Mon Sep 17 00:00:00 2001 From: kmichaelk <130953568+kmichaelk@users.noreply.github.com> Date: Mon, 23 Sep 2024 10:31:35 +0300 Subject: [PATCH] Fix parsing of multiline string literals --- ttcn3/syntax/scanner.go | 1 - ttcn3/syntax/scanner_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/ttcn3/syntax/scanner.go b/ttcn3/syntax/scanner.go index 9cef1dd3..37086f86 100644 --- a/ttcn3/syntax/scanner.go +++ b/ttcn3/syntax/scanner.go @@ -254,7 +254,6 @@ func (s *Scanner) scanString() Kind { switch ch := s.src[s.pos]; ch { case '\n', '\v', '\f': s.lines = append(s.lines, s.pos+1) - s.pos++ case '\\': s.pos++ case '"': diff --git a/ttcn3/syntax/scanner_test.go b/ttcn3/syntax/scanner_test.go index 578fb626..04ae5397 100644 --- a/ttcn3/syntax/scanner_test.go +++ b/ttcn3/syntax/scanner_test.go @@ -23,6 +23,39 @@ func TestTokenize(t *testing.T) { `COMMENT "//"`, `EOF`, }}, + {`"str" + `, []string{ + `STRING "\"str\""`, + `EOF`, + }}, + {`"multiline +str" +`, []string{ + `STRING "\"multiline\nstr\""`, + `EOF`, + }}, + {`" +multiline +str" +`, []string{ + `STRING "\"\nmultiline\nstr\""`, + `EOF`, + }}, + {`"multiline +str +" +`, []string{ + `STRING "\"multiline\nstr\n\""`, + `EOF`, + }}, + {`" +multiline +str +" +`, []string{ + `STRING "\"\nmultiline\nstr\n\""`, + `EOF`, + }}, } for _, test := range tests { root := Tokenize([]byte(test.input))