Rework "value" parser:

- Now handles any${VAR_SUBSTITUTION}inthemiddle/of/values
  - Don't use a single giant janky Regex; use small ones and have PyParsing
    combine them
This commit is contained in:
Peter Eckersley
2016-07-15 17:11:04 -07:00
parent b6966fc05e
commit e3ab49a93b
+11 -3
View File
@@ -25,11 +25,19 @@ class RawNginxParser(object):
key = Word(alphanums + "_/+-.")
dollar_var = Combine(Literal('$') + Regex(r"[^\{\};,\s]+"))
condition = Regex(r"\(.+\)")
# Matches anything that is not a special character AND any chars in single
# or double quotes
# Matches anything that is not a special character, and ${SHELL_VARS}, AND
# any chars in single or double quotes
# All of these COULD be upgraded to something like
# https://stackoverflow.com/a/16130746
value = Regex(r"((\".*\")?(\'.*\')?[^\{\};,]?)+")
dquoted = Regex(r'(\".*\")')
squoted = Regex(r"(\'.*\')")
nonspecial = Regex(r"[^\{\};,]")
varsub = Regex(r"(\$\{\w+\})")
# nonspecial nibbles one character at a time, but the other objects take
# precedence. We use ZeroOrMore to allow entries like "break ;" to be
# parsed as assignments
value = Combine(ZeroOrMore(dquoted | squoted | varsub | nonspecial))
location = CharsNotIn("{};," + string.whitespace)
# modifier for location uri [ = | ~ | ~* | ^~ ]
modifier = Literal("=") | Literal("~*") | Literal("~") | Literal("^~")