From 84f79a3e046eea1d064252ee4768ce9276a5a058 Mon Sep 17 00:00:00 2001 From: Andrew Krasichkov Date: Thu, 27 Sep 2018 19:41:19 +0300 Subject: [PATCH] Try to parse inline comment in blocks --- gixy/parser/raw_parser.py | 3 +++ tests/parser/test_raw_parser.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/gixy/parser/raw_parser.py b/gixy/parser/raw_parser.py index d79f51b..6a30b7f 100644 --- a/gixy/parser/raw_parser.py +++ b/gixy/parser/raw_parser.py @@ -126,6 +126,7 @@ def script(self): if_block << ( Keyword("if") + Group(condition) + + Suppress(Optional(comment)) + Group( left_bracket + Optional(sub_block) + @@ -137,6 +138,7 @@ def script(self): Group( Optional(space + location_modifier) + Optional(space) + value) + + Suppress(Optional(comment)) + Group( left_bracket + Optional(sub_block) + @@ -155,6 +157,7 @@ def script(self): generic_block << ( keyword + Group(ZeroOrMore(space + value)) + + Suppress(Optional(comment)) + Group( left_bracket + Optional(sub_block) + diff --git a/tests/parser/test_raw_parser.py b/tests/parser/test_raw_parser.py index 605cf90..7fa4b01 100644 --- a/tests/parser/test_raw_parser.py +++ b/tests/parser/test_raw_parser.py @@ -488,6 +488,11 @@ def test_comments(): # add_header X-Blank-Comment blank; + +if (1) # Comment +{ + add_header X-Inline blank; +} ''' expected = [ @@ -499,6 +504,9 @@ def test_comments(): ['add_header', 'X-Padding-Comment', 'padding'], [''], ['add_header', 'X-Blank-Comment', 'blank'], + ['if', ['1'], [ + ['add_header', 'X-Inline', 'blank'], + ]], ] assert_config(config, expected)