/// <summary> /// Загрузить содержимое файла с исходным кодом и получить набор единиц кода /// </summary> /// <returns></returns> public CCodeUnitsCollection Load() { if (File.Exists(m_args.GetPath())) { using (FileStream f_stream = new FileStream(m_args.GetPath(), FileMode.Open)) { using (StreamReader sreader = new StreamReader(f_stream, m_args.GetEncoding())) { CCodeUnitsCollection collection = new CCodeUnitsCollection(); string source_str = null; long line_number = CElementPosition.LINE_NUMBER_LOW_BOUND; while ((source_str = sreader.ReadLine()) != null) { CCodeUnit unit = new CCodeUnit(new CElementPosition(line_number, CElementPosition.INDEX_NUMBER_LOW_BOUND, line_number, source_str.Length), source_str); collection.Add(new CExtendedCodeUnit(unit, m_args.GetFileID().SourceFileID)); ++line_number; } return(collection); } } } else { throw new FileNotFoundException("File not found", m_args.GetPath()); } }
public static CExtendedCodeUnit FromToken(Token token, CTokenizerParms args) { CElementPosition pos = new CElementPosition(token.line, token.col, token.line, token.col + token.val.Length); CCodeUnit simple_unit = new CCodeUnit(pos, token.val); CExtendedCodeUnit unit = new CExtendedCodeUnit(simple_unit, args.GetFileID().SourceFileID); return(unit); }
public void GetSourceFileIDTest() { CTokenizerParms target = new CTokenizerParms(_Path, _Encoding, FileID); Assert.AreEqual(FileID, target.GetFileID()); }