public static Either <Error, Tuple <string, ExpressionBuilder> > ExprTerm(string s) { Either <Error, Tuple <string, ExpressionBuilder> > res1 = Unary(s); if (res1.IsRight) { return(res1); } Either <Error, Tuple <string, Term> > res2 = Parser.Term(s); if (res2.IsLeft) { return(res2.Left); } Tuple <string, Term> t2 = res2.Right; ExpressionBuilder e = new ExpressionBuilder.Value(t2.Item2); return(new Tuple <string, ExpressionBuilder>(t2.Item1, e)); }
public static Either <Error, Tuple <string, ExpressionBuilder> > Unary(string str) { str = Parser.Space(str); if (str.StartsWith("!")) { str = Parser.Space(str.Substring(1)); Either <Error, Tuple <string, ExpressionBuilder> > resultExpression = Expr(str); if (resultExpression.IsLeft) { return(resultExpression.Left); } Tuple <string, ExpressionBuilder> t = resultExpression.Right; return(new Tuple <string, ExpressionBuilder>(t.Item1, new ExpressionBuilder.Unary(ExpressionBuilder.Op.Negate, t.Item2))); } if (str.StartsWith("(")) { Either <Error, Tuple <string, ExpressionBuilder> > unaryParens = UnaryParens(str); if (unaryParens.IsLeft) { return(unaryParens.Left); } Tuple <string, ExpressionBuilder> t = unaryParens.Right; str = Parser.Space(str.Substring(1)); return(new Tuple <string, ExpressionBuilder>(t.Item1, t.Item2)); } ExpressionBuilder e; Either <Error, Tuple <string, Term> > res = Parser.Term(str); if (res.IsRight) { Tuple <string, Term> t = res.Right; str = Parser.Space(t.Item1); e = new ExpressionBuilder.Value(t.Item2); } else { Either <Error, Tuple <string, ExpressionBuilder> > res2 = UnaryParens(str); if (res2.IsLeft) { return(res2.Left); } Tuple <string, ExpressionBuilder> t = res2.Right; str = Parser.Space(t.Item1); e = t.Item2; } if (str.StartsWith(".Length")) { str = Parser.Space(str.Substring(9)); return(new Tuple <string, ExpressionBuilder>(str, new ExpressionBuilder.Unary(ExpressionBuilder.Op.Length, e))); } else { return(new Error(str, "unexpected token")); } }