reiz.io
1.0.0

Reiz.io是Python的结构源代码搜索引擎。与流行的替代方案(例如GitHub代码搜索)相比,它在语法树上执行查询(而不是原始的源代码),并试图检索结构知识(无应用语义)。有关更多信息,请参阅文档。
Reiz是Reiz.io的代码搜索框架。由于其性质,它仅与ASTS合作,并故意避免进行任何语义工作。
Some ASTs attach a bit of contextual knowledge (e.g `Name(ctx=...)`
on python) which can be queried through simple matcher queries but
reiz.io doesn't include them when comparing references (see
matchers#reference-matcher for details).
这是一个简单的reizql查询,它搜索一个以try语句结尾的函数,在该函数中,我们将调用与具有与我们所在函数相同的函数返回一个函数。
FunctionDef ( ~ func , body = [ * ..., Try ( body = [ Return ( Call ( Name ( ~ func )))])])这将符合以下内容;
def foo ( spam ):
eggs = bar ()
try :
return foo ( spam + eggs )
except ValueError :
return None从非常基本的意义上讲,它正在生成上面代码的AST,并检查它是否符合模式(Reizql查询)。
FunctionDef (
name = 'foo' ,
args = arguments (
posonlyargs = [],
args = [ arg ( arg = 'spam' , annotation = None , type_comment = None )],
vararg = None ,
kwonlyargs = [],
kw_defaults = [],
kwarg = None ,
defaults = [],
),
body = [
Assign (
targets = [ Name ( id = 'eggs' , ctx = Store ())],
value = Call (
func = Name ( id = 'bar' , ctx = Load ()),
args = [],
keywords = [],
),
type_comment = None ,
),
Try (
body = [
Return (
value = Call (
func = Name ( id = 'foo' , ctx = Load ()),
args = [
BinOp (
left = Name ( id = 'spam' , ctx = Load ()),
op = Add (),
right = Name ( id = 'eggs' , ctx = Load ()),
),
],
keywords = [],
),
),
],
handlers = [
ExceptHandler (
type = Name ( id = 'ValueError' , ctx = Load ()),
name = None ,
body = [
Return (
value = Constant ( value = None , kind = None ),
),
],
),
],
orelse = [],
finalbody = [],
),
],
decorator_list = [],
returns = None ,
type_comment = None ,
)