public override void Build(Parser parser, ParserBuindEnv env) { Parser element = env.GetParser(Element); Parser seperator = env.GetParser(Seperator); parser.Fill(new Parser[] { element, seperator }); }
public static Parser CreateProgramParser() { ParserBuindEnv env = new ParserBuindEnv(); #region expr env.AddBuilder("lambda", ASTNode(Lambda.Factory, Seq(Fork("params").Or(ASTNode(Params.Factory, "name"))).Then(Skip(Id("=>"))).Then("stmt"))); env.AddBuilder("params", ASTNode(Params.Factory, Seq(Skip(Id("("))).Then(Optional(Seq("name").Then(Optional(Repeat(Seq(Skip(Id(","))).Then("name")))).Then(Optional(Skip(Id(",")))))).Then(Skip(Id(")"))))); env.AddBuilder("valuable", Fork("branch").Or("loop").Or("assignment").Or("expr")); env.AddBuilder("branch", ASTNode(Branch.Factory, Seq("expr").Then(Skip(Id("?"))).Then("stmt").Then(Optional(Seq(Skip(Id(":"))).Then("stmt"))))); env.AddBuilder("loop", ASTNode(Loop.Factory, Seq("expr").Then(Skip(Id("~"))).Then("stmt"))); env.AddBuilder("name", Token(Name.Factory, "name")); env.AddBuilder("delay", ASTNode(Delay.Factory, Seq("name").Then(Id("++", "--")))); env.AddBuilder("closedExpr", Seq(Skip(Id("("))).Then("valuable").Then(Skip(Id(")")))); env.AddBuilder("expr", ASTNode(Calc.Factory, Seq("boollet").Then(Optional(Repeat(Seq(Id("&&", "||")).Then("boollet")))))); env.AddBuilder("boollet", ASTNode(Calc.Factory, Seq("comlet").Then(Optional(Repeat(Seq(Id(">", "<", ">=", "<=", "==", "!=")).Then("comlet")))))); env.AddBuilder("comlet", ASTNode(Calc.Factory, Seq("term").Then(Optional(Repeat(Seq(Id("+", "-", "..")).Then("term")))))); env.AddBuilder("term", ASTNode(Calc.Factory, Seq("factor").Then(Optional(Repeat(Seq(Id("*", "/")).Then("factor")))))); env.AddBuilder("factor", Fork("prefixed").Or("lambda").Or("chain").Or("closedExpr").Or("delay").Or("name").Or(Token("decimal")).Or(Token("digit")).Or(Token("string"))); env.AddBuilder("prefixed", ASTNode(Prefixed.Factory, Seq(Id("+", "-", "!")).Then("factor"))); #endregion #region suffix env.AddBuilder("chain", ASTNode(Chain.Factory, Seq(Fork("closedExpr").Or("name")).Then(Repeat("suffix")))); env.AddBuilder("suffix", Fork("arguments").Or("dot").Or("index")); env.AddBuilder("dot", ASTNode(Dot.Factory, Seq(Skip(Id("."))).Then("name"))); env.AddBuilder("index", ASTNode(Index.Factory, Seq(Skip(Id("["))).Then("valuable").Then(Skip(Id("]"))))); env.AddBuilder("arguments", ASTNode(Arguments.Factory, Seq(Skip(Id("("))).Then(Optional(Seq("valuable").Then(Optional(Repeat(Seq(Skip(Id(","))).Then("valuable")))).Then(Optional(Skip(Id(",")))))).Then(Skip(Id(")"))))); #endregion #region stmts env.AddBuilder("stmts", ASTNode(Stmts.Factory, Seq("stmt").Then(Optional(Repeat(Seq(Skip(Id(";"))).Then("stmt")))).Then(Optional(Skip(Id(";")))))); env.AddBuilder("stmt", Fork("block").Or("command").Or("valuable")); env.AddBuilder("command", ASTNode(Command.Factory, Seq(Skip(Id("/"))).Then("name").Then(Optional(Repeat("cmdArg"))))); env.AddBuilder("cmdArg", Fork(Seq(Skip(Id("$"))).Then(Token(CmdVar.Factory, "name"))).Or(Token(ConstString.Factory, "name")).Or("valuable")); env.AddBuilder("block", ASTNode(Block.Factory, Seq(Skip(Id("{"))).Then("stmts").Then(Skip(Id("}"))))); env.AddBuilder("assignment", ASTNode(Assignment.Factory, Seq(Fork("chain").Or("name")).Then(Skip(Id("="))).Then("stmt"))); #endregion env.Build(); return(env.GetParser("stmts")); }