diff options
| author | mryouse | 2022-06-05 03:34:46 +0000 |
|---|---|---|
| committer | mryouse | 2022-06-05 03:34:46 +0000 |
| commit | 4e92943c6026b9dd182802b3a2dac547fb84c7ee (patch) | |
| tree | 01e2f334441217af35a2baa055efb681acebb0d5 /lexer.py | |
| parent | 3899312e81d383d4900dc95b9d96faf1cc73db15 (diff) | |
bugfix: since :string can contain newline, count them correctly
Diffstat (limited to 'lexer.py')
| -rw-r--r-- | lexer.py | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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": |
