From c908f7211a43e6adda722a41594b4e2fcd9e2f8b Mon Sep 17 00:00:00 2001 From: tiago Date: Wed, 17 May 2023 11:57:19 +0100 Subject: [PATCH] [PARSER] structure done, and some notes --- src/notes.md | 1 + src/parser.py | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/parser.py diff --git a/src/notes.md b/src/notes.md index 626dd87..dfe3c23 100644 --- a/src/notes.md +++ b/src/notes.md @@ -5,6 +5,7 @@ - exponent floats and ints - tirar as aspas das strings, com o match object (4.18 Internal lexer state https://www.dabeaz.com/ply/ply.html#ply_nn20) - mudar ids para poderem existir keys com o formato yessir."olympus".2 + - resolver problema de quando uma key/id comecar com "fdsa".qualquercoisa nao ser apanhado como uma srting (talvez um lookup negativo a ver se tem um . a seguir as aspas) - inlinetables nao podem ter espacos no meio a menos que um dos values o permita (exemplo : multiline strings) diff --git a/src/parser.py b/src/parser.py new file mode 100644 index 0000000..7220d7d --- /dev/null +++ b/src/parser.py @@ -0,0 +1,122 @@ +import ply.yacc as yacc +from lexer import tokens + + +def p_toml(p): + "toml : content" + +def p_content_multi(p): + "content : content tomlEntries" + +def p_content_single(p): + "content : tomlEntries" + +def p_tomlEntries_table(p): + "tomlEntries : table" + + +def p_tomlEntries_object(p): + "tomlEntries : object" + + +def p_table_simple(p): + "table : '[' ID ']'" + +def p_table_array(p): + "table : '[' '[' ID ']' ']'" + +def p_object_value(p): + "object : key '=' value" + +def p_object_array(p): + "object : key '=' array" + + +def p_object_dict(p): + "object : key '=' dict" + +def p_array_cont(p): + "array : '[' aCont ']'" + +def p_array_empty(p): + "array : '[' ']'" + +def p_aCont_multiple(p): + "aCont : aCont ',' aElem" + +def p_aCont_single(p): + "aCont : aElem" + + +def p_aElem_value(p): + "aElem : value" + +def p_aElem_dict(p): + "aElem : dict" + +def p_aElem_array(p): + "aElem : array" + + +def p_dict_cont(p): + "dict : '{' dictCont '}'" + +def p_dict_empty(p): + "dict : '{' '}'" + +def p_dictCont_multiple(p): + "dictCont : dictCont ',' dictElem" + + +def p_dictCont_single(p): + "dictCont : dictElem" + +def p_dictElem_object(p): + "dictElem : object" + +def p_key_id(p): + "key : ID" + +def p_key_str(p): + "key : STR" + +def p_key_float(p): + "key : FLOAT" + +def p_key_int(p): + "key : INT" + +def p_value_str(p): + "value : STR" + +def p_value_date(p): + "value : DATE" + +def p_value_datetime(p): + "value : DATETIME" + +def p_value_int(p): + "value : INT" + +def p_value_float(p): + "value : FLOAT" + +def p_value_hex(p): + "value : HEX" + +def p_value_bin(p): + "value : BIN" + +def p_value_oct(p): + "value : OCT" + +def p_value_inf(p): + "value : INF" + +def p_value_nan(p): + "value : NAN" + + + + +