UNPKG

@prism-lang/core

Version:

A programming language for uncertainty

365 lines 13.9 kB
export type NodeType = 'Program' | 'IdentifierExpression' | 'NumberLiteral' | 'StringLiteral' | 'InterpolatedString' | 'BooleanLiteral' | 'NullLiteral' | 'UndefinedLiteral' | 'ArrayLiteral' | 'ObjectLiteral' | 'PropertyAccess' | 'OptionalChainAccess' | 'IndexAccess' | 'ConfidenceExpression' | 'BinaryExpression' | 'UnaryExpression' | 'CallExpression' | 'TernaryExpression' | 'ConfidentTernaryExpression' | 'LambdaExpression' | 'SpreadElement' | 'PlaceholderExpression' | 'AssignmentExpression' | 'BlockStatement' | 'IfStatement' | 'UncertainIfStatement' | 'ContextStatement' | 'AgentDeclaration' | 'AssignmentStatement' | 'ExpressionStatement' | 'ForLoop' | 'ForInLoop' | 'WhileLoop' | 'DoWhileLoop' | 'BreakStatement' | 'ContinueStatement' | 'UncertainForLoop' | 'UncertainWhileLoop' | 'ArrayPattern' | 'ObjectPattern' | 'RestElement' | 'DestructuringAssignment' | 'ImportStatement' | 'ExportStatement' | 'ImportSpecifier' | 'ExportSpecifier' | 'FunctionDeclaration' | 'ReturnStatement' | 'VariableDeclaration' | 'AwaitExpression'; export declare abstract class ASTNode { abstract type: NodeType; location?: { line: number; column: number; }; setLocation(line: number, column: number): this; } export declare abstract class Expression extends ASTNode { } export declare abstract class Statement extends ASTNode { } export declare class IdentifierExpression extends Expression { name: string; type: NodeType; constructor(name: string); } export declare class NumberLiteral extends Expression { value: number; type: NodeType; constructor(value: number); } export declare class StringLiteral extends Expression { value: string; type: NodeType; constructor(value: string); } export declare class InterpolatedString extends Expression { parts: string[]; expressions: Expression[]; type: NodeType; constructor(parts: string[], expressions: Expression[]); } export declare class BooleanLiteral extends Expression { value: boolean; type: NodeType; constructor(value: boolean); } export declare class NullLiteral extends Expression { type: NodeType; constructor(); } export declare class UndefinedLiteral extends Expression { type: NodeType; constructor(); } export declare class ConfidenceExpression extends Expression { expression: Expression; confidence: Expression; type: NodeType; constructor(expression: Expression, confidence: Expression); } export type BinaryOperator = '+' | '-' | '*' | '/' | '%' | '**' | '>' | '<' | '>=' | '<=' | '==' | '!=' | '===' | '!==' | '&&' | '||' | '??' | '|>' | '~>' | '~~' | '~??' | '~&&' | '~||' | '~||>' | '~@>' | '~|>' | '~?>' | '~+' | '~-' | '~*' | '~/' | '~==' | '~!=' | '~<' | '~>=' | '~<=' | '~.' | '.' | 'instanceof'; export declare class BinaryExpression extends Expression { operator: BinaryOperator; left: Expression; right: Expression; type: NodeType; constructor(operator: BinaryOperator, left: Expression, right: Expression); } export type UnaryOperator = '-' | '!' | '~' | '<~' | 'typeof'; export declare class UnaryExpression extends Expression { operator: UnaryOperator; operand: Expression; type: NodeType; constructor(operator: UnaryOperator, operand: Expression); } export declare class CallExpression extends Expression { callee: Expression; args: (Expression | SpreadElement)[]; type: NodeType; constructor(callee: Expression, args: (Expression | SpreadElement)[]); get arguments(): (Expression | SpreadElement)[]; } export declare class TernaryExpression extends Expression { condition: Expression; trueBranch: Expression; falseBranch: Expression; type: NodeType; constructor(condition: Expression, trueBranch: Expression, falseBranch: Expression); } export declare class ConfidentTernaryExpression extends Expression { condition: Expression; trueBranch: Expression; falseBranch: Expression; type: NodeType; constructor(condition: Expression, trueBranch: Expression, falseBranch: Expression); } export type LambdaParameter = string | ArrayPattern | ObjectPattern; export declare class LambdaExpression extends Expression { parameters: LambdaParameter[]; body: Expression | BlockStatement; restParameter?: (string | ArrayPattern | ObjectPattern) | undefined; type: NodeType; constructor(parameters: LambdaParameter[], body: Expression | BlockStatement, restParameter?: (string | ArrayPattern | ObjectPattern) | undefined); } export declare class ArrayLiteral extends Expression { elements: (Expression | SpreadElement | null)[]; type: NodeType; constructor(elements: (Expression | SpreadElement | null)[]); } export declare class ObjectLiteral extends Expression { properties: Array<{ key?: string; value: Expression | SpreadElement; }>; type: NodeType; constructor(properties: Array<{ key?: string; value: Expression | SpreadElement; }>); } export declare class SpreadElement extends Expression { argument: Expression; type: NodeType; constructor(argument: Expression); } export declare class PlaceholderExpression extends Expression { type: NodeType; constructor(); } export declare class AssignmentExpression extends Expression { identifier: string; value: Expression; type: NodeType; constructor(identifier: string, value: Expression); } export declare class AwaitExpression extends Expression { expression: Expression; type: NodeType; constructor(expression: Expression); } export declare class PropertyAccess extends Expression { object: Expression; property: string; type: NodeType; constructor(object: Expression, property: string); } export declare class OptionalChainAccess extends Expression { object: Expression; property: string; type: NodeType; constructor(object: Expression, property: string); } export declare class IndexAccess extends Expression { object: Expression; index: Expression; type: NodeType; constructor(object: Expression, index: Expression); } export declare class BlockStatement extends Statement { statements: Statement[]; type: NodeType; constructor(statements: Statement[]); } export declare class IfStatement extends Statement { condition: Expression; thenStatement: Statement; elseStatement?: Statement | undefined; type: NodeType; constructor(condition: Expression, thenStatement: Statement, elseStatement?: Statement | undefined); } export interface UncertainBranches { high?: Statement; medium?: Statement; low?: Statement; default?: Statement; } export declare class UncertainIfStatement extends Statement { condition: Expression; threshold: number; branches: UncertainBranches; type: NodeType; constructor(condition: Expression, threshold: number, branches: UncertainBranches); } export declare class ContextStatement extends Statement { contextName: string; body: Statement; shiftTo?: string | undefined; type: NodeType; constructor(contextName: string, body: Statement, shiftTo?: string | undefined); } export interface AgentConfig { confidence?: number; role?: string; capabilities?: string[]; } export declare class AgentDeclaration extends Statement { name: string; config: AgentConfig; type: NodeType; constructor(name: string, config: AgentConfig); } export declare class AssignmentStatement extends Statement { identifier: string; value: Expression; type: NodeType; constructor(identifier: string, value: Expression); } export declare class ExpressionStatement extends Statement { expression: Expression; type: NodeType; constructor(expression: Expression); } export declare class ForLoop extends Statement { init: Statement | null; condition: Expression | null; update: Expression | null; body: Statement; type: NodeType; constructor(init: Statement | null, condition: Expression | null, update: Expression | null, body: Statement); } export declare class ForInLoop extends Statement { variable: string; index: string | null; iterable: Expression; body: Statement; type: NodeType; constructor(variable: string, index: string | null, // Optional index variable iterable: Expression, body: Statement); } export declare class WhileLoop extends Statement { condition: Expression; body: Statement; type: NodeType; constructor(condition: Expression, body: Statement); } export declare class DoWhileLoop extends Statement { body: Statement; condition: Expression; type: NodeType; constructor(body: Statement, condition: Expression); } export declare class BreakStatement extends Statement { type: NodeType; constructor(); } export declare class ContinueStatement extends Statement { type: NodeType; constructor(); } export declare class UncertainForLoop extends Statement { init: Statement | null; condition: Expression | null; update: Expression | null; branches: UncertainBranches; type: NodeType; constructor(init: Statement | null, condition: Expression | null, update: Expression | null, branches: UncertainBranches); } export declare class UncertainWhileLoop extends Statement { condition: Expression; branches: UncertainBranches; type: NodeType; constructor(condition: Expression, branches: UncertainBranches); } export declare class Program extends ASTNode { statements: Statement[]; type: NodeType; constructor(statements: Statement[]); } export declare class ArrayPattern extends Expression { elements: (IdentifierExpression | ArrayPattern | ObjectPattern | RestElement | null)[]; elementThresholds?: (Expression | null)[] | undefined; type: NodeType; constructor(elements: (IdentifierExpression | ArrayPattern | ObjectPattern | RestElement | null)[], elementThresholds?: (Expression | null)[] | undefined); } export declare class ObjectPattern extends Expression { properties: Array<{ key: string; value: IdentifierExpression | ArrayPattern | ObjectPattern; defaultValue?: Expression; confidenceThreshold?: Expression; }>; rest?: RestElement | undefined; type: NodeType; constructor(properties: Array<{ key: string; value: IdentifierExpression | ArrayPattern | ObjectPattern; defaultValue?: Expression; confidenceThreshold?: Expression; }>, rest?: RestElement | undefined); } export declare class RestElement extends Expression { argument: IdentifierExpression; type: NodeType; constructor(argument: IdentifierExpression); } export declare class DestructuringAssignment extends Statement { pattern: ArrayPattern | ObjectPattern; value: Expression; confidenceThreshold?: Expression | undefined; type: NodeType; constructor(pattern: ArrayPattern | ObjectPattern, value: Expression, confidenceThreshold?: Expression | undefined); } export declare class ImportSpecifier extends ASTNode { imported: string; local?: string | undefined; type: NodeType; constructor(imported: string, // Name in the module local?: string | undefined); } export declare class ExportSpecifier extends ASTNode { local: string; exported?: string | undefined; type: NodeType; constructor(local: string, // Local name exported?: string | undefined); } export declare class ImportStatement extends Statement { specifiers: ImportSpecifier[]; source: string; defaultImport?: string | undefined; namespaceImport?: string | undefined; type: NodeType; constructor(specifiers: ImportSpecifier[], // Named imports source: string, // Module path defaultImport?: string | undefined, // Default import name namespaceImport?: string | undefined); } export declare class ExportStatement extends Statement { specifiers?: ExportSpecifier[] | undefined; source?: string | undefined; declaration?: Statement | undefined; isDefault?: boolean | undefined; isNamespace?: boolean | undefined; type: NodeType; constructor(specifiers?: ExportSpecifier[] | undefined, // Named exports source?: string | undefined, // Re-export source declaration?: Statement | undefined, // Direct export declaration isDefault?: boolean | undefined, // export default isNamespace?: boolean | undefined); } export declare class FunctionDeclaration extends Statement { name: string; parameters: LambdaParameter[]; body: BlockStatement; restParameter?: (string | ArrayPattern | ObjectPattern) | undefined; confidenceAnnotation?: Expression | undefined; isAsync: boolean; type: NodeType; constructor(name: string, // Function name parameters: LambdaParameter[], // Parameter list (reuse lambda parameter types) body: BlockStatement, // Function body (must be block) restParameter?: (string | ArrayPattern | ObjectPattern) | undefined, // Rest parameter confidenceAnnotation?: Expression | undefined, // Optional confidence annotation: function name() ~> 0.8 isAsync?: boolean); } export declare class ReturnStatement extends Statement { value?: Expression | undefined; type: NodeType; constructor(value?: Expression | undefined); } export declare class VariableDeclaration extends Statement { kind: 'const' | 'let'; identifier: string; initializer?: Expression | undefined; pattern?: (ArrayPattern | ObjectPattern) | undefined; type: NodeType; constructor(kind: 'const' | 'let', // Variable declaration kind identifier: string, // Variable name initializer?: Expression | undefined, // Optional initial value pattern?: (ArrayPattern | ObjectPattern) | undefined); } //# sourceMappingURL=ast.d.ts.map