Skip to content

Commit

Permalink
Added ability to preserve comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
smelandr committed Jan 11, 2017
1 parent 2ceb822 commit 37f77d8
Show file tree
Hide file tree
Showing 4 changed files with 668 additions and 414 deletions.
20 changes: 15 additions & 5 deletions nmrstarlib/bmrblex.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@ def transform_text(input_txt):
while len(inputq) > 0:
line = inputq.popleft()

if line.startswith(u";"):
if line.lstrip().startswith(u"#"):
comment = u"" + line + u"\n"
line = inputq.popleft()

while line.lstrip().startswith(u"#"):
comment += line + u"\n"
line = inputq.popleft()

outputq.append(comment)
for character in line:
outputq.append(character)

elif line.startswith(u";"):
multiline = u"\n;\n"
line = inputq.popleft()

Expand All @@ -69,8 +81,6 @@ def transform_text(input_txt):
for character in line[1:]:
outputq.append(character)

elif line.lstrip().startswith(u"#"):
continue
else:
for character in line:
outputq.append(character)
Expand Down Expand Up @@ -111,8 +121,8 @@ def bmrblex(text):
else:
nextnextchar = u""

# Process multiline string
if len(nextchar) > 1:
# Process multiline string or comment
if nextchar.startswith(u"\n;\n") or nextchar.lstrip().startswith(u"#"):
state = u" "
token = nextchar
break # emit current token
Expand Down

0 comments on commit 37f77d8

Please sign in to comment.