示例#1
0
 def p_value(self, p):
     """value : dictionary
              | array
              | bool
              | null
              | NUMBER
              | string"""
     p[0] = ast.Value(value=p[1], debug_info=self.debug_info(p, 1))
示例#2
0
 def visit(self, node):
     args = [
         ast.NamedArg(ident=ast.Id(ident='data'), arg=node.arg),
         ast.NamedArg(ident=ast.Id(ident='n'), arg=ast.Value(value=-1))
     ]
     self.counter += 1
     const_name = '_literal_const_' + str(self.counter)
     const_actor = ast.Assignment(ident=const_name,
                                  actor_type='std.Constant',
                                  args=args)
     const_actor.debug_info = node.arg.debug_info
     const_actor_port = ast.OutPort(actor=const_name, port='token')
     link = node.parent
     link.replace_child(node, const_actor_port)
     block = link.parent
     block.add_child(const_actor)
示例#3
0
        'RulePredicate': RulePredicate,
        'RuleExpression': RuleExpression,
        'Rule': Rule
    }.get(o['class'])()
    instance.__dict__ = o['data']
    return instance


if __name__ == '__main__':
    import json
    import astprint
    import astnode as ast

    Node._verbose_desc = True

    bp = astprint.BracePrinter()

    root = ast.Node()
    root.add_child(
        ast.Constant(ident=ast.Id(ident="foo"), arg=ast.Value(value=1)))
    bp.visit(root)

    s = json.dumps(root, default=ast.node_encoder, indent=2)

    print
    print s
    print

    tree = json.loads(s, object_hook=ast.node_decoder)
    bp.visit(tree)
示例#4
0
    }.get(o['class'])()
    instance.__dict__ = o['data']
    return instance


if __name__ == '__main__':
    import json
    import astprint
    import astnode as ast

    Node._verbose_desc = True

    bp = astprint.BracePrinter()

    root = ast.Node()
    root.add_child(ast.Constant(ident=ast.Id(ident="foo"), arg=ast.Value(value=1)))
    bp.visit(root)

    s = json.dumps(root, default=ast.node_encoder, indent=2)

    print
    print s
    print

    tree = json.loads(s, object_hook=ast.node_decoder)
    bp.visit(tree)