StringTree parser: Add support for comments

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2017-11-02 11:47:04 +01:00
commit 6ca2eeef61

View file

@ -1,13 +1,28 @@
from StringTree import *
from jwutils.log import *
def _cleanup_line(line):
line = line.strip()
r = ''
in_quote = None
for c in line:
if c == in_quote:
in_quote = None
else:
if c in [ '"', "'" ]:
in_quote = c
elif c == '#':
return r.strip()
r += c
return r
def parse(s): # export
slog(DEBUG, "parsing", s)
root = StringTree('', content='root')
sec = ''
for line in s.splitlines():
slog(DEBUG, "line=", line)
line = line.strip()
line = _cleanup_line(line)
if not len(line):
continue
if line[0] == '[':