You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
typesetting/pitfall/pdfkit/node_modules/dfa/index.js.map

1 line
4.0 KiB
Plaintext

{"version":3,"file":null,"sources":["src/StateMachine.js"],"sourcesContent":["const INITIAL_STATE = 1;\nconst FAIL_STATE = 0;\n\n/**\n * A StateMachine represents a deterministic finite automaton.\n * It can perform matches over a sequence of values, similar to a regular expression.\n */\nexport default class StateMachine {\n constructor(dfa) {\n this.stateTable = dfa.stateTable;\n this.accepting = dfa.accepting;\n this.tags = dfa.tags;\n }\n\n /**\n * Returns an iterable object that yields pattern matches over the input sequence.\n * Matches are of the form [startIndex, endIndex, tags].\n */\n match(str) {\n let self = this;\n return {\n *[Symbol.iterator]() {\n let state = INITIAL_STATE;\n let startRun = null;\n let lastAccepting = null;\n let lastState = null;\n\n for (let p = 0; p < str.length; p++) {\n let c = str[p];\n\n lastState = state;\n state = self.stateTable[state][c];\n\n if (state === FAIL_STATE) {\n // yield the last match if any\n if (startRun != null && lastAccepting != null && lastAccepting >= startRun) {\n yield [startRun, lastAccepting, self.tags[lastState]];\n }\n\n // reset the state as if we started over from the initial state\n state = self.stateTable[INITIAL_STATE][c];\n startRun = null;\n }\n\n // start a run if not in the failure state\n if (state !== FAIL_STATE && startRun == null) {\n startRun = p;\n }\n\n // if accepting, mark the potential match end\n if (self.accepting[state]) {\n lastAccepting = p;\n }\n\n // reset the state to the initial state if we get into the failure state\n if (state === FAIL_STATE) {\n state = INITIAL_STATE;\n }\n }\n\n // yield the last match if any\n if (startRun != null && lastAccepting != null && lastAccepting >= startRun) {\n yield [startRun, lastAccepting, self.tags[state]];\n }\n }\n };\n }\n\n /**\n * For each match over the input sequence, action functions matching\n * the tag definitions in the input pattern are called with the startIndex,\n * endIndex, and sub-match sequence.\n */\n apply(str, actions) {\n for (let [start, end, tags] of this.match(str)) {\n for (let tag of tags) {\n if (typeof actions[tag] === 'function') {\n actions[tag](start, end, str.slice(start, end + 1));\n }\n }\n }\n }\n}\n"],"names":["INITIAL_STATE","FAIL_STATE","StateMachine","dfa","stateTable","accepting","tags","str","self","p","length","state","c","startRun","lastAccepting","lastState","actions","match","start","end","tag","slice"],"mappings":";;;;;;;;;;;;AAAA,IAAMA,gBAAgB,CAAtB;AACA,IAAMC,aAAa,CAAnB;;;;;;;IAMqBC;wBACPC,GAAZ,EAAiB;;;SACVC,UAAL,GAAkBD,IAAIC,UAAtB;SACKC,SAAL,GAAiBF,IAAIE,SAArB;SACKC,IAAL,GAAYH,IAAIG,IAAhB;;;;;;;;;;;0BAOIC,KAAK;UACLC,OAAO,IAAX;;;;;;;qBACA,GAEgBR,aAFhB;wBAAA,GAGmB,IAHnB;6BAAA,GAIwB,IAJxB;yBAAA,GAKoB,IALpB;iBAAA,GAOiB,CAPjB;;;sBAOoBS,IAAIF,IAAIG,MAP5B;;;;;iBAAA,GAQcH,IAAIE,CAAJ,CARd;;;4BAUkBE,KAAZ;wBACQH,KAAKJ,UAAL,CAAgBO,KAAhB,EAAuBC,CAAvB,CAAR;;sBAEID,UAAUV,UAbpB;;;;;sBAeYY,YAAY,IAAZ,IAAoBC,iBAAiB,IAArC,IAA6CA,iBAAiBD,QAf1E;;;;;;uBAgBgB,CAACA,QAAD,EAAWC,aAAX,EAA0BN,KAAKF,IAAL,CAAUS,SAAV,CAA1B,CAhBhB;;;;;wBAoBgBP,KAAKJ,UAAL,CAAgBJ,aAAhB,EAA+BY,CAA/B,CAAR;2BACW,IAAX;;;;;oBAIED,UAAUV,UAAV,IAAwBY,YAAY,IAAxC,EAA8C;6BACjCJ,CAAX;;;;oBAIED,KAAKH,SAAL,CAAeM,KAAf,CAAJ,EAA2B;kCACTF,CAAhB;;;;oBAIEE,UAAUV,UAAd,EAA0B;0BAChBD,aAAR;;;;mBApCR;;;;;sBAyCQa,YAAY,IAAZ,IAAoBC,iBAAiB,IAArC,IAA6CA,iBAAiBD,QAzCtE;;;;;;uBA0CY,CAACA,QAAD,EAAWC,aAAX,EAA0BN,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