示例#1
0
        public SyntaxTreeNode Parse(TextReader templateReader, Type modelType)
        {
            var state  = new HandlebarsParserState();
            var tokens = HandlebarsTokenizer.Tokenize(templateReader);

            state.BlockStack.PushNewBlockWithModel(modelType);

            foreach (var token in tokens)
            {
                state.SetCurrentToken(token);

                foreach (var handler in SyntaxHandlers)
                {
                    if (handler.Key(token))
                    {
                        handler.Value.Invoke(state);
                        if (state.ContinueProcessingToken)
                        {
                            state.ContinueProcessingToken = false;
                            continue;
                        }
                        break;
                    }
                }
            }

            state.AssertStackOnRootNode();

            return(state.RootNode);
        }
示例#2
0
        public SyntaxTreeNode Parse(string templateId, TextReader templateReader, Type modelType, IMemberLocator memberLocator, IHelperHandler[] helperHandlers)
        {
            if (memberLocator == null)
            {
                memberLocator = MemberLocator.Default;
            }

            var state  = new HandlebarsParserState(templateId, memberLocator);
            var tokens = HandlebarsTokenizer.Tokenize(templateReader);

            state.BlockStack.PushNewBlockWithModel(modelType, new SourceLocation(templateId, 0, 0));

            var helpers = SyntaxHandlers.Union(GetHelperHandlers(helperHandlers ?? Enumerable.Empty <IHelperHandler>())).Union(SyntaxHandlersAfter).ToList();

            foreach (var token in tokens)
            {
                state.SetCurrentToken(token);

                foreach (var handler in helpers)
                {
                    if (handler.Key(token))
                    {
                        handler.Value.Invoke(state);
                        if (state.ContinueProcessingToken)
                        {
                            state.ContinueProcessingToken = false;
                            continue;
                        }
                        break;
                    }
                }
            }

            state.AssertStackOnRootNode();

            return(state.RootNode);
        }