Пример #1
0
    # the next would be close to the spec (but huge!)
    #identi = py.Word(u''.join(lang.IDENTIFIER_CHARS_START), u''.join(lang.IDENTIFIER_CHARS_BODY))
    # but using regex, to be consistent with the parser
    py_js_identifier = py.Regex(lang.IDENTIFIER_REGEXP)

    py_simple_type = py.Suppress('{') + py_js_identifier.copy()(
        'type_name') + py.Suppress('}')

    py_single_type = py_js_identifier.copy().setResultsName('type_name') + \
        py.ZeroOrMore('[]').setResultsName('type_dimensions')

    # mirror: {Foo|Bar? 34}
    py_type_expression = py.Suppress('{') + py.Optional(
        py.delimitedList(py_single_type, delim='|')("texp_types") +  # Foo|Bar
        py.Optional(
            py.Literal('?')("texp_optional") +  # ?
            py.Optional(py.Regex(r'[^}]+'))("texp_defval"))  # 34
    ) + py.Suppress('}')

    ##
    # "@type {Map}
    gr_at_type = py.Suppress('@') + py.Literal('type') + py_simple_type

    def parse_at_type(self, line):
        grammar = self.gr_at_type
        presult = grammar.parseString(line)
        res = {
            'category': 'type',
            'type': presult.type_name,
        }
        return res
Пример #2
0
    | pp.Combine(pp.Suppress("%") + "rip") \

reg128 = \
    pp.Combine(pp.Suppress("%") + "xmm0") \
    | pp.Combine(pp.Suppress("%") + "xmm1") \
    | pp.Combine(pp.Suppress("%") + "xmm2") \
    | pp.Combine(pp.Suppress("%") + "xmm3") \
    | pp.Combine(pp.Suppress("%") + "xmm4") \
    | pp.Combine(pp.Suppress("%") + "xmm5") \
    | pp.Combine(pp.Suppress("%") + "xmm6") \
    | pp.Combine(pp.Suppress("%") + "xmm7")

register = reg8 | reg32 | reg64 | reg128

immediate = pp.Combine(
    pp.Suppress("$") + pp.Literal("0x") + pp.Word(pp.hexnums)) | pp.Combine(
        pp.Suppress("$") + pp.Optional("-") + pp.Word(pp.nums))

memory_offset = pp.Combine(pp.Optional("-") + pp.Word(pp.nums))
memory_base = register
memory_index = register
memory_scale = pp.Or(["1", "2", "4", "8"])

label = pp.Combine(pp.Literal("L$") + pp.Word(pp.alphas, pp.alphanums + "_"))

memory = pp.Group(\
    pp.Optional(memory_offset, default = "OFFSET") \
    + pp.Suppress("(") + pp.Optional(memory_base, default = "BASE") \
    + pp.Optional(pp.Suppress(",") + memory_index \
    + pp.Optional(pp.Suppress(",") + memory_scale)) \
    + pp.Suppress(")"))
Пример #3
0
        py_js_identifier.copy().setResultsName('t_functor') +
        py.Suppress('(') +
        py.Optional(py.delimitedList(py_term_argument))  # 'foo.Bar#baz'
        .setResultsName('t_arguments') + py.Suppress(')'))

    py_simple_type = py.Suppress('{') + py_js_identifier.copy()(
        'type_name') + py.Suppress('}')

    py_single_type = py_js_identifier.copy().setResultsName('type_name') + \
        py.ZeroOrMore('[]').setResultsName('type_dimensions')

    # mirror: {Foo|Bar? 34}
    py_type_expression = py.Suppress('{') + py.Optional(
        py.delimitedList(py_single_type, delim='|')("texp_types") +  # Foo|Bar
        py.Optional(
            py.Literal('?')("texp_optional") +  # ?
            py.Optional(py.Regex(r'[^}]+'))("texp_defval"))  # 34
    ) + py.Suppress('}')

    ##
    # "@type {Map} blah
    gr_at_type = py.Suppress('@') + py.Literal(
        'type') + py_type_expression + py.restOfLine("text")

    def parse_at_type(self, line):
        grammar = self.gr_at_type
        presult = grammar.parseString(line)
        types = self._typedim_list_to_typemaps(
            presult.texp_types.asList() if presult.texp_types else [])
        res = {'category': 'type', 'type': types, 'text': presult.text.strip()}
        return res
Пример #4
0
        progOrig = toks[0][:-1]
        arrName = toks[1]
        bitlength = toks[2][1:]
        arrIndex = toks[3]
    
    temp = di.ArrayCall(arrName, arrIndex)
    temp.length = int(bitlength, 0)
    
    if progOrig != None : temp.programOrigin = progOrig
    return [temp]

def parseFunction(s, loc, toks) :
    temp = di.Function(toks[0], toks[2], toks[3])
    return temp

lpar = pp.Literal("(")
rpar = pp.Literal(")")
shiftOpGroup = pp.oneOf(">> >>> << <<<")
andOpGroup = pp.oneOf("& | ^")
plusOpGroup = pp.oneOf("+ -")
multOpGroup = pp.oneOf("* /")
unOpGroup = pp.oneOf("!")
comparator = pp.oneOf("= > >= < <= == !=")

constant = pp.Combine(pp.Optional(pp.Literal("-")) + pp.Word(pp.hexnums)) + pp.Optional(pp.Combine(pp.Literal(":") + pp.Word(pp.hexnums)), default=":32")
tempVar = pp.Optional(pp.Combine(pp.Word(pp.alphas, pp.alphanums) + pp.Literal("."))) + pp.Word(pp.alphas, pp.alphanums + "_") + pp.Optional(pp.Combine(pp.Literal(":") + pp.Word(pp.hexnums)), default=":32")
hexConstant = pp.Combine("0x" + pp.Word(pp.hexnums)) + pp.Optional(pp.Combine(pp.Literal(":") + pp.Word(pp.hexnums)), default=":32")
label = pp.Combine(pp.Literal("L$") + pp.Word(pp.alphas, pp.alphanums + "_"))

orExpression = pp.Forward()
argList = (orExpression + pp.ZeroOrMore(pp.Suppress(pp.Literal(",")) + orExpression)).setParseAction(pushCallArg)