mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
StringTree parser: Add support for comments
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
1a7a34f73c
commit
6ca2eeef61
1 changed files with 16 additions and 1 deletions
|
|
@ -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] == '[':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue