Add exception handling for date parsing in lexer

This commit is contained in:
Bananymous 2024-03-04 02:01:19 +02:00
parent 3ae6068215
commit cb4c194420
1 changed files with 5 additions and 1 deletions

View File

@ -76,7 +76,11 @@ def t_STRING(t):
def t_DATE_LITERAL(t): def t_DATE_LITERAL(t):
r'\d{4}-\d{2}-\d{2}' r'\d{4}-\d{2}-\d{2}'
t.value = datetime.date.fromisoformat(t.value) try:
t.value = datetime.date.fromisoformat(t.value)
except:
print(f'Invalid date \'{t.value}\' at line {t.lexer.lineno}')
raise SystemExit
return t return t
def t_INT_LITERAL(t): def t_INT_LITERAL(t):