コード例 #1
0
ファイル: LangModule.cs プロジェクト: hardliner66/ela-lang
        private ElaValue Read(string str)
        {
            var p   = new ElaParser();
            var res = p.Parse(str);

            if (!res.Success)
            {
                throw Fail(str);
            }

            var prog = res.Program;

            if (prog.Instances != null ||
                prog.Includes.Count != 0 ||
                prog.Classes != null ||
                prog.Types != null ||
                prog.TopLevel.Equations.Count != 1)
            {
                throw Fail(str);
            }

            var eq = prog.TopLevel.Equations[0];

            if (eq.Right != null)
            {
                throw Fail(str);
            }

            return(Read(eq.Left, str));
        }
コード例 #2
0
        private ElaAst InternalParse(string source, Document doc, IBuildLogger logger)
        {
            logger.WriteBuildInfo("Ela", ElaVersionInfo.Version);

            var parser   = new ElaParser();
            var res      = parser.Parse(source);//doc.FileInfo == null ? new ModuleFileInfo(doc.Title) : doc.FileInfo.ToModuleFileInfo());
            var messages = res.Messages.Take(100).ToList();

            logger.WriteMessages(messages.Select(m =>
                                                 new MessageItem(
                                                     m.Type == MessageType.Error ? MessageItemType.Error : (m.Type == MessageType.Warning ? MessageItemType.Warning : MessageItemType.Information),
                                                     String.Format("ELA{0}: {1}", m.Code, m.Message),
                                                     m.File == null || !new FileInfo(m.File.FullName).Exists ? doc : new VirtualDocument(new FileInfo(m.File.FullName)),
                                                     m.Line,
                                                     m.Column)
            {
                Tag = m.Code
            })
                                 , m => true);
            return(res.Success ? new ElaAst(res.Program) : null);
        }
コード例 #3
0
        public Tuple <ICompiledUnit, IEnumerable <MessageItem> > Compile(CodeDocument doc, string source)
        {
            var par    = new ElaParser();
            var parRes = par.Parse(source);
            var msg    = new List <MessageItem>();
            var unit   = doc.Unit;
            Func <ElaMessage, MessageItem> project = m => new MessageItem(
                m.Type == MessageType.Error ? MessageItemType.Error : MessageItemType.Warning, m.Message, doc, m.Line, m.Column);

            if (parRes.Success)
            {
                var copt = new CompilerOptions();

                copt.ShowHints         = false;
                copt.GenerateDebugInfo = true;
                copt.IgnoreUndefined   = true;

                //TODO: hack, should be taken from options
                copt.Prelude = "prelude";
                var comp = new ElaCompiler();

                try
                {
                    var compRes = comp.Compile(parRes.Program, copt, new ExportVars());
                    msg.AddRange(compRes.Messages.Where(m => m.Type != MessageType.Hint).Select(project));

                    if (compRes.CodeFrame != null)
                    {
                        unit = new CompiledUnit(doc, compRes.CodeFrame);
                    }
                }
                catch { }
            }
            else
            {
                msg.AddRange(parRes.Messages.Select(project));
            }

            return(Tuple.Create(unit, (IEnumerable <MessageItem>)msg));
        }
コード例 #4
0
        private static int Parse()
        {
            try
            {
                var p   = new ElaParser();
                var res = p.Parse(new FileInfo(opt.FileName));
                helper.PrintErrors(res.Messages);

                if (!res.Success)
                {
                    return(R_ERR);
                }

                Console.WriteLine(res.Program.ToString());
                return(R_OK);
            }
            catch (ElaException ex)
            {
                helper.PrintInternalError(ex);
                return(R_ERR);
            }
        }
コード例 #5
0
        private IEnumerable <SymbolLocation> ProcessFile(string name, CodeDocument doc)
        {
            var editor = app.Editor(doc.GetType());
            var list   = new List <SymbolLocation>();

            if (editor is ElaEditor)
            {
                var src = ((ITextEditor)editor).GetContent(doc);
                var p   = new ElaParser();
                var res = p.Parse(new StringBuffer(src));

                if (res.Success)
                {
                    res.Program.Includes.ForEach(i => FindName(name, doc, i, list));
                    FindName(name, doc, res.Program.Instances, list);
                    FindName(name, doc, res.Program.Classes, list);
                    FindName(name, doc, res.Program.Types, list);
                    FindName(name, doc, res.Program.TopLevel, list);
                }
            }

            return(list);
        }
コード例 #6
0
        private CodeFrame Build(ModuleReference mod, FileInfo fi)
        {
            try
            {
                var elap = new ElaParser();
                var pres = elap.Parse(fi);

                if (pres.Success)
                {
                    var elac = new ElaCompiler();
                    var copt = new BuildOptionsManager(App).CreateCompilerOptions();
                    return(elac.Compile(pres.Program,
                                        new CompilerOptions {
                        IgnoreUndefined = true, NoWarnings = true, ShowHints = false, Prelude = copt.Prelude
                    },
                                        new ExportVars()
                                        ).CodeFrame);
                }
            }
            catch { }

            return(null);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: ngoffee/ela
        static int Run(string file, string outputFile)
        {
            Console.Write("\r\nGenerating documentation file: {0}...", outputFile);

            var fi  = new FileInfo(file);
            var doc = default(Doc);

            using (var sr = new StreamReader(file))
            {
                var lst  = new List <String>();
                var line = String.Empty;

                while ((line = sr.ReadLine()) != null)
                {
                    lst.Add(line);
                }

                var p = new DocParser();
                doc = p.Parse(lst.ToArray());
            }

            var gen  = default(HtmGenerator);
            var lopt = new LinkerOptions();
            var copt = new CompilerOptions {
                Prelude = "prelude"
            };

            ConfigurationManager.AppSettings["refs"].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
            .ToList().ForEach(s => lopt.CodeBase.Directories.Add(s));

            if (!String.IsNullOrEmpty(doc.File) && doc.File.Trim(' ').Length != 0)
            {
                var elaFile = new FileInfo(Path.Combine(fi.DirectoryName, doc.File));

                if (!elaFile.Exists)
                {
                    foreach (var d in lopt.CodeBase.Directories)
                    {
                        elaFile = new FileInfo(Path.Combine(d, doc.File));

                        if (elaFile.Exists)
                        {
                            break;
                        }
                    }
                }

                var elap = new ElaParser();
                var res  = elap.Parse(elaFile);

                if (!res.Success)
                {
                    res.Messages.ToList().ForEach(m => Console.WriteLine("\r\n" + m));
                    return(-1);
                }

                lopt.CodeBase.Directories.Add(elaFile.Directory.FullName);
                var lnk  = new ElaIncrementalLinker(lopt, copt, new ModuleFileInfo(elaFile.FullName));
                var lres = lnk.Build();

                if (!lres.Success)
                {
                    lres.Messages.ToList().ForEach(m => Console.Write("\r\n" + m));
                    return(-1);
                }

                var vm = new ElaMachine(lres.Assembly);
                vm.Run();
                gen = new HtmGenerator(res.Program, doc, lnk, vm);
            }
            else
            {
                var lnk = new ElaIncrementalLinker(lopt, copt);
                gen = new HtmGenerator(null, doc, lnk, null);
            }

            var src = gen.Generate();

            var outFi = new FileInfo(outputFile);

            if (!outFi.Directory.Exists)
            {
                outFi.Directory.Create();
            }

            using (var fs = new StreamWriter(File.Create(outputFile)))
                fs.Write(src);

            Console.Write(" Done");
            return(0);
        }