Esempio n. 1
0
        public Compiler(string filename, string file, List <IBaseFunction> predefined)
        {
            LoopTracerStack = new List <LoopTracer>();
            FunctionStack.Clear();//clear this every run
            Files = new Dictionary <string, string>();
            Files.Add(filename, file);
            var onefile = ParseImports(file);

            _compileStack = ParseScopes(onefile, predefined);
            _compileStack.AddRange(predefined);
            _compileStack.AddRange(importFStack);
            ExtensionStack.AddRange(importEStack);
            StartScope(_compileStack);
        }
Esempio n. 2
0
        private List <IBaseFunction> ParseScopes(string file, List <IBaseFunction> predefined)
        {
            var temp = new List <IBaseFunction>();
            //remove all comments
            var commRegex = new Regex(@"#([^\n]+)$", RegexOptions.Multiline);

            file = commRegex.Replace(file, "");

            //add functions first
            var _functionStack = new List <IBaseFunction>();
            var scopeRegex     = new Regex(ScopeRegex(@"\bfunction\.\b"), RegexOptions.IgnorePatternWhitespace);
            var scopes         = scopeRegex.Matches(file);

            foreach (var s in scopes)
            {
                _functionStack.Add(new AnonymousFunction(s.ToString()));
            }
            //add inherits second
            var _inheritStack     = new List <IBaseFunction>();
            var inheritRegex      = new Regex(ScopeRegex(@"\boverride\.\b"), RegexOptions.IgnorePatternWhitespace);
            var inherits          = inheritRegex.Matches(file);
            var tempfunctionstack = new List <IBaseFunction>();

            tempfunctionstack.AddRange(_functionStack);
            tempfunctionstack.AddRange(predefined);
            for (var i = inherits.Count - 1; i >= 0; i--)
            {
                var inherit = inherits[i];
                var obj     = new AnonymousFunction(inherit.ToString(), tempfunctionstack);
                _inheritStack.Add(obj);
                tempfunctionstack.Insert(0, obj);
            }
            //add custom extensions
            var _extStack = new List <EDefinition>();
            var extRegex  = new Regex(ScopeRegex(@"\bextension\.\b"), RegexOptions.IgnorePatternWhitespace);
            var exts      = extRegex.Matches(file);

            for (var i = exts.Count - 1; i >= 0; i--)
            {
                var ext  = exts[i];
                var cext = new CustomExtension();
                cext.FunctionReference = new AnonymousFunction(ext.ToString(), cext);
                _extStack.Add(cext);
            }
            ExtensionStack.AddRange(_extStack);
            //add async
            var _asyncStack = new List <IBaseFunction>();
            var asyncRegex  = new Regex(ScopeRegex(@"\basync\.\b"), RegexOptions.IgnorePatternWhitespace);
            var asyncs      = asyncRegex.Matches(file);

            foreach (var i in asyncs)
            {
                var obj = new AnonymousFunction(i.ToString());
                obj.Async = true;
                _asyncStack.Add(obj);
            }
            temp.AddRange(_inheritStack.Reverse <IBaseFunction>());
            temp.AddRange(_functionStack);
            temp.AddRange(_asyncStack);
            return(temp);
        }