Esempio n. 1
0
 public static CodeFrame[] CompileFrame(string code)
 {
     return(CodeFrame.Create(code)
            .Select(frame => CompileFrame(frame, code))
            .OrderBy(f => f.Match.Index)
            .ToArray());
 }
Esempio n. 2
0
        public static CodeFrame CompileFrame(CodeFrame frame, string code)
        {
            var compiler   = new RegenCompiler(); //todo modules here?
            var parsedCode = ExpressionParser.Parse(frame.Input);

            LoadGlobals(compiler);
            //handle globals
            var globals = CodeFrame.CreateGlobals(code);

            foreach (var globalFrame in globals)
            {
                compiler.CompileGlobal(globalFrame.Input);
            }

            frame.Output = compiler.Compile(parsedCode);
            return(frame);
        }
Esempio n. 3
0
        public static List <(string Path, string Content)> Compile(string code, string templatePath = null)
        {
            templatePath = string.IsNullOrEmpty(templatePath) ? null : Path.GetFullPath(templatePath);
            var compiler = _prepareCompiler();

            //handle the _REGEN_TEMPLATE as a global
            var template = CodeFrame.Create(code, "_REGEN_TEMPLATE").Single();

            compiler.CompileGlobal(ExpressionParser.Parse(template.Input));

            //we iterate the parser tokens and take action accordingly.
            var parsedCode = ExpressionParser.Parse(template.Input);
            var returnList = new List <(string Path, string Content)>();

            foreach (var act in parsedCode.ParseActions)
            {
                switch (act.Token)
                {
                case ParserToken.Template:
                    returnList.AddRange(CompileFile(compiler, (TemplateExpression)act.Related[0], code, templatePath));
                    break;

                case ParserToken.Declaration:
                case ParserToken.Import:
                    compiler.CompileAction(act, parsedCode.ParseActions);
                    break;

                case ParserToken.ForeachLoop:
                case ParserToken.Expression:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            //return frame;
            return(returnList);
        }
Esempio n. 4
0
 public static CodeFrame ParseAt(string code, int index)
 {
     return(CompileFrame(CodeFrame.Create(code, index), code));
 }