UNPKG

@prism-lang/core

Version:

A programming language for uncertainty

607 lines 16.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExportStatement = exports.ImportStatement = exports.ExportSpecifier = exports.ImportSpecifier = exports.DestructuringAssignment = exports.RestElement = exports.ObjectPattern = exports.ArrayPattern = exports.Program = exports.UncertainWhileLoop = exports.UncertainForLoop = exports.ContinueStatement = exports.BreakStatement = exports.DoWhileLoop = exports.WhileLoop = exports.ForInLoop = exports.ForLoop = exports.ExpressionStatement = exports.AssignmentStatement = exports.AgentDeclaration = exports.ContextStatement = exports.UncertainIfStatement = exports.IfStatement = exports.BlockStatement = exports.IndexAccess = exports.OptionalChainAccess = exports.PropertyAccess = exports.AwaitExpression = exports.AssignmentExpression = exports.PlaceholderExpression = exports.SpreadElement = exports.ObjectLiteral = exports.ArrayLiteral = exports.LambdaExpression = exports.ConfidentTernaryExpression = exports.TernaryExpression = exports.CallExpression = exports.UnaryExpression = exports.BinaryExpression = exports.ConfidenceExpression = exports.UndefinedLiteral = exports.NullLiteral = exports.BooleanLiteral = exports.InterpolatedString = exports.StringLiteral = exports.NumberLiteral = exports.IdentifierExpression = exports.Statement = exports.Expression = exports.ASTNode = void 0; exports.VariableDeclaration = exports.ReturnStatement = exports.FunctionDeclaration = void 0; class ASTNode { location; setLocation(line, column) { this.location = { line, column }; return this; } } exports.ASTNode = ASTNode; class Expression extends ASTNode { } exports.Expression = Expression; class Statement extends ASTNode { } exports.Statement = Statement; class IdentifierExpression extends Expression { name; type = 'IdentifierExpression'; constructor(name) { super(); this.name = name; } } exports.IdentifierExpression = IdentifierExpression; class NumberLiteral extends Expression { value; type = 'NumberLiteral'; constructor(value) { super(); this.value = value; } } exports.NumberLiteral = NumberLiteral; class StringLiteral extends Expression { value; type = 'StringLiteral'; constructor(value) { super(); this.value = value; } } exports.StringLiteral = StringLiteral; class InterpolatedString extends Expression { parts; expressions; type = 'InterpolatedString'; constructor(parts, expressions) { super(); this.parts = parts; this.expressions = expressions; } } exports.InterpolatedString = InterpolatedString; class BooleanLiteral extends Expression { value; type = 'BooleanLiteral'; constructor(value) { super(); this.value = value; } } exports.BooleanLiteral = BooleanLiteral; class NullLiteral extends Expression { type = 'NullLiteral'; constructor() { super(); } } exports.NullLiteral = NullLiteral; class UndefinedLiteral extends Expression { type = 'UndefinedLiteral'; constructor() { super(); } } exports.UndefinedLiteral = UndefinedLiteral; class ConfidenceExpression extends Expression { expression; confidence; type = 'ConfidenceExpression'; constructor(expression, confidence) { super(); this.expression = expression; this.confidence = confidence; } } exports.ConfidenceExpression = ConfidenceExpression; class BinaryExpression extends Expression { operator; left; right; type = 'BinaryExpression'; constructor(operator, left, right) { super(); this.operator = operator; this.left = left; this.right = right; } } exports.BinaryExpression = BinaryExpression; class UnaryExpression extends Expression { operator; operand; type = 'UnaryExpression'; constructor(operator, operand) { super(); this.operator = operator; this.operand = operand; } } exports.UnaryExpression = UnaryExpression; class CallExpression extends Expression { callee; args; type = 'CallExpression'; constructor(callee, args) { super(); this.callee = callee; this.args = args; } get arguments() { return this.args; } } exports.CallExpression = CallExpression; class TernaryExpression extends Expression { condition; trueBranch; falseBranch; type = 'TernaryExpression'; constructor(condition, trueBranch, falseBranch) { super(); this.condition = condition; this.trueBranch = trueBranch; this.falseBranch = falseBranch; } } exports.TernaryExpression = TernaryExpression; class ConfidentTernaryExpression extends Expression { condition; trueBranch; falseBranch; type = 'ConfidentTernaryExpression'; constructor(condition, trueBranch, falseBranch) { super(); this.condition = condition; this.trueBranch = trueBranch; this.falseBranch = falseBranch; } } exports.ConfidentTernaryExpression = ConfidentTernaryExpression; class LambdaExpression extends Expression { parameters; body; restParameter; type = 'LambdaExpression'; constructor(parameters, body, restParameter) { super(); this.parameters = parameters; this.body = body; this.restParameter = restParameter; } } exports.LambdaExpression = LambdaExpression; class ArrayLiteral extends Expression { elements; type = 'ArrayLiteral'; constructor(elements) { super(); this.elements = elements; } } exports.ArrayLiteral = ArrayLiteral; class ObjectLiteral extends Expression { properties; type = 'ObjectLiteral'; constructor(properties) { super(); this.properties = properties; } } exports.ObjectLiteral = ObjectLiteral; class SpreadElement extends Expression { argument; type = 'SpreadElement'; constructor(argument) { super(); this.argument = argument; } } exports.SpreadElement = SpreadElement; class PlaceholderExpression extends Expression { type = 'PlaceholderExpression'; constructor() { super(); } } exports.PlaceholderExpression = PlaceholderExpression; class AssignmentExpression extends Expression { identifier; value; type = 'AssignmentExpression'; constructor(identifier, value) { super(); this.identifier = identifier; this.value = value; } } exports.AssignmentExpression = AssignmentExpression; class AwaitExpression extends Expression { expression; type = 'AwaitExpression'; constructor(expression) { super(); this.expression = expression; } } exports.AwaitExpression = AwaitExpression; class PropertyAccess extends Expression { object; property; type = 'PropertyAccess'; constructor(object, property) { super(); this.object = object; this.property = property; } } exports.PropertyAccess = PropertyAccess; class OptionalChainAccess extends Expression { object; property; type = 'OptionalChainAccess'; constructor(object, property) { super(); this.object = object; this.property = property; } } exports.OptionalChainAccess = OptionalChainAccess; class IndexAccess extends Expression { object; index; type = 'IndexAccess'; constructor(object, index) { super(); this.object = object; this.index = index; } } exports.IndexAccess = IndexAccess; class BlockStatement extends Statement { statements; type = 'BlockStatement'; constructor(statements) { super(); this.statements = statements; } } exports.BlockStatement = BlockStatement; class IfStatement extends Statement { condition; thenStatement; elseStatement; type = 'IfStatement'; constructor(condition, thenStatement, elseStatement) { super(); this.condition = condition; this.thenStatement = thenStatement; this.elseStatement = elseStatement; } } exports.IfStatement = IfStatement; class UncertainIfStatement extends Statement { condition; threshold; branches; type = 'UncertainIfStatement'; constructor(condition, threshold, branches) { super(); this.condition = condition; this.threshold = threshold; this.branches = branches; } } exports.UncertainIfStatement = UncertainIfStatement; class ContextStatement extends Statement { contextName; body; shiftTo; type = 'ContextStatement'; constructor(contextName, body, shiftTo) { super(); this.contextName = contextName; this.body = body; this.shiftTo = shiftTo; } } exports.ContextStatement = ContextStatement; class AgentDeclaration extends Statement { name; config; type = 'AgentDeclaration'; constructor(name, config) { super(); this.name = name; this.config = config; } } exports.AgentDeclaration = AgentDeclaration; class AssignmentStatement extends Statement { identifier; value; type = 'AssignmentStatement'; constructor(identifier, value) { super(); this.identifier = identifier; this.value = value; } } exports.AssignmentStatement = AssignmentStatement; class ExpressionStatement extends Statement { expression; type = 'ExpressionStatement'; constructor(expression) { super(); this.expression = expression; } } exports.ExpressionStatement = ExpressionStatement; class ForLoop extends Statement { init; condition; update; body; type = 'ForLoop'; constructor(init, condition, update, body) { super(); this.init = init; this.condition = condition; this.update = update; this.body = body; } } exports.ForLoop = ForLoop; class ForInLoop extends Statement { variable; index; iterable; body; type = 'ForInLoop'; constructor(variable, index, // Optional index variable iterable, body) { super(); this.variable = variable; this.index = index; this.iterable = iterable; this.body = body; } } exports.ForInLoop = ForInLoop; class WhileLoop extends Statement { condition; body; type = 'WhileLoop'; constructor(condition, body) { super(); this.condition = condition; this.body = body; } } exports.WhileLoop = WhileLoop; class DoWhileLoop extends Statement { body; condition; type = 'DoWhileLoop'; constructor(body, condition) { super(); this.body = body; this.condition = condition; } } exports.DoWhileLoop = DoWhileLoop; class BreakStatement extends Statement { type = 'BreakStatement'; constructor() { super(); } } exports.BreakStatement = BreakStatement; class ContinueStatement extends Statement { type = 'ContinueStatement'; constructor() { super(); } } exports.ContinueStatement = ContinueStatement; class UncertainForLoop extends Statement { init; condition; update; branches; type = 'UncertainForLoop'; constructor(init, condition, update, branches) { super(); this.init = init; this.condition = condition; this.update = update; this.branches = branches; } } exports.UncertainForLoop = UncertainForLoop; class UncertainWhileLoop extends Statement { condition; branches; type = 'UncertainWhileLoop'; constructor(condition, branches) { super(); this.condition = condition; this.branches = branches; } } exports.UncertainWhileLoop = UncertainWhileLoop; class Program extends ASTNode { statements; type = 'Program'; constructor(statements) { super(); this.statements = statements; } } exports.Program = Program; // Pattern nodes for destructuring class ArrayPattern extends Expression { elements; elementThresholds; type = 'ArrayPattern'; constructor(elements, elementThresholds // Per-element thresholds (Option 3) ) { super(); this.elements = elements; this.elementThresholds = elementThresholds; } } exports.ArrayPattern = ArrayPattern; class ObjectPattern extends Expression { properties; rest; type = 'ObjectPattern'; constructor(properties, rest) { super(); this.properties = properties; this.rest = rest; } } exports.ObjectPattern = ObjectPattern; class RestElement extends Expression { argument; type = 'RestElement'; constructor(argument) { super(); this.argument = argument; } } exports.RestElement = RestElement; class DestructuringAssignment extends Statement { pattern; value; confidenceThreshold; type = 'DestructuringAssignment'; constructor(pattern, value, confidenceThreshold // For global threshold (Option 1) ) { super(); this.pattern = pattern; this.value = value; this.confidenceThreshold = confidenceThreshold; } } exports.DestructuringAssignment = DestructuringAssignment; // Import/Export system class ImportSpecifier extends ASTNode { imported; local; type = 'ImportSpecifier'; constructor(imported, // Name in the module local // Local name (for "as" renaming) ) { super(); this.imported = imported; this.local = local; } } exports.ImportSpecifier = ImportSpecifier; class ExportSpecifier extends ASTNode { local; exported; type = 'ExportSpecifier'; constructor(local, // Local name exported // Exported name (for "as" renaming) ) { super(); this.local = local; this.exported = exported; } } exports.ExportSpecifier = ExportSpecifier; class ImportStatement extends Statement { specifiers; source; defaultImport; namespaceImport; type = 'ImportStatement'; constructor(specifiers, // Named imports source, // Module path defaultImport, // Default import name namespaceImport // Namespace import name (import * as) ) { super(); this.specifiers = specifiers; this.source = source; this.defaultImport = defaultImport; this.namespaceImport = namespaceImport; } } exports.ImportStatement = ImportStatement; class ExportStatement extends Statement { specifiers; source; declaration; isDefault; isNamespace; type = 'ExportStatement'; constructor(specifiers, // Named exports source, // Re-export source declaration, // Direct export declaration isDefault, // export default isNamespace // export * ) { super(); this.specifiers = specifiers; this.source = source; this.declaration = declaration; this.isDefault = isDefault; this.isNamespace = isNamespace; } } exports.ExportStatement = ExportStatement; // Function Declaration and Return Statement class FunctionDeclaration extends Statement { name; parameters; body; restParameter; confidenceAnnotation; isAsync; type = 'FunctionDeclaration'; constructor(name, // Function name parameters, // Parameter list (reuse lambda parameter types) body, // Function body (must be block) restParameter, // Rest parameter confidenceAnnotation, // Optional confidence annotation: function name() ~> 0.8 isAsync = false // Whether the function is async ) { super(); this.name = name; this.parameters = parameters; this.body = body; this.restParameter = restParameter; this.confidenceAnnotation = confidenceAnnotation; this.isAsync = isAsync; } } exports.FunctionDeclaration = FunctionDeclaration; class ReturnStatement extends Statement { value; type = 'ReturnStatement'; constructor(value // Optional return value ) { super(); this.value = value; } } exports.ReturnStatement = ReturnStatement; // Variable Declaration with const/let support class VariableDeclaration extends Statement { kind; identifier; initializer; pattern; type = 'VariableDeclaration'; constructor(kind, // Variable declaration kind identifier, // Variable name initializer, // Optional initial value pattern // Optional destructuring pattern ) { super(); this.kind = kind; this.identifier = identifier; this.initializer = initializer; this.pattern = pattern; } } exports.VariableDeclaration = VariableDeclaration; //# sourceMappingURL=ast.js.map