public override ICodeContext CreateContext(CodeContextTypes contextType, string name = null, Bag <string> attributes = null) { switch (contextType) { case CodeContextTypes.MethodCall: return(new MethodCallContext(name, (methodCall) => { Add(OperatorTypes.Noop, methodCall); }, attributes?.Get <string>("hook"))); case CodeContextTypes.Expression: return(new ExpressionContext((expression) => { Add(_defaultOperator, expression); })); case CodeContextTypes.SignedExpression: return(new ExpressionContext((expression) => { Add(OperatorTypes.UnaryMinus, expression); })); case CodeContextTypes.ParenthesizedExpression: return(new ExpressionContext((expression) => { Add(_defaultOperator, new ExpressionNode(GetOperatorMap(OperatorTypes.Parenthesis), expression)); })); case CodeContextTypes.BinaryExpression: if (attributes?.Contains("operator") ?? false) { var operatorType = attributes.Get <OperatorTypes>("operator"); return(new ExpressionContext((expression) => { Add(operatorType, expression); })); } break; case CodeContextTypes.IndexExpression: bool last = attributes?.Get <bool>("last", false) ?? false; return(new ExpressionContext((expression) => { Add(last?OperatorTypes.LastIndex:OperatorTypes.Index, expression); })); case CodeContextTypes.OfExpression: bool lastOf = attributes?.Get <bool>("last", false) ?? false; return(new ExpressionContext((expression) => { Add(_defaultOperator, expression); }, lastOf? OperatorTypes.LastIndexOf:OperatorTypes.IndexOf)); } return(base.CreateContext(contextType, name, attributes)); }
public virtual ICodeContext CreateContext(CodeContextTypes contextType, string name, Bag <string> attributes = null) { if (this.Parent == null) { Context.Log(LogLevel.Error, $"{contextType} not supported in {Label} context", Context.Location.Line, Context.Location.Column); return(this); } else { return(this.Parent.CreateContext(contextType, name, attributes)); } }
public override ICodeContext CreateContext(CodeContextTypes contextType, string name, Bag <string> attributes = null) { switch (contextType) { case CodeContextTypes.Attribute: return(new AttributeContext(name, (expression) => { _attributes.Add(new Attribute() { Name = name, Expression = expression.ToExpression() }); })); } return(base.CreateContext(contextType, name, attributes)); }
public void PopTo(CodeContextTypes contextType) { switch (contextType) { case CodeContextTypes.Hook: PopTo(typeof(MethodContext)); break; case CodeContextTypes.Document: PopTo(typeof(ClassContext)); break; default: throw new NotSupportedException(); } }
public override ICodeContext CreateContext(CodeContextTypes contextType, string name, Bag <string> attributes = null) { switch (contextType) { case CodeContextTypes.Method: return(new MethodContext(name, (methodDeclaration) => { _memberDeclarations.Add(methodDeclaration); }, isOverride: name == "View")); case CodeContextTypes.Hook: return(new MethodContext(name, (hookDeclaration) => { _memberDeclarations.Add(hookDeclaration); })); } return(base.CreateContext(contextType, name, attributes)); }
public override ICodeContext CreateContext(CodeContextTypes contextType, string name = null, Bag <string> attributes = null) { switch (contextType) { case CodeContextTypes.Argument: return(new ExpressionContext((expression) => { if (expression == null) { _valueExpression = SF.LiteralExpression(SyntaxKind.NullLiteralExpression); } else { _valueExpression = expression.ToExpression(); } })); } return(base.CreateContext(contextType, name, attributes)); }
public override ICodeContext CreateContext(CodeContextTypes contextType, string name = null, Bag <string> attributes = null) { switch (contextType) { case CodeContextTypes.Argument: return(new ExpressionContext((expression) => { if (expression == null) { _valueExpression = SF.LiteralExpression(SyntaxKind.TrueKeyword); } else { _valueExpression = expression.ToExpression(); } })); case CodeContextTypes.When: return(new WhenContext(name, _valueExpression, (whenStatement) => { _whenClauses.Add(whenStatement); })); case CodeContextTypes.Otherwise: string elseHookName = name; return(new BlockContext((block) => { if (elseHookName == null) { _otherwiseClause = SF.ElseClause(block); } else { _otherwiseClause = SF.ElseClause(BlockContext.MakeWriteStatement(MethodCallContext.CreateMethodCall(elseHookName, true))); } })); } return(base.CreateContext(contextType, name, attributes)); }
public override ICodeContext CreateContext(CodeContextTypes contextType, string name = null, Bag <string> attributes = null) { switch (contextType) { case CodeContextTypes.Argument: return(new ExpressionContext((expression) => { if (expression == null) { _condition = SF.LiteralExpression(SyntaxKind.FalseKeyword); } else { _condition = expression.ToExpression(); } })); case CodeContextTypes.ElseIf: return(new IfContext(name, (ifStatement) => { _elseClause = SF.ElseClause(ifStatement); })); case CodeContextTypes.Else: string elseHookName = name; return(new BlockContext((block) => { if (elseHookName == null) { _elseClause = SF.ElseClause(block); } else { _elseClause = SF.ElseClause(BlockContext.MakeWriteStatement(MethodCallContext.CreateMethodCall(elseHookName, true))); } })); } return(base.CreateContext(contextType, name, attributes)); }
public override ICodeContext CreateContext(CodeContextTypes contextType, string name = null, Bag <string> attributes = null) { switch (contextType) { case CodeContextTypes.Argument: return(new ExpressionContext((expression) => { if (expression == null) { _arguments.Add(SF.Argument(SF.LiteralExpression(SyntaxKind.NullLiteralExpression))); } else { var argumentExpression = expression.ToExpression(); #if never var parsedExpression = SF.ParseExpression(expression.ToString()); //Hack because the expression tree isn't being build the way Roslyn would like it #endif _arguments.Add(SF.Argument(argumentExpression)); } })); } return(base.CreateContext(contextType, name, attributes)); }
public override ICodeContext CreateContext(CodeContextTypes contextType, string name, Bag <string> attributes = null) { MacroDefinition macroDefinition; switch (contextType) { case CodeContextTypes.MethodCall: macroDefinition = attributes?.Get <MacroDefinition>("definition"); return(new MethodCallContext(name, (callExpression) => { WriteStatement(callExpression); }, attributes?.Get <string>("hook"), macroDefinition.RequiresState)); case CodeContextTypes.If: return(new IfContext(name, (ifStatement) => { Add(ifStatement); })); case CodeContextTypes.Choose: return(new ChooseContext((chooseStatement) => { Add(chooseStatement); })); case CodeContextTypes.Each: return(new EachContext(name, (eachStatement) => { Add(eachStatement); })); case CodeContextTypes.Set: return(new SetContext(name, (setStatement) => { Add(setStatement); })); case CodeContextTypes.HookDefinition: return(new HookDefinitionContext(name, (setStatement) => { Add(setStatement); })); case CodeContextTypes.TagOpen: return(new TagOpenContext(name, null, (expression) => { Add(expression); }, attributes?.Get <bool>("closing") ?? false)); case CodeContextTypes.TagClose: return(new TagCloseContext(name, null, (expression) => { Add(expression); })); case CodeContextTypes.Block: return(new BlockContext((block) => { Add(block); })); } return(base.CreateContext(contextType, name, attributes)); }
public void Push(CodeContextTypes contextType, string name = null, Bag <string> attributes = null) { var newContext = _codeContext.CreateContext(contextType, name, attributes); Push(newContext); }