Reworked Nginx comments parsing

pull/23/head
Andrew Krasichkov 2017-05-02 11:51:15 +03:00
parent 8de6f0a698
commit 521d4e39f5
1 changed files with 16 additions and 3 deletions

View File

@ -87,9 +87,8 @@ class RawParser(object):
)("file_delimiter")
comment = (
Suppress('#') +
Regex(r".*")
)("comment")
Regex(r"#.*")
)("comment").setParseAction(_fix_comment)
hash_value = Group(
value +
@ -160,3 +159,17 @@ class RawParser(object):
)("unparsed_block")
return sub_block
def _fix_comment(string, location, tokens):
"""
Returns "cleared" comment text
:param string: original parse string
:param location: location in the string where matching started
:param tokens: list of the matched tokens, packaged as a ParseResults_ object
:return: list of the cleared comment tokens
"""
comment = tokens[0][1:].strip()
return [comment]