import { Rule } from "../../grammar/rule" ; import { getOrCreateMap } from "../../util" ; import { State } from "./state" ; export class StateToObjectMap < T , O > { private map : Map < Rule < T > , Map < number , Map < number , Map < number , O > > > > = new Map < Rule < T > , Map < number , Map < number , Map < number , O > > > > ( ) ; constructor ( ) { } put ( rule , position , ruleStartPosition , ruleDotPosition , value ) { getOrCreateMap ( getOrCreateMap ( getOrCreateMap ( this . map , rule ) , position ) , ruleStartPosition ) . set ( ruleDotPosition , value ) ; } has ( rule , position , ruleStartPosition , ruleDotPosition ) { return getOrCreateMap ( getOrCreateMap ( getOrCreateMap ( this . map , rule ) , position ) , ruleStartPosition ) . has ( ruleDotPosition ) ; } get ( rule , position , ruleStartPosition , ruleDotPosition ) { return getOrCreateMap ( getOrCreateMap ( getOrCreateMap ( this . map , rule ) , position ) , ruleStartPosition ) . get ( ruleDotPosition ) ; } putByState < S > ( state , value ) { this . put ( state . rule , state . position , state . ruleStartPosition , state . ruleDotPosition , value ) ; } getOrDefault < S > ( rule , position , ruleStartPosition , ruleDotPosition , _default ) { if ( this . has ( rule , position , ruleStartPosition , ruleDotPosition ) ) return this . get ( rule , position , ruleStartPosition , ruleDotPosition ) ; else return _default ; } getByStateOrDefault < S > ( state , _default ) { return this . getOrDefault ( state . rule , state . position , state . ruleStartPosition , state . ruleDotPosition , _default ) ; } getByState < S > ( state ) { return this . get ( state . rule , state . position , state . ruleStartPosition , state . ruleDotPosition ) ; } hasByState < S > ( state ) { return this . has ( state . rule , state . position , state . ruleStartPosition , state . ruleDotPosition ) ; } forEach ( f ) { this . map . forEach ( ( val , rule ) => { val . forEach ( ( val2 , position ) => { val2 . forEach ( ( val3 , start ) => { val3 . forEach ( ( object , dot ) => f ( position , start , dot , rule , object ) ) ; } ) ; } ) ; } ) ; } }