python2igcse
Version:
Convert Python code to IGCSE Pseudocode format
239 lines • 5.91 kB
TypeScript
import { IR } from './ir';
import { IGCSEDataType } from './igcse';
/**
* Parser configuration options
*/
export interface ParserOptions {
/** Enable debug mode */
debug?: boolean;
/** Strict type checking */
strictTypes?: boolean;
/** Strict mode */
strictMode?: boolean;
/** Preserve comments */
preserveComments?: boolean;
/** Include comments */
includeComments?: boolean;
/** Preserve whitespace */
preserveWhitespace?: boolean;
/** Indent size */
indentSize?: number;
/** Maximum nesting depth */
maxDepth?: number;
/** Maximum nesting depth */
maxNestingDepth?: number;
/** Maximum number of errors */
maxErrors?: number;
/** Timeout (milliseconds) */
timeout?: number;
/** Allow experimental syntax */
allowExperimentalSyntax?: boolean;
}
/**
* Parser result
*/
export interface ParseResult {
/** Generated IR */
ir: IR[];
/** Error messages */
errors: ParseError[];
/** Warning messages */
warnings: ParseWarning[];
/** Parse statistics */
stats: ParseStats;
/** Success flag */
success: boolean;
/** Parse time */
parseTime: number;
}
/**
* Parse error
*/
export interface ParseError {
/** Error message */
message: string;
/** Error type */
type: ParseErrorType;
/** Line number */
line?: number;
/** Column number */
column?: number;
/** Error severity */
severity: 'error' | 'warning';
}
/**
* Parse warning
*/
export interface ParseWarning {
/** Warning message */
message: string;
/** Warning type */
type: ParseWarningType;
/** Line number */
line?: number;
/** Column number */
column?: number;
}
/**
* Parse error types
*/
export type ParseErrorType = 'syntax_error' | 'type_error' | 'name_error' | 'unsupported_feature' | 'conversion_error' | 'validation_error';
/**
* Parse warning types
*/
export type ParseWarningType = 'type_inference' | 'implicit_conversion' | 'deprecated_syntax' | 'performance_hint' | 'style_suggestion';
/**
* Parse statistics
*/
export interface ParseStats {
/** Number of lines processed */
linesProcessed: number;
/** Number of generated IR nodes */
nodesGenerated: number;
/** Parse time (milliseconds) */
parseTime: number;
/** Number of functions detected */
functionsFound: number;
/** Number of classes detected */
classesFound: number;
/** Number of variables detected */
variablesFound: number;
}
/**
* Variable information
*/
export interface VariableInfo {
/** Variable name */
name: string;
/** Data type */
type: IGCSEDataType;
/** Scope */
scope: string;
/** Whether initialized */
initialized: boolean;
/** Line number where defined */
definedAt?: number | undefined;
}
/**
* Function information
*/
export interface FunctionInfo {
/** Function name */
name: string;
/** Parameter list */
parameters: ParameterInfo[];
/** Return type */
returnType?: IGCSEDataType | undefined;
/** Function or procedure */
isFunction: boolean;
/** Has return value */
hasReturn: boolean;
/** Line number where defined */
definedAt?: number | undefined;
}
/**
* Parameter information
*/
export interface ParameterInfo {
/** Parameter name */
name: string;
/** Data type */
type: IGCSEDataType;
/** Default value */
defaultValue?: string;
/** Whether passed by reference */
byReference?: boolean;
}
/**
* Scope information
*/
export interface ScopeInfo {
/** Scope name */
name: string;
/** Parent scope */
parent?: ScopeInfo;
/** Variable list */
variables: Map<string, VariableInfo>;
/** Function list */
functions: Map<string, FunctionInfo>;
/** Scope type */
type: ScopeType;
}
/**
* Scope types
*/
export type ScopeType = 'global' | 'function' | 'class' | 'block' | 'while' | 'for';
/**
* Position information
*/
export interface Position {
/** Line number (1-based) */
line: number;
/** Column number (1-based) */
column: number;
}
/**
* Range information
*/
export interface Range {
/** Start position */
start: Position;
/** End position */
end: Position;
}
/**
* Source location
*/
export interface SourceLocation {
/** File name */
filename?: string;
/** Range */
range: Range;
}
/**
* Parser context
*/
export interface ParserContext {
/** Current scope */
currentScope: ScopeInfo;
/** Scope stack */
scopeStack: ScopeInfo[];
/** Current function */
currentFunction?: FunctionInfo;
/** Current class */
currentClass?: string;
/** Indent level */
indentLevel: number;
/** Error list */
errors: ParseError[];
/** Warning list */
warnings: ParseWarning[];
/** Array information */
arrayInfo: {
[key: string]: {
size: number;
elementType: string;
currentIndex: number;
};
};
/** Parameter mapping (for constructors) */
parameterMapping: {
[key: string]: string;
};
/** Class definition information */
classDefinitions?: {
[key: string]: any;
};
/** Parse start time */
startTime: number;
/** Method to determine if it's a class */
isClass: (name: string) => boolean;
}
/**
* Parser helper functions
*/
export declare function createParseError(message: string, type: ParseErrorType, line?: number, column?: number, severity?: 'error' | 'warning'): ParseError;
export declare function createParseWarning(message: string, type: ParseWarningType, line?: number, column?: number): ParseWarning;
export declare function createPosition(line: number, column: number): Position;
export declare function createRange(start: Position, end: Position): Range;
//# sourceMappingURL=parser.d.ts.map