Exemplo n.º 1
0
def new_binary(self, ast, op, param):
    left = Node()
    if hasattr(param, 'brack'):
        param = param.brack
    if hasattr(ast, "brack"):
        left = ast.brack
    else:
        left.set(ast)
    if isinstance(param, nodes.Binary) and param.params and isinstance(param.params[0], nodes.Array) and hasattr(
            param.params[0].call_expr, 'brack'):
        param = param.params[0].call_expr.brack
    ast.set(nodes.Binary(op, [left, param]))
    return True
Exemplo n.º 2
0
def new_unary(self, ast, op, param):
    opu = Node()
    opu.set(op)
    p = Node()
    p.set(param)
    ast.set(knodes.KUnary(opu, [p]))
    return True
Exemplo n.º 3
0
def for_decl_begin(self, current_block):
    current_block.ref = Node()
    current_block.ref.body = []
    # new to link this fake body to other block
    parent = self.rule_nodes.parents
    if 'current_block' in parent:
        current_block.ref.types = parent['current_block'].ref.types.new_child()
    return True
Exemplo n.º 4
0
 def do_call(self, parser: BasicParser) -> Node:
     if parser.begin_tag(self.tagname):
         # subcontext
         parser.push_rule_nodes()
         res = self.pt(parser)
         parser.pop_rule_nodes()
         if res and parser.end_tag(self.tagname):
             tag = parser.get_tag(self.tagname)
             # no bindings, wrap it in a Node instance
             if type(res) is bool:
                 res = Node()
             # update node cache
             parser.tag_node(self.tagname, res)
             parser.rule_nodes[self.tagname] = res
             # forward nodes
             return res
     return False
Exemplo n.º 5
0
 def eval_rule(self, name: str) -> Node:
     """Evaluate a rule by name."""
     # context created by caller
     self.rule_nodes['_'] = Node()
     # TODO: other behavior for  empty rules?
     if name not in self.__class__._rules:
         self.diagnostic.notify(
             error.Severity.ERROR, "Unknown rule : %s" % name,
             error.LocationInfo.from_stream(self._stream, is_error=True))
         raise self.diagnostic
     self._lastRule = name
     rule_to_eval = self.__class__._rules[name]
     # TODO: add packrat cache here, same rule - same pos == same res
     res = rule_to_eval(self)
     if res:
         res = self.rule_nodes['_']
     return res
Exemplo n.º 6
0
 def do_call(self, parser: BasicParser) -> Node:
     parser.rule_nodes[self.tagname] = Node()
     return True
Exemplo n.º 7
0
def new_range(self, ast, expr):
    begin = Node()
    begin.set(ast)
    ast.set(nodes.Range(nodes.Raw('...'), [begin, expr]))
    return True
Exemplo n.º 8
0
def new_binary(self, ast, op, param):
    left = Node()
    left.set(ast)
    ast.set(knodes.KBinary(op, [left, param]))
    return True
Exemplo n.º 9
0
def new_ternary(self, ast, then_expr, else_expr):
    cond = Node()
    cond.set(ast)
    ast.set(knodes.KTernary([], [cond, then_expr, else_expr]))
    return True
Exemplo n.º 10
0
def to_cast(self, ast, typename):
    expr = Node()
    expr.set(ast)
    ast.set(knodes.KCast(knodes.KRaw('()'), [typename.ctype, expr]))
    return True
Exemplo n.º 11
0
 def __init__(self):
     """
     expr_type (None | type | ref(type) | array of type): The expression type
     """
     Node.__init__(self)
     self.expr_type = None