This class supports "Match and Forward" pattern. On a failed match, the SetError method sets the ErrorMessage. On a successful match, the StartIndex is updated by a call to Forward so that the Head is positioned after the match (and any existing error is cleared).
예제 #1
0
 public void string_matcher_TryMatchJSONQuotedString( string s, string parsed, string textAfter )
 {
     var m = new StringMatcher( s );
     string result;
     Assert.That( m.TryMatchJSONQuotedString( out result, true ) );
     Assert.That( result, Is.EqualTo( parsed ) );
     Assert.That( m.TryMatchText( textAfter ), "Should be followed by: " + textAfter );
     
     m = new StringMatcher( s );
     Assert.That( m.TryMatchJSONQuotedString( true ) );
     Assert.That( m.TryMatchText( textAfter ), "Should be followed by: " + textAfter );
 }
예제 #2
0
 public JSONVersionFinder( StringMatcher m, Func<string,bool> projectNameFinder, List<VersionOccurrence> allVersions )
     : base( m )
 {
     _objectStart = -1;
     _versions = allVersions;
     _projectNameFinder = projectNameFinder;
     if( Visit() )
     {
         if( _thisVersion == null && _objectStart >= 0 )
         {
             _thisVersion = new VersionOccurrence( String.Empty, _objectStart, 0, _hasTopLevelProperties );
             if( _versions != null ) _versions.Insert( 0, _thisVersion );
         }
     }
     if( _thisVersion == null && _versions != null ) _versions.Clear();
 }
            /// <summary>
            /// Tries to parse a <see cref="DependentToken.ToString()"/> string.
            /// </summary>
            /// <param name="s">The string to parse.</param>
            /// <param name="t">The resulting dependent token.</param>
            /// <returns>True on success, false otherwise.</returns>
            static public bool TryParse(string s, out DependentToken t)
            {
                t = null;
                StringMatcher m = new StringMatcher(s);
                Guid          id;
                DateTimeStamp time;

                if (MatchOriginatorAndTime(m, out id, out time) && m.TryMatchText(" with"))
                {
                    string topic;
                    if (ExtractTopic(s, m.StartIndex, out topic))
                    {
                        t = new DependentToken(id, time, topic);
                        return(true);
                    }
                }
                return(false);
            }
 /// <summary>
 /// Matches a <see cref="LogLevelFilter"/>.
 /// </summary>
 /// <param name="this">This <see cref="StringMatcher"/>.</param>
 /// <param name="level">Resulting level.</param>
 /// <returns>True on success, false on error.</returns>
 public static bool MatchLogLevelFilter(this StringMatcher @this, out LogLevelFilter level)
 {
     level = LogLevelFilter.None;
     if ([email protected]("None"))
     {
         if (@this.MatchText("Trace"))
         {
             level = LogLevelFilter.Trace;
         }
         else if (@this.MatchText("Info"))
         {
             level = LogLevelFilter.Info;
         }
         else if (@this.MatchText("Warn"))
         {
             level = LogLevelFilter.Warn;
         }
         else if (@this.MatchText("Error"))
         {
             level = LogLevelFilter.Error;
         }
         else if (@this.MatchText("Fatal"))
         {
             level = LogLevelFilter.Fatal;
         }
         else if (@this.MatchText("Off"))
         {
             level = LogLevelFilter.Off;
         }
         else if (@this.MatchText("Invalid"))
         {
             level = LogLevelFilter.Invalid;
         }
         else
         {
             return(false);
         }
     }
     return(true);
 }
예제 #5
0
        /// <summary>
        /// Matches a <see cref="DateTimeStamp"/>.
        /// </summary>
        /// <param name="this">This <see cref="StringMatcher"/>.</param>
        /// <param name="time">Resulting time stamp on successful match; <see cref="DateTimeStamp.Unknown"/> otherwise.</param>
        /// <returns>True if the time stamp has been matched.</returns>
        static public bool MatchDateTimeStamp(this StringMatcher @this, out DateTimeStamp time)
        {
            time = DateTimeStamp.Unknown;
            int      savedIndex = @this.StartIndex;
            DateTime t;

            if ([email protected](out t))
            {
                return(@this.SetError());
            }
            byte uniquifier = 0;

            if (@this.MatchChar('('))
            {
                int unique;
                if ([email protected](out unique, 0, 255) || [email protected](')'))
                {
                    return(@this.BackwardAddError(savedIndex));
                }
                uniquifier = (byte)unique;
            }
            time = new DateTimeStamp(t, uniquifier);
            return(@this.Forward(0));
        }
예제 #6
0
 JSONFrameworksFinder( StringMatcher m, List<string> frameworks )
     : base( m )
 {
     _frameworks = frameworks;
     Visit();
 }
예제 #7
0
 public JSONVisitor( StringMatcher m )
 {
     _m = m;
     _path = new List<Parent>();
 }
예제 #8
0
 public JSONProperties( StringMatcher m)
     : base( m )
 {
     Properties = new List<string>();
     Paths = new List<string>();
 }
        /// <summary>
        /// Matches a <see cref="LogFilter"/>: it can be a predefined filter as ("Undefined", "Debug", "Verbose", etc.)
        /// or as {GroupLogLevelFilter,LineLogLevelFilter} pairs like "{None,None}", "{Error,Trace}".
        /// </summary>
        /// <param name="m">This <see cref="StringMatcher"/>.</param>
        /// <param name="f">Resulting filter.</param>
        /// <returns>True on success, false on error.</returns>
        public static bool MatchLogFilter(this StringMatcher m, out LogFilter f)
        {
            f = LogFilter.Undefined;
            if (!m.MatchText("Undefined"))
            {
                if (m.MatchText("Debug"))
                {
                    f = LogFilter.Debug;
                }
                else if (m.MatchText("Verbose"))
                {
                    f = LogFilter.Verbose;
                }
                else if (m.MatchText("Monitor"))
                {
                    f = LogFilter.Monitor;
                }
                else if (m.MatchText("Terse"))
                {
                    f = LogFilter.Terse;
                }
                else if (m.MatchText("Release"))
                {
                    f = LogFilter.Release;
                }
                else if (m.MatchText("Off"))
                {
                    f = LogFilter.Off;
                }
                else if (m.MatchText("Invalid"))
                {
                    f = LogFilter.Invalid;
                }
                else
                {
                    int savedIndex = m.StartIndex;

                    if (!m.MatchChar('{'))
                    {
                        return(m.BackwardAddError(savedIndex));
                    }
                    LogLevelFilter group, line;

                    m.MatchWhiteSpaces();
                    if (!m.MatchLogLevelFilter(out group))
                    {
                        return(m.BackwardAddError(savedIndex));
                    }

                    m.MatchWhiteSpaces();
                    if (!m.MatchChar(','))
                    {
                        return(m.BackwardAddError(savedIndex));
                    }

                    m.MatchWhiteSpaces();
                    if (!m.MatchLogLevelFilter(out line))
                    {
                        return(m.BackwardAddError(savedIndex));
                    }
                    m.MatchWhiteSpaces();

                    if (!m.MatchChar('}'))
                    {
                        return(m.BackwardAddError(savedIndex));
                    }
                    f = new LogFilter(group, line);
                }
            }
            return(true);
        }
예제 #10
0
 void ExtractVersions( string text )
 {
     StringMatcher m = new StringMatcher( text );
     var allVersions = new List<VersionOccurrence>();
     JSONVersionFinder finder = new JSONVersionFinder( m, _projectNameFinder, allVersions );
     _thisVersion = finder.ThisVersion;
     _allVersions = allVersions;
     _sameVersions = finder.SameVersions;
     _parseError = m.ErrorMessage;
 }
예제 #11
0
        /// <summary>
        /// Tries to parse a string formatted with the <see cref="FileNameUniqueTimeUtcFormat"/>.
        /// The string must contain only the time unless <paramref name="allowSuffix"/> is true.
        /// </summary>
        /// <param name="s">The string to parse.</param>
        /// <param name="time">Result time on success.</param>
        /// <param name="allowSuffix">True to accept a string that starts with the time and contains more text.</param>
        /// <returns>True if the string has been successfully parsed.</returns>
        public static bool TryParseFileNameUniqueTimeUtcFormat(string s, out DateTime time, bool allowSuffix = false)
        {
            var m = new StringMatcher(s);

            return(m.MatchFileNameUniqueTimeUtcFormat(out time) && (allowSuffix || m.IsEnd));
        }
예제 #12
0
        /// <summary>
        /// Tries to parse a <see cref="LogFilter"/>: it can be a predefined filter as ("Undefined", "Debug", "Verbose", etc.)
        /// or as {GroupLogLevelFilter,LineLogLevelFilter} pairs like "{None,None}", "{Error,Trace}".
        /// </summary>
        /// <param name="s">Filter to parse.</param>
        /// <param name="f">Resulting filter.</param>
        /// <returns>True on success, false on error.</returns>
        public static bool TryParse(string s, out LogFilter f)
        {
            var m = new StringMatcher(s);

            return(m.MatchLogFilter(out f) && m.IsEnd);
        }
예제 #13
0
 public JSONVisitor(StringMatcher m)
 {
     _m    = m;
     _path = new List <Parent>();
 }