Skip to content

Commit 97c693d

Browse files
author
Paul J Stevens
committed
fix value definition and some cleanups
1 parent 1646532 commit 97c693d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

nginxparser.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from pyparsing import (
44
Literal, White, Word, alphanums, CharsNotIn, Forward, Group, SkipTo,
5-
LineEnd, Optional, OneOrMore, ZeroOrMore, pythonStyleComment)
5+
Optional, OneOrMore, ZeroOrMore, pythonStyleComment)
66

77

88
class NginxParser(object):
@@ -16,7 +16,7 @@ class NginxParser(object):
1616
semicolon = Literal(";").suppress()
1717
space = White().suppress()
1818
key = Word(alphanums + "_/")
19-
value = CharsNotIn("{};,")
19+
value = CharsNotIn("{};")
2020
value2 = CharsNotIn(";")
2121
location = CharsNotIn("{};," + string.whitespace)
2222
ifword = Literal("if")
@@ -29,19 +29,25 @@ class NginxParser(object):
2929
setblock = (setword + OneOrMore(space + value2) + semicolon)
3030
block = Forward()
3131
ifblock = Forward()
32-
subblock = ZeroOrMore(Group(assignment) | block | ifblock | setblock)
33-
ifblock = (
32+
subblock = Forward()
33+
34+
ifblock << (
3435
ifword
3536
+ SkipTo('{')
3637
+ left_bracket
3738
+ subblock
3839
+ right_bracket)
3940

41+
subblock << ZeroOrMore(
42+
Group(assignment) | block | ifblock | setblock
43+
)
44+
4045
block << Group(
4146
Group(key + Optional(space + modifier) + Optional(space + location))
4247
+ left_bracket
43-
+ Group(ZeroOrMore(Group(assignment) | block | ifblock | setblock))
44-
+ right_bracket)
48+
+ Group(subblock)
49+
+ right_bracket
50+
)
4551

4652
script = OneOrMore(Group(assignment) | block).ignore(pythonStyleComment)
4753

0 commit comments

Comments
 (0)