mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 01:52:56 +01:00
StringTree: Respect quoted quotes
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
4a200c8851
commit
3d93d534db
3 changed files with 17 additions and 11 deletions
|
|
@ -59,7 +59,7 @@ class CmdBeautify(TrimSourceCmd):
|
||||||
r = ''
|
r = ''
|
||||||
indent = args.indent_assignments
|
indent = args.indent_assignments
|
||||||
for line in contents.splitlines(True):
|
for line in contents.splitlines(True):
|
||||||
m = re.match(r'^ *([a-zA-Z_][a-zA-Z0-9_]*)\s*([?+]*)(=)\s*(.*)', line)
|
m = re.match(r'^ *([a-zA-Z_][a-zA-Z0-9_]*)\s*([?+:]*)(=)\s*(.*)', line)
|
||||||
if m is None:
|
if m is None:
|
||||||
r += line
|
r += line
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,11 @@ class StringTree: # export
|
||||||
l = len(components)
|
l = len(components)
|
||||||
if len(path) == 0 or l == 0:
|
if len(path) == 0 or l == 0:
|
||||||
assert self.content is None
|
assert self.content is None
|
||||||
self.content = cleanup_string(content)
|
#self.content = cleanup_string(content)
|
||||||
|
self.content = content
|
||||||
slog(DEBUG, " -- content = >" + str(content) + "<, self.content = >" + str(self.content) + "<")
|
slog(DEBUG, " -- content = >" + str(content) + "<, self.content = >" + str(self.content) + "<")
|
||||||
|
#assert(content != "'antlr_doesnt_understand_vertical_tab'")
|
||||||
|
assert(content != '"[a-zA-Z0-9+_*/-]"')
|
||||||
#self.children[content] = StringTree(None, content)
|
#self.children[content] = StringTree(None, content)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
@ -89,10 +92,9 @@ class StringTree: # export
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
return self.__set(key, value)
|
return self.__set(key, value)
|
||||||
|
|
||||||
def __dump(self, prio, indent=0, caller=None, *args):
|
def __dump(self, prio, indent=0, **kwargs):
|
||||||
if caller is None:
|
caller = kwargs['caller'] if 'caller' in kwargs.keys() else get_caller_pos(1)
|
||||||
caller = get_caller_pos(1)
|
slog(prio, '|' + (' ' * indent) + str(self.content), caller=caller)
|
||||||
slog(prio, (' ' * indent) + str(self.content), caller=caller)
|
|
||||||
indent += 2
|
indent += 2
|
||||||
for name, child in self.children.iteritems():
|
for name, child in self.children.iteritems():
|
||||||
child.__dump(prio, indent=indent, caller=caller)
|
child.__dump(prio, indent=indent, caller=caller)
|
||||||
|
|
@ -110,7 +112,7 @@ class StringTree: # export
|
||||||
if len(content) == 0:
|
if len(content) == 0:
|
||||||
raise Exception("Tried to set empty content")
|
raise Exception("Tried to set empty content")
|
||||||
self.content = content
|
self.content = content
|
||||||
|
|
||||||
def add(self, path, content = None):
|
def add(self, path, content = None):
|
||||||
slog(DEBUG, "adding", content, "at", path, "to", self.content)
|
slog(DEBUG, "adding", content, "at", path, "to", self.content)
|
||||||
return self.__set(path, content)
|
return self.__set(path, content)
|
||||||
|
|
@ -144,7 +146,11 @@ class StringTree: # export
|
||||||
return None
|
return None
|
||||||
return self.children[next(reversed(self.children))].content
|
return self.children[next(reversed(self.children))].content
|
||||||
|
|
||||||
def dump(self, prio, caller=None, *args):
|
def dump(self, prio, *args, **kwargs):
|
||||||
if caller is None:
|
caller = kwargs['caller'] if 'caller' in kwargs.keys() else get_caller_pos(1)
|
||||||
caller = get_caller_pos(1)
|
msg = ''
|
||||||
|
if args is not None:
|
||||||
|
msg = ' ' + ' '.join(args) + ' '
|
||||||
|
slog(prio, ",------------" + msg + "----------- >", caller=caller)
|
||||||
self.__dump(prio, indent=0, caller=caller)
|
self.__dump(prio, indent=0, caller=caller)
|
||||||
|
slog(prio, "`------------" + msg + "----------- <", caller=caller)
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ def parse(s): # export
|
||||||
|
|
||||||
if rhs is None:
|
if rhs is None:
|
||||||
raise Exception("failed to parse assignment", line)
|
raise Exception("failed to parse assignment", line)
|
||||||
root.add(sec + '.' + cleanup_string(lhs), quote(cleanup_string(rhs)))
|
root.add(sec + '.' + cleanup_string(lhs), cleanup_string(rhs))
|
||||||
return root
|
return root
|
||||||
|
|
||||||
def read(path): # export
|
def read(path): # export
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue