From 3ccb736eb9e18f68526008a42175e1af269fdf82 Mon Sep 17 00:00:00 2001 From: afonsofrancof Date: Wed, 24 May 2023 16:08:30 +0100 Subject: [PATCH] fix string id e tal --- .gitignore | 1 + src/example.toml | 2 +- src/lexer.py | 27 ++++++++++++++------------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index c18dd8d..27d1807 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__/ +Session.vim diff --git a/src/example.toml b/src/example.toml index 8c07ef4..581a235 100644 --- a/src/example.toml +++ b/src/example.toml @@ -6,4 +6,4 @@ othername = """Tom \"The killer\" or \"yo\" or 'you' Preston-Werner""" date = 2010-04-23 time = 21:30:00 -lol."yo" = "test" +"lol".yo = "test" diff --git a/src/lexer.py b/src/lexer.py index 19d41a9..cb6e149 100644 --- a/src/lexer.py +++ b/src/lexer.py @@ -15,17 +15,9 @@ tokens = [ "INF", "NAN", "COMMENT", -] + ] -def t_MLSTR(t): - r"(\"\"\"(?:[^\"\\]|\\.)+\"\"\")|(\'\'\'(?:[^\'\\]|\\.)+\'\'\')" - return t - -# STR needs to be the first one to catch -def t_STR(t): - r"(\"(?:[^\"\\]|\\.)+\")|(\'[^\']+\')" - return t # needs to check if datetime is valid @@ -45,6 +37,19 @@ def t_TIME(t): r"\d{2}:\d{2}:\d{2}(\.\d{1,6})?" return t +# ID needs to be the last so it doesnt catch everything (literally) +def t_ID(t): + r"(([\w_]+)|(\"[\w_]+\"\.|\'[\w_]+\'\.)([\w_]+|\"[\w_]+\"|\'[\w_]+\'))(\.([\w_]+|\"[\w_]+\"|\'[\w_]+\'))*" + return t + +def t_MLSTR(t): + r"(\"\"\"(?:[^\"\\]|\\.)+\"\"\")|(\'\'\'(?:[^\'\\]|\\.)+\'\'\')" + return t + +# STR needs to be the first one to catch +def t_STR(t): + r"(?