Beispiel #1
0
        static Interpolate()
        {
            // Parser for a text block
            var text = from s in asString(many1(attempt(satisfy(c => c != '{'))))
                       select ScriptExpr.ConstString(s);

            // Parser for the interpolation block
            var format = from o in ch('{')
                         from s in asString(many1(attempt(satisfy(c => c != '}'))))
                         from c in ch('}')
                         from d in ScriptParser.Parse(s)
                         .Match(
                Right: dsl => result(dsl),
                Left: e => failure <ScriptExpr>(e))
                         select d;

            // Parser for many blocks
            var blocks = many(attempt(choice(attempt(text), format)));

            // Final parser which does some post processing on the blocks
            Parser = from b in blocks
                     from _ in eof
                     select b.IsEmpty
                        ? ScriptExpr.ConstString("")
                        : b.Tail.IsEmpty && b.Head is StringConstExpr
                            ? b.Head
                            : ScriptExpr.InterpString(b);
        }
Beispiel #2
0
 public FailExpr(ScriptExpr expr) => Expr = expr;
Beispiel #3
0
 /// <summary>
 /// Helper function for taking the tree expression that you get with comma
 /// separated values and flattens them inta Seq of ScriptExprs.
 /// </summary>
 static Seq <ScriptExpr> FlattenTuple(ScriptExpr expr) =>
 expr is TupleExpr tuple
Beispiel #4
0
 public static ScriptExpr Log(ScriptExpr expr) => new LogExpr(expr);
Beispiel #5
0
 public static ScriptExpr Fail(ScriptExpr expr) => new FailExpr(expr);
Beispiel #6
0
 public static ScriptExpr Parens(ScriptExpr expr) => new ParensExpr(expr);
Beispiel #7
0
 public static ScriptExpr Postfix(ScriptExpr expr, string @operator) => new UnaryExpr(false, expr, @operator);
Beispiel #8
0
 public static ScriptExpr Prefix(ScriptExpr expr, string @operator) => new UnaryExpr(true, expr, @operator);
Beispiel #9
0
 public static ScriptExpr BooleanBinary(ScriptExpr left, ScriptExpr right, string @operator) => new BooleanBinaryExpr(left, right, @operator);
Beispiel #10
0
 public static ScriptExpr Args(ScriptExpr left, ScriptExpr right) => new TupleExpr(left, right);