コード例 #1
0
        // Try match at least start
        private TokenDescription.TokenDescriptionMatch CoreStartMatch(string line,
                                                                      int startAt,
                                                                      IReadOnlyList <Token> context)
        {
            // Starts
            foreach (var item in m_Items)
            {
                if (item.TryMatchStart(line, startAt, context, out var match))
                {
                    // No Stop match, just return the start
                    if (!item.TryMatchStop(line, startAt + match.Length, context, out var matchStop, match.Extract(line))) // + 1 removed !!!!!!
                    {
                        return(match);
                    }

                    // Let's combine start and stop into entire
                    TokenDescription.TokenDescriptionMatch matchEntire =
                        new TokenDescription.TokenDescriptionMatch(match.Description, match.From, matchStop.To, TokenMatchKind.Entire);

                    return(matchEntire);
                }
            }

            return(TokenDescription.TokenDescriptionMatch.EmptyMatch);
        }
コード例 #2
0
        /// <summary>
        /// Match (start or entire)
        /// </summary>
        public TokenDescription.TokenDescriptionMatch Match(string line,
                                                            int startAt,
                                                            IReadOnlyList <Token> context)
        {
            if (string.IsNullOrEmpty(line))
            {
                return(TokenDescription.TokenDescriptionMatch.EmptyMatch);
            }
            else if (startAt >= line.Length)
            {
                return(TokenDescription.TokenDescriptionMatch.EmptyMatch);
            }

            if (null == context)
            {
                context = new List <Token>();
            }

            CoreUpdate();

            TokenDescription.TokenDescriptionMatch match1 = CoreEntireMatch(line, startAt, context);
            TokenDescription.TokenDescriptionMatch match2 = CoreStartMatch(line, startAt, context);

            if (!match1.IsMatch)
            {
                return(match2);
            }
            else if (!match2.IsMatch)
            {
                return(match1);
            }

            if (match1.Description.Priority < match2.Description.Priority) // was < ???
            {
                return(match1);
            }
            else
            {
                return(match2);
            }
        }