import IStepParser from "./IStepParser";
import Step from "./Step";

export default class StepFactory {

    public stepParser: IStepParser;

    constructor(stepParser: IStepParser) {
        this.stepParser = stepParser;
    }

    public createStep(text: string): Promise<Step> {
        if (text.length === 0) {
            return;
        }
        return this.stepParser.parseStepExpression(text).then((ast) => {
            return ast.buildNFA();
        }).then((nfa) => {
            return nfa.toDFA();
        }).then((dfa) => {
            return new Step(text, dfa);
        });
    }

}
