protected override void VisitAnyExpression(AnyExpression expression) { CS.IndentInOut( "AnyExpression", () => { Locals.PeekPrep(Writer); CS.If( $"!{Cfg.CurName}.AtEnd", () => { using var next = Locals.Use("next"); using var location = Locals.Use("location"); using var node = Locals.Use("node"); CS.Ln($"{next} = {Cfg.CurName}.Advance(1);"); CS.Ln($"{location} = Location.From({Cfg.CurName}, {next});"); CS.Ln($"{node} = Leaf.From({location}, NodeSymbols.Any, ((char){Cfg.CurName}.Current).ToString(CultureInfo.InvariantCulture));"); CS.Ln($"{Locals.Result} = Result.Success({node}, {next}, {node});"); }, () => { CS.Ln($"{Locals.Result} = Result.Fail({Cfg.CurName});"); }); }); }
private Expression Primary(INode node) { switch (node.Name) { case "identifier": return(NameExpression.From(node, Identifier(node))); case "singleString": case "doubleString": return(StringLiteral(node)); case ".": return(AnyExpression.From(node)); case "choice": return(Expression(node)); case "class": return(Class(node)); case "ε": return(EpsilonExpression.From(node)); case "inline": return(InlineExpression.From(node, Rule(node[0]))); default: throw new NotImplementedException(); } }
public async Task TestAnyExpression() { var config = new MustacheConfigSchema() { Params = new List <Param> { new Param { Name = "MySql", DefaultValue = "true" }, new Param { Name = "MySqlEFCore", DefaultValue = "false" }, new Param { Name = "C", DefaultValue = "false" }, }, }; var dv = new Dictionary <string, string> { { "MySql", "true" }, }; var calcParam = new CalculatedParam { Name = "AnyEFCore", Expression = "MySql,Postgres,Redis,MongoDB,OAuthConnector", ExpressionType = ExpressionTypeEnum.Any, }; var expression = new AnyExpression(_logger, calcParam, config); var result = await expression.EvaluateExpressionAsync(dv); Assert.Equal("True", result); }
protected override void VisitAnyExpression(AnyExpression expression) { void Write() { Writer.Write($"{OpSymbols.Any}"); } LexSpaced(expression, Write); }
public IActionResult Index() { var anyExample = new AnyExpression().GetExampleQuery(_context); var includeExample = new IncludeExpression().GetExampleQuery(_context); var andOrExample = new AndOrExpression().GetExampleQuery(_context); var result = new ExpressionResult(anyExample.ToList(), includeExample.ToList(), andOrExample.ToList()); return(View(result)); }
private IDictionary <string, IExpression> GetEvaluationExpressions(MustacheConfigSchema schema) { var evalExpressions = new Dictionary <string, IExpression>(); foreach (var calculatedParam in schema.CalculatedParams) { IExpression expression = null; switch (calculatedParam.ExpressionType) { case ExpressionTypeEnum.Any: expression = new AnyExpression(_logger, calculatedParam, schema); break; case ExpressionTypeEnum.Bool: expression = new BooleanExpression(_logger, calculatedParam, schema); break; case ExpressionTypeEnum.Case: expression = new CaseExpression(_logger, calculatedParam, schema); break; case ExpressionTypeEnum.String: expression = new CaseExpression(_logger, calculatedParam, schema); break; case ExpressionTypeEnum.MoreThanOne: expression = new MoreThanOneExpression(_logger, calculatedParam, schema); break; default: throw new InvalidEnumArgumentException("Calculated Expression", (int)calculatedParam.ExpressionType, typeof(ExpressionTypeEnum)); } if (expression != null) { evalExpressions.Add(calculatedParam.Name, expression); } } return(evalExpressions); }
private static Expression Expression(INode node) { switch (node.Name) { case "sequence": return(Sequence(node)); case "choice": return(Choice(node)); case "prefix.drop": return(DropExpression.From(node[0], Expression(node[0]))); case "prefix.lift": return(LiftExpression.From(node[0], Expression(node[0]))); case "prefix.fuse": return(FuseExpression.From(node[0], Expression(node[0]))); case "prefix.not": return(NotExpression.From(node[0], Expression(node[0]))); case "suffix.zero-or-more": return(StarExpression.From(node[0], Expression(node[0]))); case "suffix.one-or-more": return(PlusExpression.From(node[0], Expression(node[0]))); case "suffix.zero-or-one": return(OptionalExpression.From(node[0], Expression(node[0]))); case "inline": return(InlineExpression.From(node[0], Tree.Rule.From(Identifier(node[0]), Expression(node[1])))); case "identifier": return(NameExpression.From(node, Identifier(node))); case "any": return(AnyExpression.From(node)); case "verbatim-string": return(StringLiteralExpression.From(node, ((ILeaf)node).Value)); case "character-class": return(Class(node)); case "string": return(String(node)); default: throw new NotImplementedException(); } }
protected override void VisitAnyExpression(AnyExpression expression) { Push(new Any()); }
public void IdentityIsNull() { AnyExpression expression = new AnyExpression(); Assert.IsFalse(expression.Evaluate((IIdentity)null)); }
public void PrincipalIsNull() { AnyExpression expression = new AnyExpression(); Assert.IsFalse(expression.Evaluate((IPrincipal)null)); }
public void IdentityNotNull() { AnyExpression expression = new AnyExpression(); Assert.IsTrue(expression.Evaluate(new GenericIdentity("foo"))); }
public void PrincipalNotNull() { AnyExpression expression = new AnyExpression(); Assert.IsTrue(expression.Evaluate(new GenericPrincipal(new GenericIdentity("foo"), null))); }
public void TrueTest() { AnyExpression expression = new AnyExpression(); Assert.IsTrue(expression.Evaluate(new GenericPrincipal(new GenericIdentity("foo"), null))); }
protected override void VisitAnyExpression(AnyExpression expression) { base.VisitAnyExpression(expression); SetNullable(expression, false); }