fix some of the string stripping and added more examples
This commit is contained in:
parent
daf20c6e0b
commit
a4e60dd218
3 changed files with 14 additions and 7 deletions
|
@ -8,6 +8,9 @@ date = 2010-04-23
|
|||
time = 21:30:00
|
||||
"lol".yo = "tesaat"
|
||||
|
||||
[owner.name]
|
||||
first = "joao"
|
||||
|
||||
[[fruits]]
|
||||
name = "apple"
|
||||
|
||||
|
@ -29,3 +32,5 @@ name = "banana"
|
|||
|
||||
[[fruits.varieties]]
|
||||
name = "plantain"
|
||||
integers2 = [1,2,3]
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ def t_BOOL(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_]+\'))*"
|
||||
r"(([\w_]+)|(\"[\w_]+\"|\'[\w_]+\')\s*\.\s*([\w_]+|\"[\w_]+\"|\'[\w_]+\'))(\s*\.\s*([\w_]+|\"[\w_]+\"|\'[\w_]+\'))*"
|
||||
return t
|
||||
|
||||
|
||||
|
@ -93,6 +93,7 @@ def t_MLSTR(t):
|
|||
# STR needs to be the first one to catch
|
||||
def t_STR(t):
|
||||
r"(\"(?:[^\"\\]|\\.)+\")|(\'[^\']+\')"
|
||||
t.value = t.value.strip("\"'")
|
||||
return t
|
||||
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ def p_tomlEntries_object(p):
|
|||
def p_table_simple(p):
|
||||
"""table : '[' ID ']'"""
|
||||
p.parser.syntax_error = False
|
||||
headers = [s.strip('"\'') for s in p[2].split('.')]
|
||||
headers = p[2].split('.')
|
||||
temp = p.parser.root_dict
|
||||
for header in headers[:-1]:
|
||||
if header not in temp:
|
||||
|
@ -49,7 +49,7 @@ def p_table_simple(p):
|
|||
def p_table_array(p):
|
||||
"""table : '[' '[' ID ']' ']'"""
|
||||
p.parser.syntax_error = False
|
||||
headers = [s.strip('"\'') for s in p[3].split('.')]
|
||||
headers = p[3].split('.')
|
||||
temp = p.parser.root_dict
|
||||
for header in headers[:-1]:
|
||||
if header not in temp:
|
||||
|
@ -72,13 +72,13 @@ def p_object(p):
|
|||
| key '=' dict"""
|
||||
if p.parser.syntax_error:
|
||||
return
|
||||
headers = [s.strip('"\'') for s in p[1].split('.')]
|
||||
headers = p[1].split('.')
|
||||
temp = p.parser.current_header
|
||||
for header in headers[:-1]:
|
||||
if header not in temp:
|
||||
temp[header] = {}
|
||||
temp = temp[header]
|
||||
temp[headers[-1]] = p[3].strip('"\'')
|
||||
temp[headers[-1]] = p[3]
|
||||
|
||||
|
||||
def p_array_cont(p):
|
||||
|
@ -94,7 +94,8 @@ def p_array_empty(p):
|
|||
def p_aCont_multiple(p):
|
||||
"""aCont : aCont ',' aElem"""
|
||||
arr: list = p[1]
|
||||
p[0] = arr.append(p[3])
|
||||
arr.append(p[3])
|
||||
p[0] = arr
|
||||
|
||||
|
||||
def p_aCont_single(p):
|
||||
|
@ -134,7 +135,7 @@ def p_dictElem_object(p):
|
|||
"""dictElem : key '=' value
|
||||
| key '=' array
|
||||
| key '=' dict"""
|
||||
headers = [s.strip('"\'') for s in p[1].split('.')]
|
||||
headers = p[1].split('.')
|
||||
p[0] = {}
|
||||
temp = p[0]
|
||||
for header in headers[:-1]:
|
||||
|
|
Loading…
Add table
Reference in a new issue