From 4e92943c6026b9dd182802b3a2dac547fb84c7ee Mon Sep 17 00:00:00 2001 From: mryouse Date: Sun, 5 Jun 2022 03:34:46 +0000 Subject: bugfix: since :string can contain newline, count them correctly --- lexer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lexer.py') diff --git a/lexer.py b/lexer.py index 1f963cc..c4f52d3 100644 --- a/lexer.py +++ b/lexer.py @@ -67,9 +67,10 @@ def lex(data): current += length # strings elif char == '"': - tok, length = get_string(data[current+1:], line) + tok, length, offset = get_string(data[current+1:], line) tokens.append(tok) current += length + line += offset # bools elif char == "#": tok, length = get_bool(data[current+1:], line) @@ -118,14 +119,17 @@ def get_number(data, line): def get_string(data, line): + offset = 0 counter = 0 string = "" while data[counter] != '"': + if data[counter] == "\n": + offset += 1 string += data[counter] counter += 1 if counter >= len(data): raise Exception("couldn't parse string") - return Token(TokenType.STRING, string, string, line), counter + 1 + return Token(TokenType.STRING, string, string, line), counter + 1, offset def get_bool(data, line): if len(data) >= 4 and data[:4] == "true": -- cgit v1.2.3