本文整理汇总了Python中ast.Node类的典型用法代码示例。如果您正苦于以下问题:Python Node类的具体用法?Python Node怎么用?Python Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: p_array
def p_array(p):
'''array : unary_expr list %prec LBRACKET
| tuple list %prec LBRACKET
'''
p[0]= Node('Subscript')
p[0].var = p[1]
p[0].slice = p[2]
示例2: p_for3
def p_for3(p):
"""for : FOR NAME EQ range block
"""
p[0] = Node("For")
p[0].iter = p[2]
p[0].range = p[4]
p[0].body = p[5]
示例3: p_array
def p_array(p):
'''array : unary_expr list %prec LBRACKET
| tuple list %prec LBRACKET
'''
p[0]= Node('ARRAY')
p[0].var = p[1]
p[0].elems = p[2].elems
示例4: t_Dstring
def t_Dstring(t):
r'".*?[^\\]"'
t.type='STRING'
x=Node('String')
x.value=t.value[1:-1]
t.value = x
return t
示例5: p_for1
def p_for1(p):
"""for : FOR NAME IN load block
"""
p[0] = Node("ForEach")
p[0].iter = p[2]
p[0].list = p[4]
p[0].body = p[5]
示例6: p_halfcblock
def p_halfcblock(p):
'''halfcblock : Lcurly
| halfcblock pvar
| halfcblock dot
| halfcblock dvar
| halfcblock spaces
| halfcblock identifier
| halfcblock newline
| halfcblock cblock
| halfcblock pblock
| halfcblock colon
| halfcblock string
| halfcblock num
| halfcblock eq
| halfcblock lt
| halfcblock gt
| halfcblock not
| halfcblock tab
| halfcblock misc
| halfcblock comma
| halfcblock fcall
'''
p[0] = Node('halfc','')
if len(p)>2:
p[0].args=p[1].args
n=p[2]
if isinstance(p[2],str):
x= p[2]
if x=='\n':
x='newline'
n=Node("token")
n.str = x
p[0].args.append(n)
else:
p[0].args= []
示例7: p_fDef
def p_fDef(p):
"""fDef : DEF NAME defTuple ARROW EXCLAMATION NAME block"""
p[0] = Node("Fdef")
p[0].func = p[2]
p[0].args = p[3]
p[0].rettype = p[6]
p[0].body = p[7]
示例8: t_Sstring
def t_Sstring(t):
r"'.*?[^\\]'"
t.type='STRING'
x=Node('String')
x.value=t.value[1:-1]
t.value = x
return t
示例9: p_lookup
def p_lookup(p):
"""lookup : load DOT NAME
"""
p[0] = Node("Lookup")
p[0].var = p[1]
p[0].var.ctl = "store"
p[0].attr = p[3]
示例10: p_fcall
def p_fcall(p):
'''fcall : unary_expr tuple
| fcall tuple
'''
p[0] = Node('FCALL')
p[0].func = p[1]
p[0].args = p[2].elems
示例11: p_assign4
def p_assign4(p):
'''assign : commalist_expr EQ commalist_expr
'''
p[0] = Node('Assign')
p[0].target =Node('tuple')
p[0].target.elems =p[1].elems
p[0].value =Node('tuple')
p[0].value.elems =p[3].elems
示例12: p_lookup
def p_lookup(p):
'''lookup : unary_expr DOT IDENTIFIER %prec DOT
| list DOT IDENTIFIER %prec DOT
| tuple DOT IDENTIFIER %prec DOT
'''
p[0] = Node('LOOKUP')
p[0].var = p[1]
p[0].attr = p[3]
示例13: p_elif2
def p_elif2(p):
'''elif : ELIF expr block elif
| ELIF expr block else
'''
p[0] =Node('IF')
p[0].cond = p[2]
p[0].body = p[3].body
p[0].orelse = p[4]
示例14: p_foreach
def p_foreach(p):
'''foreach : FOR IDENTIFIER IN expr block
| FOR vdef IN expr block
'''
p[0] = Node('Foreach')
p[0].iter = p[2]
p[0].target = p[4]
p[0].body = p[5].body
示例15: p_if2
def p_if2(p):
'''if : IF expr block elif
| IF expr block else
'''
p[0] = Node('IF')
p[0].cond = p[1]
p[0].body=p[3].body
p[0].orelse = p[4]