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); }
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; } }
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(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; }