From 3297f6671e2d02b34117cce204fad36ddf8f6071 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 23 Feb 2024 01:08:58 -0500 Subject: [PATCH] Lexer skips over zero runes now --- lexer/lexer.go | 17 +++++++++++++---- parser/meta/parser_test.go | 13 ++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lexer/lexer.go b/lexer/lexer.go index df8f6b9..8d3734c 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -5,6 +5,7 @@ import "io" import "fmt" import "bufio" import "unicode" +import "unicode/utf8" import "git.tebibyte.media/fspl/fspl/errors" // TokenKind is an enumeration of all tokens the FSPL compiler recognizes. @@ -134,7 +135,8 @@ type fsplLexer struct { filename string lineScanner *bufio.Scanner rune rune - runeLine []rune + line string + lineFood string offset int row int @@ -314,10 +316,11 @@ func (this *fsplLexer) nextInternal () (token Token, err error) { } func (this *fsplLexer) nextRune () error { - if this.column >= len(this.runeLine) { + if this.lineFood == "" { ok := this.lineScanner.Scan() if ok { - this.runeLine = []rune(this.lineScanner.Text()) + this.line = this.lineScanner.Text() + this.lineFood = this.line this.rune = '\n' this.column = 0 this.row ++ @@ -331,7 +334,13 @@ func (this *fsplLexer) nextRune () error { } } } else { - this.rune = this.runeLine[this.column] + var ch rune + var size int + for ch == 0 && this.lineFood != "" { + ch, size = utf8.DecodeRuneInString(this.lineFood) + this.lineFood = this.lineFood[size:] + } + this.rune = ch this.column ++ } diff --git a/parser/meta/parser_test.go b/parser/meta/parser_test.go index cad0fde..fff8fd5 100644 --- a/parser/meta/parser_test.go +++ b/parser/meta/parser_test.go @@ -9,7 +9,8 @@ testString (test, + 'io' + '../io' customIo`, // input -`'5a8353f8cad84604be6029a2575996bc' +` +'5a8353f8cad84604be6029a2575996bc' + 'io' + '../io' customIo `) @@ -27,3 +28,13 @@ testString (test, + 'io' + '../io' customIo `) } + +func TestOnlyUUID (test *testing.T) { +testString (test, +// correct +`'5a8353f8-cad8-4604-be60-29a2575996bc'`, +// input +` +'5a8353f8cad84604be6029a2575996bc' +`) +}