From 23ec2303e3df945050c101d407e53f977f6aa6c7 Mon Sep 17 00:00:00 2001 From: Andrew Krasichkov Date: Tue, 2 May 2017 11:51:15 +0300 Subject: [PATCH] Reworked Nginx comments parsing --- gixy/parser/raw_parser.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/gixy/parser/raw_parser.py b/gixy/parser/raw_parser.py index eb066e0..e2fdd59 100644 --- a/gixy/parser/raw_parser.py +++ b/gixy/parser/raw_parser.py @@ -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]