CAIT
A package of tools for capturing student code by matching it against patterns.
Helper functions for traversing through the code structure.
- find_function_calls(name: str, root=None, report=<pedal.core.report.Report object>)[source]
Returns a list of CaitNodes representing all of the function calls that were found. This includes both methods and regular functions.
- find_function_definition(name, root=None, report=<pedal.core.report.Report object>)[source]
Finds the given function definition based on the given
name
.
- find_operation(op_name, root=None, report=<pedal.core.report.Report object>)[source]
Returns all the occurrences of the operator
op_name
in the source code. You can specify the operator as a string like"+"
or"<<"
. Supports all comparison, boolean, binary, and unary operators.
- find_prior_initializations(node, report=<pedal.core.report.Report object>)[source]
DEPRECATED
Given a Name node, returns a list of all the assignment statements that incorporate that Name node prior to that line. Returns None if no Name is given.
- is_top_level(ast_node, report=<pedal.core.report.Report object>) bool [source]
Determines if the
ast_node
is at the top-level of the program. Correctly handles expression statements (so a print call on its own will be considered a statement, even though its technically an expression).
Field |
Type |
Initial |
Description |
---|---|---|---|
ast |
CaitNode |
None |
The CaitNode tree that was most recently parsed out. |
cache |
{str: CaitNode} |
{} |
A dictionary mapping previously parsed code to CaitNode trees. |
success |
bool |
True |
Whether the most recent parsing was successful. |
error |
Exception |
None |
The most recent exception, or None. |
- data_state(node, report=<pedal.core.report.Report object>)[source]
Determines the Tifa State of the given node.
- data_type(node, report=<pedal.core.report.Report object>)[source]
Looks up the type of the node using Tifa’s analysis.
- def_use_error(node, report=<pedal.core.report.Report object>)[source]
Checks if node is a name and has a def_use_error
- expire_cait_cache(report=<pedal.core.report.Report object>)[source]
Deletes the most recent CAIT run and any cached CAIT parses.
- Parameters:
report (Report) – The report to attach data to. Defaults to MAIN_REPORT.
- find_asts(node_name: str, student_code=None, report=<pedal.core.report.Report object>)[source]
Find all occurrences of the given AST node, based on the name of the AST node (e.g.,
"For"
or"FunctionDef"
).- Parameters:
node_name – the string representing the “type” of node to look for
student_code (str) – Optionally, different code to parse and search.
report – defaults to MAIN_REPORT unless another one is given.
- Returns:
- a list of Ast Nodes (cait_nodes) of self that are of the specified type (including self if self
meets that criteria)
Returns:
- find_expr_sub_matches(pattern, student_code, is_mod=False, report=<pedal.core.report.Report object>)[source]
Finds pattern in student_code # TODO: Add code to make pattern accept CaitNodes # TODO: Make this function without so much meta knowledge :param pattern: the expression to find (str that MUST evaluate to a Module node with a single child or an AstNode) :param student_code: student subtree :param is_mod: currently hack for multiline sub matches :type is_mod: bool :param report: defaults to MAIN_REPORT unless another one exists
- Returns:
a list of matches or False if no matches found
- find_match(pattern, student_code=None, report=<pedal.core.report.Report object>, cut=False, use_previous=None)[source]
Apply Tree Inclusion and return the first match of the
pattern
in thestudent_code
.- Parameters:
pattern (str) – The CaitExpression to match against.
student_code (str) – The string of student code to check against. Defaults to the code of the Source tool in the Report.
report (Report) – The report to attach data to.
cut (bool) – Set to true to trim root to first branch
use_previous (AstMap) – If user wants to continue off of a previously found match
- Returns:
- The first matching node for the given pattern, or
None if nothing was found.
- Return type:
CaitNode or None
- find_matches(pattern, student_code=None, cut=False, report=<pedal.core.report.Report object>, use_previous=None)[source]
Apply Tree Inclusion and return all matches of the
pattern
in thestudent_code
.- Parameters:
pattern (str) – The CaitExpression to match against.
student_code (str) – The string of student code to check against.
report (Report) – The report to attach data to.
cut (bool) – Set to true to trim root to first branch
use_previous (AstMap) – If user wants to continue off of a previously found match
- Returns:
All matching nodes for the given pattern.
- Return type:
list[pedal.cait.ast_map.AstMap]
- find_submatches(pattern, student_code, is_mod=False, report=<pedal.core.report.Report object>)[source]
Incomplete.
- parse_program(student_code=None, report=<pedal.core.report.Report object>)[source]
Parses student code and produces a CAIT representation.
- reparse_if_needed(student_code=None, report=<pedal.core.report.Report object>)[source]
Retrieves the current report for CAIT. If there is no CAIT report, it will generate one. If source code is given, that will be used instead of the report’s submission.