//Metodi statici /// <summary> /// Permette l'estrazione da una stringa del codice per l'interpretazione /// </summary> /// <param name="RawLine">Codice grezzo</param> /// <param name="LineNumber">Numero della linea</param> /// <param name="lm">Gestore dei messaggi</param> /// <returns>Restituisce una linea di codice composta</returns> public static CodeLine LineExtractor(string RawLine, int LineNumber, LogManager lm) { if (string.IsNullOrWhiteSpace(RawLine)) { if (RawLine == null) { lm.Add("The translator cannot work on the that line", LineNumber); } return(null); } int level = CountIntendation(RawLine); RawLine = CodeCleaner.RemoveTabulation(RawLine, lm); RawLine = CodeCleaner.ReduceWitheSpaces(RawLine, lm); if (level == -1) { lm.Add("The translator cannot found the level of the indentation on that line", LineNumber); return(null); } else { return(new CodeLine(RawLine, LineNumber, level)); } }
//Metodo statico /// <summary> /// Crea un immagine del codice con tuttte le sezioni ripulite ed esplicitate /// </summary> /// <param name="RawCode">Codice da analizzare</param> /// <param name="PackageAdd">Pacchetti aggiunti nel sistema</param> /// <param name="Type">Tipo di codice</param> /// <param name="lm">Gestore di messaggi</param> /// <returns>Immagine del codice</returns> public static CodeImage CreateCodeImage(string RawCode, PackageCollection PackageAdd, CodeType Type, LogManager lm) { //Pachet name string[] packageName; SectionCollection sc; VariableCollection vc; //Costanti PackageCollection pc; //Pacchetti inclusi bool exactType = false; string PackName = null; //Pulizia RawCode = CodeCleaner.TextReturnUnified(RawCode, lm); vc = CodeElaborator.ExtractConstant(ref RawCode, lm); RawCode = CodeCleaner.CommentDelete(RawCode, lm); RawCode = CodeCleaner.RemoveSynonyms(RawCode, lm); RawCode = CodeCleaner.StartLineUnified(RawCode, 4, lm); RawCode = CodeCleaner.ReduceWitheSpaces(RawCode, lm); //Analisi Include packageName = CodeElaborator.IncludeFinder(RawCode, lm); RawCode = CodeElaborator.RemoveInclude(RawCode, lm); //Tipo exactType = CodeElaborator.CheckIfCorrectType(RawCode, Type, lm); if (!exactType) { lm.Add("The code is wrong for the current type of compilation"); } //Estrazione codice sc = SectionCollection.ExtractCollection(RawCode, lm); //Selezione pacchetti pc = PackageAdd.IncludedPackage(packageName, lm); //Creazione aggiunta per pacchetti if (Type == CodeType.Package) { PackName = CodeElaborator.PackegeNameExtractor(RawCode, lm); RawCode = CodeElaborator.RemovePackageName(RawCode, lm); } return((Type == CodeType.Program) ? new CodeImage(sc, pc, vc, Type) : new CodeImage(sc, pc, vc, Type, PackName)); }