From 16ee71ed87753ee2f9105eea967a15cd4e80a765 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 19 May 2019 16:48:31 +0800 Subject: [PATCH] build: generate dist for v1.0.0 --- dist/fas/combineStateOps.d.ts | 6 ++ dist/fas/combineStateOps.js | 32 ++++++++ dist/fas/dfa.d.ts | 3 +- dist/fas/epsilon.d.ts | 4 + dist/fas/epsilon.js | 10 +++ dist/fas/nfa.d.ts | 2 +- dist/fas/state.d.ts | 32 +------- dist/fas/state.js | 146 ++------------------------------- dist/fas/stateOps.d.ts | 26 ++++++ dist/fas/stateOps.js | 150 ++++++++++++++++++++++++++++++++++ dist/index.d.ts | 8 +- dist/index.js | 35 ++++---- 12 files changed, 265 insertions(+), 189 deletions(-) create mode 100644 dist/fas/combineStateOps.d.ts create mode 100644 dist/fas/combineStateOps.js create mode 100644 dist/fas/epsilon.d.ts create mode 100644 dist/fas/epsilon.js create mode 100644 dist/fas/stateOps.d.ts create mode 100644 dist/fas/stateOps.js diff --git a/dist/fas/combineStateOps.d.ts b/dist/fas/combineStateOps.d.ts new file mode 100644 index 0000000..8673abc --- /dev/null +++ b/dist/fas/combineStateOps.d.ts @@ -0,0 +1,6 @@ +import { StateOp } from './stateOps'; +export declare function concatMultipleStates(...states: StateOp[]): StateOp; +export declare function unionMultipleStates({ states, accepted }: { + states: StateOp[]; + accepted?: boolean; +}): StateOp; diff --git a/dist/fas/combineStateOps.js b/dist/fas/combineStateOps.js new file mode 100644 index 0000000..e17ceda --- /dev/null +++ b/dist/fas/combineStateOps.js @@ -0,0 +1,32 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var stateOps_1 = require("./stateOps"); +function concatMultipleStates() { + var states = []; + for (var _i = 0; _i < arguments.length; _i++) { + states[_i] = arguments[_i]; + } + if (states.length === 0) { + throw new Error('Argument must be at least one state'); + } + if (states.length === 1) { + return states[0]; + } + return states.reduce(function (stateA, stateB) { + return new stateOps_1.ConcatState(stateA, stateB); + }); +} +exports.concatMultipleStates = concatMultipleStates; +function unionMultipleStates(_a) { + var states = _a.states, _b = _a.accepted, accepted = _b === void 0 ? false : _b; + if (states.length === 0) { + throw new Error('Argument must be at least one state'); + } + if (states.length === 1) { + return states[0]; + } + return states.reduce(function (stateA, stateB, currentIndex) { + return new stateOps_1.UnionState(stateA, stateB, (currentIndex === states.length - 1) && accepted); + }); +} +exports.unionMultipleStates = unionMultipleStates; diff --git a/dist/fas/dfa.d.ts b/dist/fas/dfa.d.ts index 5381e31..6cb8de2 100644 --- a/dist/fas/dfa.d.ts +++ b/dist/fas/dfa.d.ts @@ -1,4 +1,5 @@ -import { State, Epsilon } from './state'; +import { State } from './state'; +import { Epsilon } from './epsilon'; export declare class DFAStatesSet { states: Set; private nextStatesSetMap; diff --git a/dist/fas/epsilon.d.ts b/dist/fas/epsilon.d.ts new file mode 100644 index 0000000..c45b85f --- /dev/null +++ b/dist/fas/epsilon.d.ts @@ -0,0 +1,4 @@ +export declare class Epsilon { +} +declare const epsilon: Epsilon; +export default epsilon; diff --git a/dist/fas/epsilon.js b/dist/fas/epsilon.js new file mode 100644 index 0000000..cf18c76 --- /dev/null +++ b/dist/fas/epsilon.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Epsilon = /** @class */ (function () { + function Epsilon() { + } + return Epsilon; +}()); +exports.Epsilon = Epsilon; +var epsilon = new Epsilon(); +exports.default = epsilon; diff --git a/dist/fas/nfa.d.ts b/dist/fas/nfa.d.ts index a627172..d30ff1b 100644 --- a/dist/fas/nfa.d.ts +++ b/dist/fas/nfa.d.ts @@ -1,4 +1,4 @@ -import { StateOp } from './state'; +import { StateOp } from './stateOps'; import { DFA } from './dfa'; export declare class NFA { private stateOp; diff --git a/dist/fas/state.d.ts b/dist/fas/state.d.ts index a5edced..fd1a20a 100644 --- a/dist/fas/state.d.ts +++ b/dist/fas/state.d.ts @@ -1,7 +1,5 @@ -export declare class Epsilon { -} -export declare const epsilon: Epsilon; -declare type InputType = string | Epsilon; +import { Epsilon } from './epsilon'; +export declare type InputType = string | Epsilon; export declare class State { nextStatesMap: Map>; private accepted; @@ -11,29 +9,3 @@ export declare class State { isAccepted(): boolean; epsilonClosure(): Set; } -export declare class StateOp { - protected start: State | null; - protected end: State | null; - constructor(); - getStartState(): State | null; - getEndState(): State | null; - setNext(input: InputType, state: StateOp): void; -} -export declare class SingleInputState extends StateOp { - constructor(input: InputType, accepted?: boolean); -} -export declare class ConcatState extends StateOp { - private a; - private b; - constructor(a: StateOp, b: StateOp); -} -export declare class UnionState extends StateOp { - private a; - private b; - constructor(a: StateOp, b: StateOp, accepted?: boolean); -} -export declare class ClosureState extends StateOp { - private a; - constructor(a: StateOp, accepted?: boolean); -} -export {}; diff --git a/dist/fas/state.js b/dist/fas/state.js index 8b4ef99..b9ef47a 100644 --- a/dist/fas/state.js +++ b/dist/fas/state.js @@ -1,17 +1,4 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); var __values = (this && this.__values) || function (o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); @@ -22,15 +9,12 @@ var __values = (this && this.__values) || function (o) { } }; }; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", { value: true }); var utils_1 = require("../utils"); -var Epsilon = /** @class */ (function () { - function Epsilon() { - } - return Epsilon; -}()); -exports.Epsilon = Epsilon; -exports.epsilon = new Epsilon(); +var epsilon_1 = __importDefault(require("./epsilon")); var State = /** @class */ (function () { function State(accepted, alias) { if (accepted === void 0) { accepted = false; } @@ -56,7 +40,7 @@ var State = /** @class */ (function () { var e_1, _a; var epsilonSet = new Set(); epsilonSet.add(this); - var epsilonStates = this.nextStatesMap.get(exports.epsilon); + var epsilonStates = this.nextStatesMap.get(epsilon_1.default); if (epsilonStates) { utils_1.mergeSetInto(epsilonSet, epsilonStates); try { @@ -78,123 +62,3 @@ var State = /** @class */ (function () { return State; }()); exports.State = State; -var StateOp = /** @class */ (function () { - function StateOp() { - this.start = null; - this.end = null; - } - StateOp.prototype.getStartState = function () { - return this.start; - }; - StateOp.prototype.getEndState = function () { - return this.end; - }; - StateOp.prototype.setNext = function (input, state) { - var start = state.getStartState(); - if (start && this.end) { - this.end.setNext(input, start); - } - else if (!start) { - throw new Error('Start state of param state is null'); - } - else if (!this.end) { - throw new Error('this.end is null'); - } - }; - return StateOp; -}()); -exports.StateOp = StateOp; -var SingleInputState = /** @class */ (function (_super) { - __extends(SingleInputState, _super); - function SingleInputState(input, accepted) { - if (accepted === void 0) { accepted = false; } - var _this = _super.call(this) || this; - _this.start = new State(); - _this.end = new State(accepted); - _this.start.setNext(input, _this.end); - return _this; - } - return SingleInputState; -}(StateOp)); -exports.SingleInputState = SingleInputState; -var ConcatState = /** @class */ (function (_super) { - __extends(ConcatState, _super); - function ConcatState(a, b) { - var _this = _super.call(this) || this; - _this.a = a; - _this.b = b; - _this.start = _this.a.getStartState(); - _this.a.setNext(exports.epsilon, _this.b); - _this.end = _this.b.getEndState(); - return _this; - } - return ConcatState; -}(StateOp)); -exports.ConcatState = ConcatState; -var UnionState = /** @class */ (function (_super) { - __extends(UnionState, _super); - function UnionState(a, b, accepted) { - var e_2, _a; - if (accepted === void 0) { accepted = false; } - var _this = _super.call(this) || this; - _this.a = a; - _this.b = b; - _this.start = new State(); - _this.end = new State(accepted); - try { - for (var _b = __values([_this.a, _this.b]), _c = _b.next(); !_c.done; _c = _b.next()) { - var arg = _c.value; - var argOpStart = arg.getStartState(); - var argOpEnd = arg.getEndState(); - if (argOpStart) { - _this.start.setNext(exports.epsilon, argOpStart); - } - else { - throw new Error('start of argOp is null'); - } - if (argOpEnd) { - argOpEnd.setNext(exports.epsilon, _this.end); - } - else { - throw new Error('end of argOp is null'); - } - } - } - catch (e_2_1) { e_2 = { error: e_2_1 }; } - finally { - try { - if (_c && !_c.done && (_a = _b.return)) _a.call(_b); - } - finally { if (e_2) throw e_2.error; } - } - return _this; - } - return UnionState; -}(StateOp)); -exports.UnionState = UnionState; -var ClosureState = /** @class */ (function (_super) { - __extends(ClosureState, _super); - function ClosureState(a, accepted) { - if (accepted === void 0) { accepted = false; } - var _this = _super.call(this) || this; - _this.a = a; - _this.start = new State(); - _this.end = new State(accepted); - var aStart = _this.a.getStartState(); - var aEnd = _this.a.getEndState(); - if (aStart) { - _this.start.setNext(exports.epsilon, aStart); - } - else { - throw new Error('start of a is null'); - } - _this.start.setNext(exports.epsilon, _this.end); - if (aEnd) { - aEnd.setNext(exports.epsilon, _this.end); - aEnd.setNext(exports.epsilon, _this.start); - } - return _this; - } - return ClosureState; -}(StateOp)); -exports.ClosureState = ClosureState; diff --git a/dist/fas/stateOps.d.ts b/dist/fas/stateOps.d.ts new file mode 100644 index 0000000..568f104 --- /dev/null +++ b/dist/fas/stateOps.d.ts @@ -0,0 +1,26 @@ +import { State, InputType } from './state'; +export declare class StateOp { + protected start: State | null; + protected end: State | null; + constructor(); + getStartState(): State | null; + getEndState(): State | null; + setNext(input: InputType, state: StateOp): void; +} +export declare class SingleInputState extends StateOp { + constructor(input: InputType, accepted?: boolean); +} +export declare class ConcatState extends StateOp { + private a; + private b; + constructor(a: StateOp, b: StateOp); +} +export declare class UnionState extends StateOp { + private a; + private b; + constructor(a: StateOp, b: StateOp, accepted?: boolean); +} +export declare class ClosureState extends StateOp { + private a; + constructor(a: StateOp, accepted?: boolean); +} diff --git a/dist/fas/stateOps.js b/dist/fas/stateOps.js new file mode 100644 index 0000000..e1fdbc0 --- /dev/null +++ b/dist/fas/stateOps.js @@ -0,0 +1,150 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __values = (this && this.__values) || function (o) { + var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; + if (m) return m.call(o); + return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var state_1 = require("./state"); +var epsilon_1 = __importDefault(require("./epsilon")); +var StateOp = /** @class */ (function () { + function StateOp() { + this.start = null; + this.end = null; + } + StateOp.prototype.getStartState = function () { + return this.start; + }; + StateOp.prototype.getEndState = function () { + return this.end; + }; + StateOp.prototype.setNext = function (input, state) { + var start = state.getStartState(); + if (start && this.end) { + this.end.setNext(input, start); + } + else if (!start) { + throw new Error('Start state of param state is null'); + } + else if (!this.end) { + throw new Error('this.end is null'); + } + }; + return StateOp; +}()); +exports.StateOp = StateOp; +var SingleInputState = /** @class */ (function (_super) { + __extends(SingleInputState, _super); + function SingleInputState(input, accepted) { + if (accepted === void 0) { accepted = false; } + var _this = _super.call(this) || this; + _this.start = new state_1.State(); + _this.end = new state_1.State(accepted); + _this.start.setNext(input, _this.end); + return _this; + } + return SingleInputState; +}(StateOp)); +exports.SingleInputState = SingleInputState; +var ConcatState = /** @class */ (function (_super) { + __extends(ConcatState, _super); + function ConcatState(a, b) { + var _this = _super.call(this) || this; + _this.a = a; + _this.b = b; + _this.start = _this.a.getStartState(); + _this.a.setNext(epsilon_1.default, _this.b); + _this.end = _this.b.getEndState(); + return _this; + } + return ConcatState; +}(StateOp)); +exports.ConcatState = ConcatState; +var UnionState = /** @class */ (function (_super) { + __extends(UnionState, _super); + function UnionState(a, b, accepted) { + var e_1, _a; + if (accepted === void 0) { accepted = false; } + var _this = _super.call(this) || this; + _this.a = a; + _this.b = b; + _this.start = new state_1.State(); + _this.end = new state_1.State(accepted); + try { + for (var _b = __values([_this.a, _this.b]), _c = _b.next(); !_c.done; _c = _b.next()) { + var arg = _c.value; + var argOpStart = arg.getStartState(); + var argOpEnd = arg.getEndState(); + if (argOpStart) { + _this.start.setNext(epsilon_1.default, argOpStart); + } + else { + throw new Error('start of argOp is null'); + } + if (argOpEnd) { + argOpEnd.setNext(epsilon_1.default, _this.end); + } + else { + throw new Error('end of argOp is null'); + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_1) throw e_1.error; } + } + return _this; + } + return UnionState; +}(StateOp)); +exports.UnionState = UnionState; +var ClosureState = /** @class */ (function (_super) { + __extends(ClosureState, _super); + function ClosureState(a, accepted) { + if (accepted === void 0) { accepted = false; } + var _this = _super.call(this) || this; + _this.a = a; + _this.start = new state_1.State(); + _this.end = new state_1.State(accepted); + var aStart = _this.a.getStartState(); + var aEnd = _this.a.getEndState(); + if (aStart) { + _this.start.setNext(epsilon_1.default, aStart); + } + else { + throw new Error('start of a is null'); + } + _this.start.setNext(epsilon_1.default, _this.end); + if (aEnd) { + aEnd.setNext(epsilon_1.default, _this.end); + aEnd.setNext(epsilon_1.default, _this.start); + } + return _this; + } + return ClosureState; +}(StateOp)); +exports.ClosureState = ClosureState; diff --git a/dist/index.d.ts b/dist/index.d.ts index cb0ff5c..1d7512d 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1 +1,7 @@ -export {}; +import * as stateOps from './fas/stateOps'; +export { stateOps }; +export * from './fas/combineStateOps'; +export { State } from './fas/state'; +export { default as epsilon } from './fas/epsilon'; +export { NFA } from './fas/nfa'; +export { DFA, DFAStatesSet } from './fas/dfa'; diff --git a/dist/index.js b/dist/index.js index d3eb90e..ff7ab6e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,19 +1,24 @@ "use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); +var stateOps = __importStar(require("./fas/stateOps")); +exports.stateOps = stateOps; +__export(require("./fas/combineStateOps")); var state_1 = require("./fas/state"); +exports.State = state_1.State; +var epsilon_1 = require("./fas/epsilon"); +exports.epsilon = epsilon_1.default; var nfa_1 = require("./fas/nfa"); -// (1|0)*1 -var one = new state_1.SingleInputState('1'); -var zero = new state_1.SingleInputState('0'); -var oneOrZero = new state_1.UnionState(one, zero); -var oneOrZeroStar = new state_1.ClosureState(oneOrZero); -var final = new state_1.ConcatState(oneOrZeroStar, new state_1.SingleInputState('1', true)); -var dfa = new nfa_1.NFA(final).toDFA(); -console.log(dfa.test('1')); -console.log('-------------', dfa.test('00000000001')); -console.log('-------------', dfa.test('10101010000101')); -console.log('-------------', dfa.test('01010011000101011')); -console.log('-------------', dfa.test('010100110001010110')); -console.log('-------------', dfa.test('')); -console.log('-------------', dfa.test('0000000000000000')); -console.log('-------------', dfa.test('11111111111')); +exports.NFA = nfa_1.NFA; +var dfa_1 = require("./fas/dfa"); +exports.DFA = dfa_1.DFA; +exports.DFAStatesSet = dfa_1.DFAStatesSet;