Пример #1
0
        private void ParseInternal(string text, string sourceFilePath)
        {
            // Early exit
            if (string.IsNullOrEmpty(text))
            {
                HasErrors = false;
                Messages = new List<LogMessage>();
                return;
            }

            var lexer = new Lexer(text, sourceFilePath, options.Mode == ScriptMode.ScriptOnly);
            var parser = new Parser(lexer, options);

            Page = parser.Run();

            HasErrors = parser.HasErrors;
            Messages = parser.Messages;
        }
Пример #2
0
        public void TestFunctionCallInExpression()
        {
            var lexer = new Lexer(@"{{ 
with math
    round pi 
end
}}");
            var parser = new Parser(lexer);
            
            var scriptPage = parser.Run();

            foreach (var message in parser.Messages)
            {
                Console.WriteLine(message);
            }
            Assert.False(parser.HasErrors);
            Assert.NotNull(scriptPage);

            var rootObject = new ScriptObject();
            rootObject.SetValue("math", ScriptObject.From(typeof(MathObject)), true);

            var context = new TemplateContext();
            context.PushGlobal(rootObject);
            scriptPage.Evaluate(context);
            context.PopGlobal();

            // Result
            var result = context.Output.ToString();

            Console.WriteLine(result);
        }