Skip to content

Commit

Permalink
add to raise an error when string is not terminated (#421)
Browse files Browse the repository at this point in the history
* add to raise an error when string is not terminated

* add to handle TokenError and CParsingError when run a rule test

* add tests for string parsing

* revert(4c0b1ae): add to handle TokenError and CParsingError when run a rule test

This reverts commit 4c0b1ae.

* revert(16f1f9e): add tests for string parsing

This reverts commit 16f1f9e.
  • Loading branch information
NiumXp committed Nov 15, 2023
1 parent eefad71 commit 41442cc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions norminette/lexer/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def read_file(filename):


class TokenError(Exception):
def __init__(self, pos):
self.msg = f"Error: Unrecognized token line {pos[0]}, col {pos[1]}"
def __init__(self, pos, message=None):
self.msg = message or f"Error: Unrecognized token line {pos[0]}, col {pos[1]}"

def __repr__(self):
return self.msg
Expand Down Expand Up @@ -114,6 +114,8 @@ def string(self):
self.__line_pos = 1
if self.peek_char() == '"':
break
if self.peek_char() == '\n':
raise TokenError(pos, f"String literal unterminated detected at line {pos[0]}")
self.pop_char()
else:
raise TokenError(pos)
Expand Down

0 comments on commit 41442cc

Please sign in to comment.