Example #1
0
 internal override bool TryEvaluate(Stack<Context> contextStack, CompilationState state, out Context context)
 {
     //Add the Identifier to the current context
       var memberSymbol = contextStack.Any() ? contextStack.Peek().Symbol.FindMember(_value) :
                                       state.Introspector.GetTypeSymbol(_value);
       if (memberSymbol != null)
       {
     var identifierContext = new Context(string.Join(".", contextStack.Peek().FullPath, _value), memberSymbol);
     if (_next == null)
     {
       //Last element => return IdentifierContext
       context = identifierContext;
       return true;
     }
     else
     {
       //Push the identifier on the contextStack and keep going
       contextStack.Push(identifierContext);
       return _next.TryEvaluate(contextStack, state, out context);
     }
       }
       else
       {
     state.AddTypeError($"Could not find Member '{_value}' in Type '{contextStack.Peek().Symbol.ToDisplayString()}'!", HandlebarsTypeErrorKind.UnknownMember);
     context = null;
     return false;
       }
 }
 internal override bool TryEvaluate(CompilationState state, out Context context)
 {
     //Copy Stack as identifier elements manipulate (push, pop)
       var cpContextStack = new Stack<Context>();
       cpContextStack = new Stack<Context>(state.ContextStack.Reverse());
       return Path.TryEvaluate(cpContextStack, state, out context);
 }
 /// <summary>
 /// Will evaluate to a context inside a loop. Used for the context inside #each blocks
 /// </summary>
 /// <param name="state"></param>
 /// <returns></returns>
 internal Context EvaluateLoop(CompilationState state)
 {
     Context loopVariable;
       if (TryEvaluate(state, out loopVariable))
       {
     var elementSymbol = loopVariable.Symbol.GetElementSymbol();
     if (elementSymbol!=null)
       return state.BuildLoopContext(loopVariable.Symbol.GetElementSymbol());
       }
       return null;
 }
 internal override bool TryEvaluate(CompilationState state, out Context context)
 {
     var ctLoopContext = IsCompileTimeLoop(state);
       if (ctLoopContext!=null)
       {//Inside CTLoop -> Return literal
     context = new Context(ctLoopContext.First.ToString().ToLower(), state.Introspector.GetBoolTypeSymbol());
     return true;
       } else
       {
     context = new Context($"first{state.LoopLevel}", state.Introspector.GetBoolTypeSymbol());
     return InsideEachLoopCheck(state);
       }
 }
 internal override bool TryEvaluate(CompilationState state, out Context context)
 {
     var ctLoopContext = IsCompileTimeLoop(state);
       if (ctLoopContext!=null)
       {
     context = new Context($"\"{ctLoopContext.Key}\"", state.Introspector.GetStringTypeSymbol());
     return true;
       }
       else
       {
     state.AddTypeError("KeyExpression outside a compiletime loop over an Object", HandlebarsTypeErrorKind.IllegalKeyExpression);
     context = null;
     return false;
       }
 }
Example #6
0
 internal abstract bool TryEvaluate(CompilationState state, out Context context);
 internal override bool TryEvaluate(CompilationState state, out Context context)
 {
     context = new Context($"\"{_value}\"", state.Introspector.GetStringTypeSymbol());
       return true;
 }
 public CodeGenerationVisitor(RoslynIntrospector introspector, HandlebarsTemplate template)
 {
     state = new CompilationState(introspector, template);
       state.Introspector = introspector;
 }
 protected CompileTimeLoopContext IsCompileTimeLoop(CompilationState state)
 {
     return state.ContextStack.Peek() as CompileTimeLoopContext;
 }
 protected bool InsideEachLoopCheck(CompilationState state)
 {
     if (state.LoopLevel > 0)
     return true;
       state.AddTypeError("SpecialExpressions can only exist inside EachBlocks", HandlebarsTypeErrorKind.SpecialExpressionOutsideEachLoop);
       return false;
 }
Example #11
0
 internal abstract bool TryEvaluate(Stack<Context> contextStack, CompilationState state, out Context context);
Example #12
0
 internal override bool TryEvaluate(Stack<Context> contextStack, CompilationState state, out Context context)
 {
     if (_next == null)
       {
     context = contextStack.Peek();
     return true;
       }
       else
     return _next.TryEvaluate(contextStack, state, out context);
 }
Example #13
0
 internal override bool TryEvaluate(Stack<Context> contextStack, CompilationState state, out Context context)
 {
     if (_next == null)
       {
     context = contextStack.Last();
     return true;
       }
       else
       {
     var rootedContextStack = new Stack<Context>();
     rootedContextStack.Push(contextStack.Last());
     return _next.TryEvaluate(rootedContextStack, state, out context);
       }
 }
Example #14
0
 internal override bool TryEvaluate(Stack<Context> contextStack, CompilationState state, out Context context)
 {
     if (!contextStack.Any() || contextStack.Count == 1)
       {
     state.AddTypeError("Error in MemberExpression: Empty ContextStack but PathUp Element ('../')!", HandlebarsTypeErrorKind.EmptyContextStack);
     context = null;
     return false;
       }
       contextStack.Pop();
       return _next.TryEvaluate(contextStack, state, out context);
 }