Skip to content

Commit

Permalink
Fixed issues #2, #5, #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
smelandr committed Aug 3, 2017
1 parent f995484 commit a4be3d3
Show file tree
Hide file tree
Showing 4 changed files with 590 additions and 241 deletions.
18 changes: 16 additions & 2 deletions nmrstarlib/bmrblex.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def transform_text(input_txt):
line = inputq.popleft()

multiline += line[:1]
outputq.append(multiline)
outputq.append(multiline[3:-1]) # remove NMR-STAR syntax from multiline string

for character in line[1:]:
outputq.append(character)
Expand Down Expand Up @@ -108,8 +108,10 @@ def bmrblex(text):
u"!@$%^&*()_+:;?/>.<,~`|\{[}]-=")

whitespace = u" \t\v\r\n"
comment = u"#"
state = u" "
token = u""
single_line_comment = u""

while len(stream) > 0:
nextnextchar = stream.popleft()
Expand All @@ -122,12 +124,16 @@ def bmrblex(text):
else:
nextnextchar = u""

# Process multiline string or comment
# Process multiline string, comment, or single line comment
if len(nextchar) > 1:
state = u" "
token = nextchar
break # emit current token

elif nextchar in whitespace and nextnextchar in comment and state not in (u"'", u'"'):
single_line_comment = u""
state = u"#"

if state is None:
token = u"" # past end of file
break
Expand Down Expand Up @@ -166,8 +172,16 @@ def bmrblex(text):
if nextchar == state:
if nextnextchar in whitespace:
state = u" "
token = token[1:-1] # remove single or double quotes from the ends
break

# Process single line comment
elif state == u"#":
single_line_comment += nextchar
if nextchar == u"\n":
state = u" "
break

# Process regular (unquoted) token
elif state == u"a":
if not nextchar:
Expand Down

0 comments on commit a4be3d3

Please sign in to comment.