Ejemplo n.º 1
0
litarg = Group(
    number | aString
)('args*')
litkwarg = Group(argname + equal + litarg)('kwargs*')
# lookahead to prevent failing on equals
litargs = delimitedList(~litkwarg + litarg)
litkwargs = delimitedList(litkwarg)

template = Group(
    Literal('template') + leftParen +
    (call | pathExpression) +
    Optional(comma + (litargs | litkwargs)) +
    rightParen
)('template')

if __version__.startswith('1.'):
    expression << Group(template | call | pathExpression)('expression')
    grammar << expression
else:
    expression <<= Group(template | call | pathExpression)('expression')
    grammar <<= expression


def enableDebug():
    for name, obj in globals().items():
        try:
            obj.setName(name)
            obj.setDebug(True)
        except:
            pass
Ejemplo n.º 2
0
litargs = delimitedList(~litkwarg +
                        litarg)  # lookahead to prevent failing on equals
litkwargs = delimitedList(litkwarg)

template = Group(
    Literal('template') + leftParen + (call | pathExpression) +
    Optional(comma + (litargs | litkwargs)) + rightParen)('template')

pipeSep = ZeroOrMore(Literal(' ')) + Literal('|') + ZeroOrMore(Literal(' '))

pipedExpression = Group(
    (template | call | pathExpression) +
    Group(ZeroOrMore(Suppress(pipeSep) +
                     Group(call)('pipedCall')))('pipedCalls'))('expression')

if __version__.startswith('1.'):
    expression << pipedExpression
    grammar << expression
else:
    expression <<= pipedExpression
    grammar <<= expression


def enableDebug():
    for name, obj in list(globals().items()):
        try:
            obj.setName(name)
            obj.setDebug(True)
        except:
            pass
Ejemplo n.º 3
0
args = delimitedList(~kwarg + arg)  # lookahead to prevent failing on equals
kwargs = delimitedList(kwarg)

call = Group(funcname + leftParen + Optional(args + Optional(comma + kwargs)) + rightParen)("call")

# Metric pattern (aka. pathExpression)
validMetricChars = "".join((set(printables) - set(symbols)))
escapedChar = backslash + Word(symbols, exact=1)
partialPathElem = Combine(OneOrMore(escapedChar | Word(validMetricChars)))

matchEnum = Combine(leftBrace + delimitedList(partialPathElem, combine=True) + rightBrace)

pathElement = Combine(Group(partialPathElem | matchEnum) + ZeroOrMore(matchEnum | partialPathElem))
pathExpression = delimitedList(pathElement, delim=".", combine=True)("pathExpression")

if __version__.startswith("1."):
    expression << Group(call | pathExpression)("expression")
    grammar << expression
else:
    expression <<= Group(call | pathExpression)("expression")
    grammar <<= expression


def enableDebug():
    for name, obj in globals().items():
        try:
            obj.setName(name)
            obj.setDebug(True)
        except:
            pass