Esempio n. 1
0
    def tagmatch(self):

        self.ignore(whitespace)

        self.nextmust('#')

        text = self.noms(until=tagmatchterm)

        return s_ast.TagMatch(text)
Esempio n. 2
0

evalcache = s_cache.FixedCache(_forkedParseEval, size=100)
querycache = s_cache.FixedCache(_forkedParseQuery, size=100)


def massage_vartokn(x):
    return s_ast.Const('' if not x else (x[1:-1] if x[0] == "'" else (
        unescape(x) if x[0] == '"' else x)))


# For AstConverter, one-to-one replacements from lark to synapse AST
terminalClassMap = {
    'ABSPROP': s_ast.AbsProp,
    'ABSPROPNOUNIV': s_ast.AbsProp,
    'ALLTAGS': lambda _: s_ast.TagMatch(''),
    'BREAK': lambda _: s_ast.BreakOper(),
    'CONTINUE': lambda _: s_ast.ContinueOper(),
    'DEREFMATCHNOSEP': massage_vartokn,
    'DOUBLEQUOTEDSTRING': lambda x: s_ast.Const(unescape(
        x)),  # drop quotes and handle escape characters
    'TRIPLEQUOTEDSTRING': lambda x: s_ast.Const(x[3:-3]),  # drop the triple 's
    'NUMBER': lambda x: s_ast.Const(s_ast.parseNumber(x)),
    'HEXNUMBER': lambda x: s_ast.Const(s_ast.parseNumber(x)),
    'BOOL': lambda x: s_ast.Bool(x == 'true'),
    'SINGLEQUOTEDSTRING': lambda x: s_ast.Const(x[1:-1]),  # drop quotes
    'TAGMATCH': lambda x: s_ast.TagMatch(kids=AstConverter._tagsplit(x)),
    'VARTOKN': massage_vartokn,
}

# For AstConverter, one-to-one replacements from lark to synapse AST
Esempio n. 3
0
    The full list of escaped characters can be found at
    https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
    '''
    ret = ast.literal_eval(valu)
    assert isinstance(ret, str)
    return ret


# For AstConverter, one-to-one replacements from lark to synapse AST
terminalClassMap = {
    'ABSPROP':
    s_ast.AbsProp,
    'ABSPROPNOUNIV':
    s_ast.AbsProp,
    'ALLTAGS':
    lambda _: s_ast.TagMatch(''),
    'BREAK':
    lambda _: s_ast.BreakOper(),
    'CONTINUE':
    lambda _: s_ast.ContinueOper(),
    'DOUBLEQUOTEDSTRING':
    lambda x: s_ast.Const(unescape(x)
                          ),  # drop quotes and handle escape characters
    'NUMBER':
    lambda x: s_ast.Const(s_ast.parseNumber(x)),
    'SINGLEQUOTEDSTRING':
    lambda x: s_ast.Const(x[1:-1]),  # drop quotes
    'TAGMATCH':
    lambda x: s_ast.TagMatch(kids=AstConverter._tagsplit(x)),
    'VARTOKN':
    lambda x: s_ast.Const(x[1:-1] if len(x) and x[0] in ("'", '"') else x)
Esempio n. 4
0
    'vareval':
    s_ast.VarEvalOper,
    'varvalue':
    s_ast.VarValue,
    'univprop':
    s_ast.UnivProp
}

# For AstConverter, one-to-one replacements from lark to synapse AST
terminalClassMap = {
    'ABSPROP':
    s_ast.AbsProp,
    'ABSPROPNOUNIV':
    s_ast.AbsProp,
    'ALLTAGS':
    lambda _: s_ast.TagMatch(''),
    'BREAK':
    lambda _: s_ast.BreakOper(),
    'CONTINUE':
    lambda _: s_ast.ContinueOper(),
    'DOUBLEQUOTEDSTRING':
    lambda x: s_ast.Const(x[1:-1]),  # drop quotes
    'NUMBER':
    lambda x: s_ast.Const(s_ast.parseNumber(x)),
    'SINGLEQUOTEDSTRING':
    lambda x: s_ast.Const(x[1:-1]),  # drop quotes
    'TAGMATCH':
    s_ast.TagMatch,
    'VARTOKN':
    lambda x: s_ast.Const(x[1:-1] if len(x) and x[0] in ("'", '"') else x)
}