FastPgm MkFastPgm(object defs) { var def_list = (Cons <Def>)defs; var pgm = new FastPgm(); foreach (var def in def_list) { pgm.Add(def); } program = pgm; return(pgm); }
/// <summary> /// Parses a Fast program from given text. /// </summary> public static FastPgm Parse(string text, string filename = null) { MemoryStream mstr = null; FastPgm pgm = null; try { mstr = new MemoryStream(Encoding.UTF8.GetBytes(text)); mstr.Position = 0; pgm = Parse(mstr, filename); } finally { if (mstr != null) { mstr.Dispose(); } } return(pgm); }
/// <summary> /// Parses a single Fast program from multiple files. /// Returns null if files is empty. /// </summary> /// <param name="files">given files</param> public static FastPgm ParseFiles(params string[] files) { FileStream stream = null; FastPgm pgm = null; foreach (var file in files) { try { FileInfo fi = new FileInfo(file); stream = fi.OpenRead(); var parser = new FastPgmParser(stream, fi.FullName); bool ok = parser.Parse(); if (!ok) { throw new FastParseException("Error: fast parser failed", fi.FullName); } if (pgm == null) { pgm = parser.program; } else { pgm.Add(parser.program.defs); } } finally { if (stream != null) { stream.Dispose(); stream = null; } } } return(pgm); }