import { Loc } from "../traverser/base" ; import { Token } from "./index" ; import { ContextualKeyword } from "./keywords" ; import { TokenType , TokenType as tt } from "./types" ; export class StateSnapshot { constructor ( readonly potentialArrowAt , readonly tokensLength , readonly pos , readonly type , readonly contextualKeyword , readonly start , readonly end , readonly isType , readonly error ) { } } export class ErrorWithPos { public pos : i32 = - 1 ; public loc : Loc | null = null ; constructor ( public message ) { } } export default class State { potentialArrowAt : i32 = - 1 ; tokens : Array < Token > = new Array < Token > ( 300000 ) ; pos : i32 = 0 ; type : TokenType = tt . eof ; contextualKeyword : ContextualKeyword = ContextualKeyword . NONE ; start : i32 = 0 ; end : i32 = 0 ; isType : boolean = false ; error : ErrorWithPos | null = null ; constructor ( ) { this . tokens . length = 0 ; } snapshot ( ) { return new StateSnapshot ( this . potentialArrowAt , this . tokens . length , this . pos , this . type , this . contextualKeyword , this . start , this . end , this . isType , this . error ) ; } restoreFromSnapshot ( snapshot ) { this . potentialArrowAt = snapshot . potentialArrowAt ; this . tokens . length = snapshot . tokensLength ; this . pos = snapshot . pos ; this . type = snapshot . type ; this . contextualKeyword = snapshot . contextualKeyword ; this . start = snapshot . start ; this . end = snapshot . end ; this . isType = snapshot . isType ; this . error = snapshot . error ; } }