示例#1
0
 public Label(DocLocation loc, string labelName, string description, ParserInformation parent)
 {
     LabelName   = labelName;
     Location    = loc;
     Description = description;
     Parent      = parent;
 }
示例#2
0
 public Equate(DocLocation loc, string labelName, string value, string description, ParserInformation parent)
 {
     LabelName   = labelName;
     Location    = loc;
     Description = description;
     Parent      = parent;
     Value       = value;
 }
示例#3
0
 public Define(DocLocation loc, string macroName, string contents, string description, ParserInformation parent, int value)
 {
     Location    = loc;
     Name        = macroName;
     Contents    = contents;
     Description = description;
     Parent      = parent;
     Value       = value;
 }
示例#4
0
        public void RemoveParseData(FilePath fullPath)
        {
            ParserInformation replaceMe = GetParseInfo(fullPath);

            if (replaceMe != null)
            {
                ParserInfomInformation.Remove(replaceMe);
            }
        }
        public void ParseFile(int hashCode, FilePath file, string fileText)
        {
            if (file == null)
            {
                System.Diagnostics.Debug.WriteLine("No file name specified");
                return;
            }

            if (string.IsNullOrEmpty(fileText))
            {
                System.Diagnostics.Debug.WriteLine("Lines were null or empty");
                return;
            }

            if (hashCode == 0)
            {
                hashCode = fileText.GetHashCode();
            }

            string  extension = Path.GetExtension(file);
            IParser parser    = _parserFactory.CreateFromExtension(extension);

            if (parser == null)
            {
                return;
            }

            ParserInformation parserInfo = new ParserInformation(hashCode, file);

            parser.ParseText(parserInfo, fileText);

            lock (_parserInfoDictionary)
            {
                _parserInfoDictionary.Remove(file);
                _parserInfoDictionary.Add(file, parserInfo);
                foreach (var item in _parserInfoDictionary)
                {
                    item.Value.IsIncluded = false;
                }
            }

            if (OnParserFinished != null)
            {
                OnParserFinished(this, new ParserEventArgs(file));
            }
        }
示例#6
0
        protected override void Execute()
        {
            ParserInformation info         = _parserData.Parent;
            FilePath          file         = info.SourceFile;
            IIncludeFile      includedFile = _parserData as IIncludeFile;

            if (includedFile != null)
            {
                string   path     = Path.Combine(_projectService.Project.ProjectDirectory, includedFile.IncludedFile);
                FilePath filePath = new FilePath(path);
                RunCommand(new OpenFileAction(filePath));
            }
            else
            {
                RunCommand(new GotoLineAction(file, _parserData.Location.Line));
            }
        }
示例#7
0
        private void AddLabels()
        {
            var fileEditor = DockingService.ActiveDocument as AbstractFileEditor;

            if (fileEditor == null)
            {
                return;
            }

            FilePath fileName = fileEditor.FileName;

            if (fileName == null)
            {
                return;
            }

            ParserInformation info = _parserService.GetParserInfo(fileName);

            if (info == null)
            {
                ClearLabels();
                return;
            }

            bool showEquates = includeEquatesBox.Checked;

            ListBox.ObjectCollection labelsToAdd = new ListBox.ObjectCollection(labelsBox);

            var labels = info.Where(d => (d is Label && !((Label)d).IsReusable) ||
                                    ((d is Equate || d is Define || d is Macro) && showEquates))
                         .Cast <object>().ToArray();

            labelsToAdd.AddRange(labels);

            labelsBox.Items.Clear();
            labelsBox.Items.AddRange(labelsToAdd);
        }
        /// <summary>
        /// Parses a file for useful information
        /// </summary>
        /// <param name="file">Text in the file to read</param>
        /// <param name="lines"></param>
        /// <param name="increment"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public ParserInformation ParseFile(string file, string lines, float increment = .05f, Action <double> callback = null)
        {
            if (string.IsNullOrEmpty(file))
            {
                throw new FileNotFoundException("No file name specified");
            }
            if (string.IsNullOrEmpty(lines))
            {
                throw new Exception("Lines were null or empty");
            }
            ParserInformation info = new ParserInformation(file);
            int    counter = 0;
            double percent = 0, newPercent;

            while (counter < lines.Length && counter >= 0)
            {
                newPercent = counter / lines.Length;
                if (newPercent < percent)
                {
                    //should never get here
                    throw new Exception("Repeat!");
                }
                if (percent + increment <= newPercent)
                {
                    percent = newPercent;
                    if (callback != null)
                    {
                        callback(percent);
                    }
                }
                //handle label other xx = 22 type define
                if (IsValidLabelChar(lines[counter]))
                {
                    string description = GetDescription(lines, counter);
                    int    newCounter  = GetLabel(lines, counter);
                    string labelName   = lines.Substring(counter, newCounter - counter);
                    if (newCounter < lines.Length && lines[newCounter] == ':')
                    {
                        //its definitely a label
                        Label labelToAdd = new Label(counter, labelName, false, description, info);
                        info.LabelsList.Add(labelToAdd);
                    }
                    else
                    {
                        int tempCounter = SkipWhitespace(lines, newCounter);
                        if (tempCounter == -1)
                        {
                            //it must be a label with no colon at the very end of a file
                            Label labelToAdd = new Label(counter, labelName, true, description, info);
                            info.LabelsList.Add(labelToAdd);
                            break;
                        }
                        if (lines[tempCounter] == '=')
                        {
                            Define defineToAdd;
                            tempCounter++;
                            int temp = SkipWhitespace(lines, tempCounter);
                            if (temp == -1)
                            {
                                //we hit the end of the file and didn't find a value after the =
                                defineToAdd = new Define(counter, labelName, String.Empty, description, info);
                                info.DefinesList.Add(defineToAdd);
                                break;
                            }
                            counter    = temp;
                            newCounter = SkipToEOCL(lines, tempCounter);
                            if (newCounter == -1)
                            {
                                newCounter = lines.Length + 1;
                            }
                            string contents = lines.Substring(counter, newCounter - counter - 1).Trim();
                            //its a define
                            defineToAdd = new Define(counter, labelName, contents, description, info, EvaluateContents(contents));
                            info.DefinesList.Add(defineToAdd);
                        }
                        else if (lines[tempCounter] == '(')
                        {
                            //must be a macro
                            counter = SkipToEOL(lines, counter);
                            continue;
                        }
                        else
                        {
                            string nextWord        = null;
                            int    secondWordStart = GetWord(lines, tempCounter);
                            if (secondWordStart != -1)
                            {
                                nextWord = lines.Substring(tempCounter, secondWordStart - tempCounter).ToLower();
                            }
                            if (secondWordStart != -1 && (nextWord == ".equ" || nextWord == "equ"))
                            {
                                Define defineToAdd;
                                //its an equate
                                secondWordStart = SkipWhitespace(lines, secondWordStart);
                                if (secondWordStart == -1)
                                {
                                    //we couldn't find second word start
                                    defineToAdd = new Define(counter, labelName, String.Empty, description, info, null);
                                    info.DefinesList.Add(defineToAdd);
                                    break;
                                }
                                int secondWordEnd = SkipToEOCL(lines, secondWordStart);
                                if (secondWordEnd == -1)
                                {
                                    secondWordEnd = lines.Length + 1;
                                }
                                string contents = lines.Substring(secondWordStart, secondWordEnd - secondWordStart - 1);
                                defineToAdd = new Define(counter, labelName, contents, description, info, EvaluateContents(contents));
                                info.DefinesList.Add(defineToAdd);
                            }
                            else
                            {
                                //it must be a label with no colon
                                Label labelToAdd = new Label(counter, labelName, true, description, info);
                                info.LabelsList.Add(labelToAdd);
                            }
                        }
                    }
                    counter = SkipToEOCL(lines, counter);
                    continue;
                }
                int tempVar = SkipWhitespace(lines, counter);
                if (tempVar == -1)
                {
                    counter = SkipToEOCL(lines, counter);
                    continue;
                }
                counter = tempVar;
                //string substring = lines.Substring(counter).ToLower();
                if (string.Compare(lines, counter, commentString, 0, commentString.Length, true) == 0)
                {
                    counter = FindString(lines, counter, endCommentString) + endCommentString.Length;
                }
                //handle macros, defines, and includes
                else if (string.Compare(lines, counter, defineString, 0, defineString.Length, true) == 0)
                {
                    Define defineToAdd;
                    string description = GetDescription(lines, counter);
                    counter += defineString.Length;
                    counter  = SkipWhitespace(lines, counter);
                    int newCounter = GetLabel(lines, counter);
                    if (newCounter == -1)
                    {
                        break;
                    }
                    string defineName = lines.Substring(counter, newCounter - counter);
                    if (string.IsNullOrEmpty(defineName))
                    {
                        continue;
                    }
                    counter    = SkipWhitespace(lines, newCounter);
                    newCounter = SkipToEOCL(lines, counter);
                    if (counter == -1 || counter + 1 == newCounter)
                    {
                        //end of the road
                        defineToAdd = new Define(counter, defineName, String.Empty, description, info);
                        info.DefinesList.Add(defineToAdd);
                        continue;
                    }
                    if (newCounter == -1)
                    {
                        newCounter = lines.Length + 1;
                    }

                    string contents = lines.Substring(counter, newCounter - counter - 1).Trim();
                    defineToAdd = new Define(counter, defineName, contents, description, info, EvaluateContents(contents));
                    info.DefinesList.Add(defineToAdd);
                    counter = newCounter;
                }
                else if (string.Compare(lines, counter, macroString, 0, macroString.Length, true) == 0)
                {
                    string description = GetDescription(lines, counter);
                    counter += macroString.Length;
                    //skip any whitespace
                    counter = SkipWhitespace(lines, counter);
                    int    newCounter = GetLabel(lines, counter);
                    string macroName  = lines.Substring(counter, newCounter - counter);
                    newCounter = FindChar(lines, newCounter, '(') + 1;
                    List <string> args;
                    if (counter == 0)
                    {
                        args = new List <string>();
                    }
                    else
                    {
                        args = GetMacroArgs(lines, newCounter);
                    }
                    counter    = SkipToEOL(lines, counter);
                    newCounter = FindString(lines, counter, endMacroString);
                    if (newCounter != -1)
                    {
                        string contents   = lines.Substring(counter, newCounter - counter);
                        Macro  macroToAdd = new Macro(counter, macroName, args, contents, description, info);
                        info.MacrosList.Add(macroToAdd);
                        counter = newCounter + endMacroString.Length;
                    }
                }
                else if (string.Compare(lines, counter, includeString, 0, includeString.Length, true) == 0)
                {
                    string description = GetDescription(lines, counter);
                    counter += includeString.Length;
                    //we need to find the quotes
                    counter = SkipWhitespace(lines, counter);
                    if (counter == -1)
                    {
                        continue;
                    }
                    int newCounter;
                    if (lines[counter] == '\"')
                    {
                        newCounter = FindChar(lines, ++counter, '\"');
                    }
                    else
                    {
                        newCounter = SkipToEOCL(lines, counter);
                    }
                    //if the end of line char is next, then newCounter will be counter + 1
                    if (counter == -1 || newCounter == -1 || counter + 1 == newCounter)
                    {
                        counter = SkipToEOL(lines, counter);
                    }
                    else
                    {
                        string includeFile = lines.Substring(counter, newCounter - counter).Trim();
                        if (!string.IsNullOrEmpty(includeFile))
                        {
                            IncludeFile includeToAdd = new IncludeFile(counter, includeFile, description, info);
                            if (!info.IncludeFilesList.Contains(includeToAdd))
                            {
                                info.IncludeFilesList.Add(includeToAdd);
                            }
                        }
                        counter = SkipToEOCL(lines, newCounter);
                    }
                }
                else if (lines[counter] == commentChar)
                {
                    counter = SkipToEOL(lines, counter);
                }
                else
                {
                    counter = SkipToEOCL(lines, counter);
                }
            }
            //HideProgressDelegate hideProgress = DockingService.MainForm.HideProgressBar;
            //DockingService.MainForm.Invoke(hideProgress);
            return(info);
        }
示例#9
0
 public InstructionException(Type errorType, ParserInformation parserInfo)
 {
     _errorType  = errorType;
     _parserInfo = parserInfo;
 }
示例#10
0
 public InstructionException( Type errorType, ParserInformation parserInfo )
 {
     _errorType = errorType;
     _parserInfo = parserInfo;
 }