import { LSTypes } from "./constants" ; import { Token } from "../structures/token" ; import { FuncArgs } from "../functions/function" ; import { Expr , Variable } from "../expressions/expr" ; export interface Visitor < T > { visitBlockStmt : ( stmt : Block ) => T ; visitClassStmt : ( stmt : Class ) => T ; visitExpressionStmt : ( stmt : Expression ) => T ; visitFuncStmt : ( stmt : Func ) => T ; visitIfStmt : ( stmt : If ) => T ; visitImportStmt : ( stmt : Import ) => T ; visitReturnStmt : ( stmt : Return ) => T ; visitVarStmt : ( stmt : Var ) => T ; visitWhileStmt : ( stmt : While ) => T ; } export type Stmt = Block | Class | Expression | Func | If | Import | Return | Var | While ; export class Block { statements : Stmt [ ] ; constructor ( statements ) { this . statements = statements ; } accept < T > ( visitor ) { return visitor . visitBlockStmt ( this ) ; } } export class Class { name : Token ; methods : Func [ ] ; superclass : null | Variable ; constructor ( name , superclass , methods ) { this . name = name ; this . methods = methods ; this . superclass = superclass ; } accept < T > ( visitor ) { return visitor . visitClassStmt ( this ) ; } } export class Expression { expression : Expr ; constructor ( expression ) { this . expression = expression ; } accept < T > ( visitor ) { return visitor . visitExpressionStmt ( this ) ; } } export class Func { name : Token ; body : Stmt [ ] ; params : FuncArgs [ ] ; overridden : boolean ; returntypes : LSTypes [ ] ; constructor ( name , params , returntypes , body , overridden = false ) { this . name = name ; this . body = body ; this . params = params ; this . overridden = overridden ; this . returntypes = returntypes ; } accept < T > ( visitor ) { return visitor . visitFuncStmt ( this ) ; } } export class If { condition : Expr ; thenBranch : Stmt ; elseBranch : Stmt | null ; constructor ( condition , thenBranch , elseBranch ) { this . condition = condition ; this . thenBranch = thenBranch ; this . elseBranch = elseBranch ; } accept < T > ( visitor ) { return visitor . visitIfStmt ( this ) ; } } export class Import { module : Token ; name : Token ; constructor ( module , name ) { this . module = module ; this . name = name ; } accept < T > ( visitor ) { return visitor . visitImportStmt ( this ) ; } } export class Return { keyword : Token ; value : Expr | null ; constructor ( keyword , value ) { this . keyword = keyword ; this . value = value ; } accept < T > ( visitor ) { return visitor . visitReturnStmt ( this ) ; } } export class Var { name : Token ; value : Token | null ; types : LSTypes [ ] ; constant : boolean ; initializer : Expr | null ; constructor ( name , value , constant , types , initializer ) { this . name = name ; this . value = value ; this . types = types ; this . constant = constant ; this . initializer = initializer ; } accept < T > ( visitor ) { return visitor . visitVarStmt ( this ) ; } } export class While { condition : Expr ; body : Stmt ; constructor ( condition , body ) { this . condition = condition ; this . body = body ; } accept < T > ( visitor ) { return visitor . visitWhileStmt ( this ) ; } }