[PARSER] structure done, and some notes

This commit is contained in:
Tiago Sousa 2023-05-17 11:57:19 +01:00
parent db9411d0d0
commit c908f7211a
2 changed files with 123 additions and 0 deletions

View file

@ -5,6 +5,7 @@
- exponent floats and ints - 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) - 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 - 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) - inlinetables nao podem ter espacos no meio a menos que um dos values o permita (exemplo : multiline strings)

122
src/parser.py Normal file
View file

@ -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"