import { setFlagsFromString } from "v8"; import G from "@cafetextual/util/dist/src/type/G"; /** * Mostly extracting methods to prevent circular dependancies with flexJS doesn't like */ export default class GrammarCompilerHelper { /** * Creates a vector, or reuses an existing one, then appends content of additional vectors to it */ static mergeTokens(existing:Array = null, v1:any = null, v2:any = null):Array { var out:Array = existing ? existing : new Array(); var s:string; if (v1) { if (G.isArr(v1)) { this.mergeArray(out, v1 as Array); } else if (G.isStr(v1) && (v1 as string).length > 0 && out.indexOf(v1) < 0) { out.push(v1); } } if (v2) { if (G.isArr(v2)) { this.mergeArray(out, v2 as Array); } else if (G.isStr(v2) && (v2 as string).length > 0 && out.indexOf(v2) < 0) { out.push(v2); } } return out; } // mergeTokens static mergeArray(out:Array, v:Array, backwards:boolean = false):void { if (backwards) { for (var i:number = v.length -1; i>=0;i--) { var sv:string = v[i]; if (out.indexOf(sv) < 0) { out.push(sv); } } } var s:string for (s of v) { if (out.indexOf(s) < 0) { out.push(s); } } } } // class