/// <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());
     }
 }
示例#2
0
文件: Utils.cs 项目: mfvanek/i-clone
        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);
        }
示例#3
0
        public void GetSourceFileIDTest()
        {
            CTokenizerParms target = new CTokenizerParms(_Path, _Encoding, FileID);

            Assert.AreEqual(FileID, target.GetFileID());
        }