Example #1
0
        public IParserData GetData(int index)
        {
            IParserData xmlData = (IParserData)Activator.CreateInstance(_dataType);

            XmlNode progNode = _nodeList.Item(index);

            if (progNode != null)
            {
                for (int i = 0; i < _data.Fields.Count; i++)
                {
                    XmlField field = _data.Fields[i];

                    XmlNode node;
                    if ((node = progNode.SelectSingleNode(field.XmlName)) != null)
                    {
                        xmlData.SetElement(field.FieldName, node.InnerText);
                    }
                    if ((node = progNode.Attributes.GetNamedItem(field.XmlName)) != null)
                    {
                        xmlData.SetElement(field.FieldName, node.InnerText);
                    }
                }
            }

            return(xmlData);
        }
        public void ParseSection2()
        {
            // Start and End for tag
            HtmlSectionTemplate template = new HtmlSectionTemplate();

            template.Tags     = "T";
            template.Template =
                "<table><tr><td>Title:<#TITLE>(</td><td><#START></td><td><#DESCRIPTION></td><Z(><td><#GENRE></td></Z)?></tr></table>";

            HtmlSectionParser elements = new HtmlSectionParser(template);

            ParserData  data   = new ParserData();
            IParserData idata  = (IParserData)data;
            string      source = "<table><tr><td>Test</td><td>123</td><td>blah blah</td></tr></table>";

            elements.ParseSection(source, ref idata);

            Assert.IsTrue(data.GetElement("#TITLE") == "Test");
            Assert.IsTrue(data.GetElement("#START") == "123");
            Assert.IsTrue(data.GetElement("#DESCRIPTION") == "blah blah");

            data   = new ParserData();
            idata  = (IParserData)data;
            source = "<table><tr><td>Title:Test(1:2)</td><td>123</td><td>blah blah</td></tr></table>";
            elements.ParseSection(source, ref idata);

            Assert.IsTrue(data.GetElement("#TITLE") == "Test");
            Assert.IsTrue(data.GetElement("#START") == "123");
            Assert.IsTrue(data.GetElement("#DESCRIPTION") == "blah blah");
        }
Example #3
0
        private void ValidateInput()
        {
            string      symbolName = inputBox.Text;
            IParserData data       = _parserService.GetParserData(symbolName, Settings.Default.CaseSensitive).FirstOrDefault();

            SetInputError(data == null ? "Invalid symbol name" : string.Empty);
        }
Example #4
0
        public IParserData GetData(int index)
        {
            string rowSource = _rows.GetSource(index);

            IParserData rowData = (IParserData)Activator.CreateInstance(_dataType);

            _parser.ParseRow(rowSource, ref rowData);

            return(rowData);
        }
        private void TextArea_ToolTipRequest(object sender, ToolTipRequestEventArgs e)
        {
            if (!e.InDocument)
            {
                return;
            }

            var segment = Document.GetLineSegment(e.LogicalPosition.Line);
            var word    = segment.GetWord(e.LogicalPosition.Column);

            if (word == null || string.IsNullOrEmpty(word.Word))
            {
                return;
            }

            string text = word.Word;
            string tooltip;

            try
            {
                IParserData data = _parserService.GetParserData(text, Settings.Default.CaseSensitive).FirstOrDefault();

                if (data == null)
                {
                    var address = _symbolService.SymbolTable.GetAddressFromLabel(text);
                    tooltip = address == null ? string.Empty : address.Value.ToString();
                }
                else
                {
                    tooltip = data.Description;
                }
            }
            catch (Exception)
            {
                return;
            }

            if (string.IsNullOrEmpty(tooltip))
            {
                if (_debuggerService.CurrentDebugger == null)
                {
                    return;
                }

                ushort?regValue = _debuggerService.CurrentDebugger.GetRegisterValue(text);
                if (!regValue.HasValue)
                {
                    return;
                }

                tooltip = "$" + regValue.Value.ToString("X");
            }

            e.ShowToolTip(tooltip);
        }
Example #6
0
    public bool ParseRow(string source, ref IParserData data)
    {
      ArrayList sourceData = GetElements(source);

      for (int i = 0; i < _templateData.Count && i < sourceData.Count; i++)
      {
        string template = (string)_templateData[i];

        if (template.IndexOf("#") != -1)
        {
          string rowSource = (string)sourceData[i];
          data.SetElement(template, rowSource);
        }
      }
      return true;
    }
Example #7
0
        public bool ParseRow(string source, ref IParserData data)
        {
            ArrayList sourceData = GetElements(source);

            for (int i = 0; i < _templateData.Count && i < sourceData.Count; i++)
            {
                string template = (string)_templateData[i];

                if (template.IndexOf("#") != -1)
                {
                    string rowSource = (string)sourceData[i];
                    data.SetElement(template, rowSource);
                }
            }
            return(true);
        }
        public override void SetupDataProvider(string fileName, TextArea textArea)
        {
            base.SetupDataProvider(fileName, textArea);

            string word = TextEditor.GetWordBeforeCaret();

            IParserService parserService = DependencyFactory.Resolve <IParserService>();
            var            parserData    = parserService.GetParserData(word, Settings.Default.CaseSensitive).ToList();

            Data.AddRange(parserData.Select(d =>
            {
                IParserData data = d;
                while (data != null)
                {
                    string description = data.Description;
                    IMacro macro       = data as IMacro;
                    if (macro != null)
                    {
                        string argDesc = macro.Arguments.Aggregate(macro.Name + "(", (current, arg) => current + (arg + ", "));
                        if (argDesc.Length > 2)
                        {
                            argDesc = argDesc.Remove(argDesc.Length - 2);
                        }
                        argDesc += ")";
                        return(argDesc + "\n" + description);
                    }

                    if (!string.IsNullOrEmpty(data.Description))
                    {
                        return(description);
                    }

                    if (d is IDefine)
                    {
                        data = parserService.TryResolveDefine(d as IDefine, Settings.Default.CaseSensitive);
                    }
                    else
                    {
                        break;
                    }
                }

                return(null);
            })
                          .Where(d => d != null));
        }
        // Compare the length of the strings, or the strings
        // themselves, if they are the same length.
        public int Compare(object x, object y)
        {
            IParserData datax = x as IParserData;
            IParserData datay = y as IParserData;

            if (datax == null || datay == null || datax.Offset == datay.Offset)
            {
                return(0);
            }
            if (datax.Offset > datay.Offset)
            {
                return(1);
            }
            else
            {
                return(-1);
            }
        }
Example #10
0
 public int CompareTo(IParserData other)
 {
     if (other == null)
     {
         return(1);
     }
     if (Offset == other.Offset)
     {
         return(0);
     }
     if (Offset > other.Offset)
     {
         return(1);
     }
     else
     {
         return(-1);
     }
 }
        public void ParseSection3()
        {
            // Multiple tags
            HtmlSectionTemplate template = new HtmlSectionTemplate();

            template.Tags     = "T";
            template.Template =
                "<table><tr><td><#TITLE>-<#SUBTITLE></td><td><#START></td><td><#DESCRIPTION></td><Z(><td><#GENRE></td></Z)?></tr></table>";

            HtmlSectionParser elements = new HtmlSectionParser(template);
            ParserData        data     = new ParserData();
            IParserData       idata    = (IParserData)data;
            string            source   = "<table><tr><td>Test-Sub</td><td>123</td><td>blah blah</td></tr></table>";

            elements.ParseSection(source, ref idata);

            Assert.IsTrue(data.GetElement("#TITLE") == "Test");
            Assert.IsTrue(data.GetElement("#SUBTITLE") == "Sub");
            Assert.IsTrue(data.GetElement("#START") == "123");
            Assert.IsTrue(data.GetElement("#DESCRIPTION") == "blah blah");
        }
        public IParserData GetData(int index)
        {
            IParserData jSONData = (IParserData)Activator.CreateInstance(_dataType);

            JSONNode progNode = _nodeList[index];

            if (progNode != null)
            {
                for (int i = 0; i < _data.Fields.Count; i++)
                {
                    JSONField       field   = _data.Fields[i];
                    List <JSONNode> subNode = progNode.GetNodes(field.JSONName, null);
                    if (subNode.Count > 0)
                    {
                        jSONData.SetElement(field.FieldName, subNode[0].GetValue(""));
                    }
                }
            }

            return(jSONData);
        }
Example #13
0
 public int CompareTo(IParserData other)
 {
     if (Parent != null && !Parent.Equals(other.Parent))
     {
         return(1);
     }
     if (other is IIncludeFile)
     {
         return(Name.CompareTo(other.Name));
     }
     else if (other.Offset < Offset)
     {
         return(1);
     }
     else if (other.Offset == Offset)
     {
         return(0);
     }
     else
     {
         return(-1);
     }
 }
Example #14
0
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>Parser Data</returns>
        public IParserData GetData(int index)
        {
            string sectionSource;

            if (_sectionSource != string.Empty)
            {
                sectionSource  = _sectionSource;
                _sectionSource = string.Empty;
            }
            else
            {
                sectionSource = _profiler.GetSource(index);
            }

            // create a new IParserData object from the type and arguments given to the constructor
            IParserData sectionData = (IParserData)Activator.CreateInstance(_dataType, _dataArgs);

            if (_sectionParser.ParseSection(sectionSource, ref sectionData))
            {
                return(sectionData);
            }
            return(null);
        }
Example #15
0
        private void editorBox_MouseHover(object sender, EventArgs e)
        {
            RemoveCurrentMarker();

            if ((Control.ModifierKeys & Keys.Control) == 0)
            {
                return;
            }

            TextArea textArea = (TextArea)sender;
            var      point    = textArea.PointToClient(Control.MousePosition);
            var      location = GetWordUnderCursor(point);
            var      textWord = GetTextWordAtLocation(location);

            if (textWord == null)
            {
                return;
            }

            string      symbolName = textWord.Word;
            IParserData data       = _parserService.GetParserData(symbolName, Settings.Default.CaseSensitive).FirstOrDefault();

            if (data == null)
            {
                return;
            }

            IDocument document = textArea.Document;
            int       offset   = document.GetOffsetForLineNumber(location.Line) + textWord.Offset;

            _currentMarkerLine = location.Line;
            _currentMarker     = new TextMarker(offset, textWord.Length, TextMarkerType.Underlined, Color.Black);
            document.MarkerStrategy.AddMarker(_currentMarker);
            document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, _currentMarkerLine));
            document.CommitUpdate();
        }
Example #16
0
 public GotoLabelAction(IParserData parserData)
 {
     _parserData = parserData;
 }
 public CustomParser(IParserData data)
     : base(data)
 {
 }
Example #18
0
        /// <summary>
        /// Parses the section.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="data">The data.</param>
        /// <returns>bool - success/fail</returns>
        public bool ParseSection(string source, ref IParserData data)
        {
            Sections sourceData  = GetSections(source);
            bool     hasOptional = false;
            bool     hasMatched  = false;
            int      dataFound   = 0;

            if (sourceData.dataFields.Count == 0)
            {
                return(false);
            }

            if (sourceData.dataFields.Count > _templateData.minFields)
            {
                hasOptional = true;
            }

            int s = 0;

            for (int t = 0; t < _templateData.dataFields.Count; t++)
            {
                DataField templateField = (DataField)_templateData.dataFields[t];

                if (templateField.optional)
                {
                    if (!hasOptional)
                    {
                        continue;
                    }
                }

                if (s < sourceData.dataFields.Count)
                {
                    DataField sourceField = (DataField)sourceData.dataFields[s];

                    if (!templateField.hasData &&
                        templateField.htmlTag != null &&
                        sourceField.htmlTag != null)
                    {
                        if (templateField.htmlTag.SameType(sourceField.htmlTag))
                        {
                            s++;
                        }
                    }
                    else
                    {
                        if (templateField.source != string.Empty &&
                            templateField.hasData)
                        {
                            int index = 0;
                            for (int i = 0; i < templateField.dataElements.Count; i++)
                            {
                                ElementData element = (ElementData)templateField.dataElements[i];

                                int startPos;
                                if (index < sourceField.source.Length)
                                {
                                    if (element.start == string.Empty ||
                                        (startPos = sourceField.source.IndexOf(element.start, index, StringComparison.OrdinalIgnoreCase)) ==
                                        -1)
                                    {
                                        startPos = index;
                                    }
                                    else
                                    {
                                        startPos = startPos + element.start.Length;
                                    }

                                    int endPos;
                                    if (element.end == string.Empty ||
                                        (endPos = sourceField.source.IndexOf(element.end, startPos, StringComparison.OrdinalIgnoreCase)) ==
                                        -1)
                                    {
                                        endPos = sourceField.source.Length;
                                    }

                                    string elementSource = sourceField.source.Substring(startPos, endPos - startPos);

                                    if (elementSource != string.Empty)
                                    {
                                        if (element.name[0] == '*')
                                        {
                                            if (hasMatched && element.name == "*VALUE")
                                            {
                                                data.SetElement(_matchField, elementSource);
                                                hasMatched = false;
                                            }
                                            else
                                            {
                                                if (IsMatch(element.name, elementSource))
                                                {
                                                    hasMatched = true;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            data.SetElement(element.name, elementSource);
                                        }
                                        dataFound++;
                                        if (dataFound == _templateData.dataTags)
                                        {
                                            break;
                                        }
                                    }
                                    index = endPos + element.end.Length;
                                }
                            }
                        }
                        s++;
                    }
                }
            }

            if (dataFound == 0 && _templateData.dataTags > 0)
            {
                return(false);
            }

            return(true);
        }
 public ParserBase(IParserData parserData)
 {
     Data = parserData;
 }
    /// <summary>
    /// Parses the section.
    /// </summary>
    /// <param name="source">The source.</param>
    /// <param name="data">The data.</param>
    /// <returns>bool - success/fail</returns>
    public bool ParseSection(string source, ref IParserData data)
    {
      Sections sourceData = GetSections(source);
      bool hasOptional = false;
      bool hasMatched = false;
      int dataFound = 0;

      if (sourceData.dataFields.Count == 0)
      {
        return false;
      }

      if (sourceData.dataFields.Count > _templateData.minFields)
      {
        hasOptional = true;
      }

      int s = 0;
      for (int t = 0; t < _templateData.dataFields.Count; t++)
      {
        DataField templateField = (DataField)_templateData.dataFields[t];

        if (templateField.optional)
        {
          if (!hasOptional)
          {
            continue;
          }
        }

        if (s < sourceData.dataFields.Count)
        {
          DataField sourceField = (DataField)sourceData.dataFields[s];

          if (!templateField.hasData &&
              templateField.htmlTag != null &&
              sourceField.htmlTag != null)
          {
            if (templateField.htmlTag.SameType(sourceField.htmlTag))
            {
              s++;
            }
          }
          else
          {
            if (templateField.source != string.Empty &&
                templateField.hasData)
            {
              int index = 0;
              for (int i = 0; i < templateField.dataElements.Count; i++)
              {
                ElementData element = (ElementData)templateField.dataElements[i];

                int startPos;
                if (index < sourceField.source.Length)
                {
                  if (element.start == string.Empty ||
                      (startPos = sourceField.source.IndexOf(element.start, index, StringComparison.OrdinalIgnoreCase)) ==
                      -1)
                  {
                    startPos = index;
                  }
                  else
                  {
                    startPos = startPos + element.start.Length;
                  }

                  int endPos;
                  if (element.end == string.Empty ||
                      (endPos = sourceField.source.IndexOf(element.end, startPos, StringComparison.OrdinalIgnoreCase)) ==
                      -1)
                  {
                    endPos = sourceField.source.Length;
                  }

                  string elementSource = sourceField.source.Substring(startPos, endPos - startPos);

                  if (elementSource != string.Empty)
                  {
                    if (element.name[0] == '*')
                    {
                      if (hasMatched && element.name == "*VALUE")
                      {
                        data.SetElement(_matchField, elementSource);
                        hasMatched = false;
                      }
                      else
                      {
                        if (IsMatch(element.name, elementSource))
                        {
                          hasMatched = true;
                        }
                      }
                    }
                    else
                    {
                      data.SetElement(element.name, elementSource);
                    }
                    dataFound++;
                    if (dataFound == _templateData.dataTags)
                    {
                      break;
                    }
                  }
                  index = endPos + element.end.Length;
                }
              }
            }
            s++;
          }
        }
      }

      if (dataFound == 0 && _templateData.dataTags > 0)
      {
        return false;
      }

      return true;
    }
Example #21
0
 private static void GotoLabel(IParserData parserData)
 {
     AbstractUiAction.RunCommand(new GotoLabelAction(parserData));
 }