Exemple #1
0
        /// <summary>
        /// Loads the listener.
        /// </summary>
        /// <param name="assemblyName">Path to the assembly containing the listener class.</param>
        /// <param name="className">Name of the listener class in the assembly.</param>
        /// <returns>A new Parse Listener object.</returns>
        /// <exception cref="ParseCodeException">
        /// Thrown when a valid BaseParser object cannot be created.
        /// </exception>
        public static IParseListener LoadListener(string assemblyName, string className)
        {
            Assembly assembly = Assembly.Load(AssemblyName.GetAssemblyName(assemblyName));

            if (assembly == null)
            {
                throw new ParseCodeException(string.Format("Assembly {0} not loaded", assemblyName));
            }

            Type type = assembly.GetType(className, true);

            if (type == null)
            {
                throw new ParseCodeException(string.Format("{0} not found in assembly: {1}", className, assemblyName));
            }

            IParseListener parseListener = Activator.CreateInstance(type) as IParseListener;

            if (parseListener == null)
            {
                throw new ParseCodeException(string.Format("{0} does not implement IParseListener", type.Name));
            }

            return(parseListener);
        }
    public bool Parse(string line, IParseListener listener)
    {
      if (string.IsNullOrEmpty(line.Trim()))
      {
        return true;
      }

      return false;
    }
    public bool Parse(string line, IParseListener resultBuilder)
    {
      foreach (var parser in _lineParsers)
      {
        var parsed = parser.Parse(line, resultBuilder);
        if (parsed) return true;
      }

      return false;
    }
    public bool Parse(string line, IParseListener listener)
    {
      var match = regex.Match(line);
      if (!match.Success)
        return false;

      listener.OnNamespace(match.Groups["namespace"].Value);

      return true;
    }
    void ParseLine(string line, IParseListener listener)
    {
      listener.BeginLine(_currentLineNumber, line);
      var parsed = _lineParser.Parse(line, listener);

      if (!parsed)
      {
        listener.AddError("Sorry, no idea what this line is supposed to be.");
      }
    }
    public void Parse(TextReader reader, IParseListener listener)
    {
      if (reader == null) throw new ArgumentNullException("reader");

      _currentLineNumber = 0;
      string line = reader.ReadLine();
      while (line != null)
      {
        ParseLine(line, listener);

        ++_currentLineNumber;
        line = reader.ReadLine();
      }
    }
    public bool Parse(string line, IParseListener listener)
    {
      var match = Regex.Match(line);
      if (!match.Success)
        return false;

      var verbs = match.GroupCaptures("acceptedVerb").Select(x => x.Value);
      var url = match.Groups["url"].Value;
      var hash = match.Groups["hash"].Value;
      var comment = match.Groups["comment"].Value;

      listener.OnUrl(verbs, url, hash, comment);

      return true;
    }