xbc: barevals do have spaces in them, dingus

current
Síle Ekaterin Liszka 2024-01-12 17:51:31 -08:00
parent 7d4b991f4a
commit 053b9188a8
Signed by: VulpineAmethyst
SSH Key Fingerprint: SHA256:VcHwQ6SUfi/p0Csfxe3SabX/TImWER0PhoJqkt+GlmE
1 changed files with 14 additions and 3 deletions

View File

@ -112,8 +112,8 @@ key_fragment = Word(alphas + nums + '_-')
key = DelimitedList(key_fragment, delim='.', combine=True) key = DelimitedList(key_fragment, delim='.', combine=True)
bareval = CharsNotIn('{}#=+:;,\n\'"') bareval = CharsNotIn('{}#=+:;,\n\'"')
strvals = QuotedString("'", multiline=True, unquote_results=True) strvals = QuotedString("'", multiline=True, unquote_results=False)
strvald = QuotedString('"', multiline=True, unquote_results=True) strvald = QuotedString('"', multiline=True, unquote_results=False)
value = bareval | strvald | strvals value = bareval | strvald | strvals
assign = Literal('=') assign = Literal('=')
@ -159,6 +159,11 @@ def lex(data):
tree = XBCParser.parseString(data).asList() tree = XBCParser.parseString(data).asList()
return tree return tree
def unquote(val):
if val[0] in '\'"' and val[0] == val[-1]:
return val[1:-1]
return val.strip()
def parse_block(key, seq): def parse_block(key, seq):
if isinstance(seq, list) and len(seq) == 1 and isinstance(seq[0], list): if isinstance(seq, list) and len(seq) == 1 and isinstance(seq[0], list):
seq = seq[0] seq = seq[0]
@ -200,6 +205,12 @@ def parse_block(key, seq):
else: else:
assign = value assign = value
if isinstance(assign, list):
for i in range(len(assign)):
assign[i] = unquote(assign[i])
else:
assign = unquote(assign)
if isinstance(assign, list) and len(assign) == 1: if isinstance(assign, list) and len(assign) == 1:
assign = assign[0] assign = assign[0]