python2ib
Version:
Convert Python code to IB Pseudocode format
81 lines • 4.19 kB
TypeScript
/**
* Base visitor class for AST traversal using the Visitor pattern
*/
import { PythonASTNode } from '../ast-parser.js';
import { IR } from '../../types/ir.js';
import { ConvertOptions } from '../../types/config.js';
/** Base visitor interface */
export interface Visitor<T = IR> {
visit(node: PythonASTNode): T;
}
/** Abstract base visitor class */
export declare abstract class BaseVisitor implements Visitor<IR> {
protected config: Required<ConvertOptions>;
constructor(config: Required<ConvertOptions>);
/** Main visit method - dispatches to specific visit methods */
visit(node: PythonASTNode): IR;
/** Visit multiple nodes and return array of IRs */
visitMany(nodes: PythonASTNode[]): IR[];
/** Handle unsupported node types */
protected visitUnsupported(node: PythonASTNode): IR;
/** Extract string representation from expression node */
protected extractExpression(node: PythonASTNode, depth?: number): string;
/** Format constant values */
protected formatConstant(value: any): string;
/** Extract binary operation expression */
protected extractBinaryOperation(node: PythonASTNode, depth?: number): string;
/** Extract unary operation expression */
protected extractUnaryOperation(node: PythonASTNode, depth?: number): string;
/** Extract comparison expression */
protected extractComparison(node: PythonASTNode, depth?: number): string;
/** Extract boolean operation expression */
protected extractBooleanOperation(node: PythonASTNode, depth?: number): string;
/** Extract function call expression */
protected extractCall(node: PythonASTNode, depth?: number): string;
/** Extract subscript expression (array/list access) */
protected extractSubscript(node: PythonASTNode, depth?: number): string;
/** Extract attribute access expression (e.g., obj.method) */
protected extractAttribute(node: PythonASTNode, depth?: number): string;
/** Extract joined string (f-string) expression */
protected extractJoinedString(node: PythonASTNode, _depth?: number): string;
/** Convert Python binary operators to IB Pseudocode */
protected convertBinaryOperator(op: string): string;
/** Convert Python unary operators to IB Pseudocode */
protected convertUnaryOperator(op: string): string;
/** Convert Python comparison operators to IB Pseudocode */
protected convertComparisonOperator(op: string): string;
/** Check if a function has return statements */
protected hasReturnStatement(body: PythonASTNode[]): boolean;
/** Apply variable name mapping if configured */
protected mapVariableName(name: string): string;
/** Apply function name mapping if configured */
protected mapFunctionName(name: string): string;
/** Convert snake_case to camelCase */
private snakeToCamelCase;
/** Create error IR node */
protected createError(message: string, lineNumber?: number): IR;
/** Create warning IR node */
protected createWarning(message: string, lineNumber?: number): IR;
}
/** Utility functions for visitor implementations */
export declare const VisitorUtils: {
/** Check if assignment is simple (single target) */
isSimpleAssignment(node: PythonASTNode): boolean;
/** Check if node is a function call */
isFunctionCall(node: PythonASTNode): boolean;
/** Check if node is a print statement */
isPrintCall(node: PythonASTNode): boolean;
/** Check if node is an input statement */
isInputCall(node: PythonASTNode): boolean;
/** Check if node is an input call wrapped in type conversion (e.g., int(input())) */
isWrappedInputCall(node: PythonASTNode): boolean;
/** Extract input call from wrapped input (e.g., extract input() from int(input())) */
extractInputFromWrapped(node: PythonASTNode): PythonASTNode | null;
/** Check if node is a range call */
isRangeCall(node: PythonASTNode): boolean;
/** Extract function name from call node */
getFunctionName(node: PythonASTNode): string;
/** Extract variable name from assignment target */
getAssignmentTarget(node: PythonASTNode): string;
};
//# sourceMappingURL=base-visitor.d.ts.map