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
|
time = 21:30:00
|
||||||
"lol".yo = "tesaat"
|
"lol".yo = "tesaat"
|
||||||
|
|
||||||
|
[owner.name]
|
||||||
|
first = "joao"
|
||||||
|
|
||||||
[[fruits]]
|
[[fruits]]
|
||||||
name = "apple"
|
name = "apple"
|
||||||
|
|
||||||
|
@ -29,3 +32,5 @@ name = "banana"
|
||||||
|
|
||||||
[[fruits.varieties]]
|
[[fruits.varieties]]
|
||||||
name = "plantain"
|
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)
|
# ID needs to be the last so it doesnt catch everything (literally)
|
||||||
def t_ID(t):
|
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
|
return t
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,6 +93,7 @@ def t_MLSTR(t):
|
||||||
# STR needs to be the first one to catch
|
# STR needs to be the first one to catch
|
||||||
def t_STR(t):
|
def t_STR(t):
|
||||||
r"(\"(?:[^\"\\]|\\.)+\")|(\'[^\']+\')"
|
r"(\"(?:[^\"\\]|\\.)+\")|(\'[^\']+\')"
|
||||||
|
t.value = t.value.strip("\"'")
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ def p_tomlEntries_object(p):
|
||||||
def p_table_simple(p):
|
def p_table_simple(p):
|
||||||
"""table : '[' ID ']'"""
|
"""table : '[' ID ']'"""
|
||||||
p.parser.syntax_error = False
|
p.parser.syntax_error = False
|
||||||
headers = [s.strip('"\'') for s in p[2].split('.')]
|
headers = p[2].split('.')
|
||||||
temp = p.parser.root_dict
|
temp = p.parser.root_dict
|
||||||
for header in headers[:-1]:
|
for header in headers[:-1]:
|
||||||
if header not in temp:
|
if header not in temp:
|
||||||
|
@ -49,7 +49,7 @@ def p_table_simple(p):
|
||||||
def p_table_array(p):
|
def p_table_array(p):
|
||||||
"""table : '[' '[' ID ']' ']'"""
|
"""table : '[' '[' ID ']' ']'"""
|
||||||
p.parser.syntax_error = False
|
p.parser.syntax_error = False
|
||||||
headers = [s.strip('"\'') for s in p[3].split('.')]
|
headers = p[3].split('.')
|
||||||
temp = p.parser.root_dict
|
temp = p.parser.root_dict
|
||||||
for header in headers[:-1]:
|
for header in headers[:-1]:
|
||||||
if header not in temp:
|
if header not in temp:
|
||||||
|
@ -72,13 +72,13 @@ def p_object(p):
|
||||||
| key '=' dict"""
|
| key '=' dict"""
|
||||||
if p.parser.syntax_error:
|
if p.parser.syntax_error:
|
||||||
return
|
return
|
||||||
headers = [s.strip('"\'') for s in p[1].split('.')]
|
headers = p[1].split('.')
|
||||||
temp = p.parser.current_header
|
temp = p.parser.current_header
|
||||||
for header in headers[:-1]:
|
for header in headers[:-1]:
|
||||||
if header not in temp:
|
if header not in temp:
|
||||||
temp[header] = {}
|
temp[header] = {}
|
||||||
temp = temp[header]
|
temp = temp[header]
|
||||||
temp[headers[-1]] = p[3].strip('"\'')
|
temp[headers[-1]] = p[3]
|
||||||
|
|
||||||
|
|
||||||
def p_array_cont(p):
|
def p_array_cont(p):
|
||||||
|
@ -94,7 +94,8 @@ def p_array_empty(p):
|
||||||
def p_aCont_multiple(p):
|
def p_aCont_multiple(p):
|
||||||
"""aCont : aCont ',' aElem"""
|
"""aCont : aCont ',' aElem"""
|
||||||
arr: list = p[1]
|
arr: list = p[1]
|
||||||
p[0] = arr.append(p[3])
|
arr.append(p[3])
|
||||||
|
p[0] = arr
|
||||||
|
|
||||||
|
|
||||||
def p_aCont_single(p):
|
def p_aCont_single(p):
|
||||||
|
@ -134,7 +135,7 @@ def p_dictElem_object(p):
|
||||||
"""dictElem : key '=' value
|
"""dictElem : key '=' value
|
||||||
| key '=' array
|
| key '=' array
|
||||||
| key '=' dict"""
|
| key '=' dict"""
|
||||||
headers = [s.strip('"\'') for s in p[1].split('.')]
|
headers = p[1].split('.')
|
||||||
p[0] = {}
|
p[0] = {}
|
||||||
temp = p[0]
|
temp = p[0]
|
||||||
for header in headers[:-1]:
|
for header in headers[:-1]:
|
||||||
|
|
Loading…
Add table
Reference in a new issue