jacques.ast package¶
Submodules¶
jacques.ast.jacques_ast module¶
- class jacques.ast.jacques_ast.CodeJAST(code_ast, command, *args, **kwargs)¶
Bases:
JASTJAST subclass for python code ASTs.
- Parameters:
code_ast – The python AST node.
command – The command called by original python AST node.
- property regex¶
Unparse code AST into a regex with placeholders replaced with their respective regex patterns. :return: Regex string.
- property source_code¶
- Returns:
The source code of AST this node.
- class jacques.ast.jacques_ast.DslJAST¶
Bases:
JASTJAST subclass for DSL queries.
- Parameters:
dsl_string – The DSL query string.
command – The command called by original DSL query.
- property command: str¶
- property jacques_dsl: str¶
- merge(other: DslJAST, id_provider: _IdProvider) Optional[List[str]]¶
Merge two DSL trees of the same format, detecting mismatch in the relevant keyword and rendering it as a Choicleton placeholder.
- Parameters:
other – The other DSL query.
id_provider – The id provider to use for generating new ids.
- Returns:
Choice keywords produced as a result of a merge.
- property name: str¶
- property nldsl_code_choice: str¶
- property nldsl_dsl: str¶
- property nldsl_grammar_mods: str¶
- property placeholders¶
Get all placeholders in this DSL JAST.
- Returns:
List of placeholders.
- property regex: str¶
jacques.ast.jacques_ast_utils module¶
- class jacques.ast.jacques_ast_utils.CodeExtractor(jacques)¶
Bases:
NodeTransformerTakes a CodeJAST subtree and extracts proper AST subtree.
- Parameters:
jacques – Jacques instance
- extract(root_code_jast: CodeJAST, pipe_nodes: List[CodeJAST]) AST¶
Extracts an AST subtree from the given CodeJAST.
- Parameters:
root_code_jast – CodeJAST to extract from
pipe_nodes – List of CodeJAST nodes that should be replaced with Pipe nodes, if encountered.
- Returns:
Python AST subtree
- generic_visit(node: AST) AST¶
Called if no explicit visitor function exists for a node.
- visit_Assign(node: Assign)¶
- visit_Call(node: Call)¶
- visit_Name(node: Call)¶
- visit_Subscript(node: Subscript)¶
- class jacques.ast.jacques_ast_utils.SubtreeBuilder¶
Bases:
objectTakes a list of CodeJAST nodes and reassembles it into a CodeJAST subtree. The nodes in the input list have ALL of their original children, but only the nodes in the list are included in the output tree.
- jacques.ast.jacques_ast_utils.clone_matched(target: CodeJAST, reference: CodeJAST) CodeJAST¶
Takes a CodeJAST subtree from SubtreeBuilder, and a complete CodeJAST, and extracts matching subtree as a clone
- jacques.ast.jacques_ast_utils.extract_subtree_by_ref_as_ref_list(target: CodeJAST, reference: CodeJAST) List[CodeJAST]¶
Same as clone_matched, but extracts the match as a list with direct references in target
- Parameters:
target – CodeJAST to extract from
reference – CodeJAST to extract
- Returns:
List of CodeJAST nodes that match the reference
jacques.ast.python_ast_arg_replacer module¶
- class jacques.ast.python_ast_arg_replacer.ArgumentReplacer(dsl_arg: DSL, id_provider: _IdProvider)¶
Bases:
NodeTransformerReplaces the argument with a placeholder
- Parameters:
dsl_arg – the argument to replace in case of a match
id_provider – the id provider to use
- generic_visit(node)¶
Called if no explicit visitor function exists for a node.
- replace(node: AST) Tuple[AST, jacques.core.arguments._Argument.Placeholder | None]¶
Replaces the argument with a placeholder
- Parameters:
node – Python AST to replace the argument in
- Returns:
updated tree and the placeholder reference or None if no match was found
- visit_BinOp(node: BinOp) Any¶
- visit_Compare(node: Compare) Any¶
- visit_Constant(node: Constant) Any¶
- visit_Lambda(node: Lambda) Any¶
- visit_List(node: List) Any¶
- visit_Name(node: Name) Any¶
- visit_alias(node: alias) Any¶
jacques.ast.python_ast_cross_comparer module¶
- class jacques.ast.python_ast_cross_comparer.Comparer(dsl_arg: DSL)¶
Bases:
NodeVisitorClass that handles cross-compare algorithm described in the original paper
- Parameters:
dsl_arg – the argument to compare against
- compare(node: AST) int¶
Traverse the tree and compare the argument with each node
- Parameters:
node – Python AST to compare the argument against
- Returns:
number of matches
- visit_BinOp(node: BinOp) Any¶
- visit_Compare(node: Compare) Any¶
- visit_Constant(node: Constant) Any¶
- visit_List(node: List) Any¶
- visit_Name(node: Name) Any¶
- visit_alias(node: alias) Any¶
jacques.ast.python_ast_utils module¶
- class jacques.ast.python_ast_utils.JacquesRegexUnparser(*, _avoid_backslashes=False)¶
Bases:
_UnparserUnparser for python trees which renders placeholders in regex.
- generic_visit(node)¶
Called if no explicit visitor function exists for a node.
- visit(node)¶
Outputs a source code string that, if converted back to an ast (using ast.parse) will generate an AST equivalent to node
- class jacques.ast.python_ast_utils.JacquesUnparser(*, _avoid_backslashes=False)¶
Bases:
_UnparserUnparser for python trees which renders placeholders in NLDSL friendly format.
- generic_visit(node)¶
Called if no explicit visitor function exists for a node.
- class jacques.ast.python_ast_utils.MissingArgumentFixer(arguments: List[jacques.core.arguments._Argument.DSL | jacques.core.arguments._Argument.Placeholder])¶
Bases:
NodeVisitor- generic_visit(node)¶
Called if no explicit visitor function exists for a node.
- visit(node: AST) AST¶
Visit a node.
- class jacques.ast.python_ast_utils.ToFunctionUnparser¶
Bases:
_Unparser- generic_visit(node)¶
Called if no explicit visitor function exists for a node.
- sort_code_mods()¶
- to_function(node: AST) str¶
- visit_Dict(node)¶
- jacques.ast.python_ast_utils.unparse_comparator(comparator: cmpop) str¶
- jacques.ast.python_ast_utils.unparse_operation(operation: AST) str¶
Module contents¶
Most, if not all of this is to be rewritten to cover another programming language.