public RegexCharClass(RegexBuffer buffer)
        {
            int startLocation = buffer.Offset;

            buffer.MoveNext();
            Match match = new Regex(@"(?<Negated>\^?)(?<Class>.+?)\]").Match(buffer.String);

            if (match.Success)
            {
                if (match.Groups["Negated"].ToString() == "^")
                {
                    this.description = string.Format("Any character not in \"{0}\"", match.Groups["Class"]);
                }
                else
                {
                    this.description = string.Format("Any character in \"{0}\"", match.Groups["Class"]);
                }
                buffer.Offset += match.Groups[0].Length;
            }
            else
            {
                this.description = "missing ']' in character class";
            }
            buffer.AddLookup(this, startLocation, buffer.Offset - 1);
        }
        public RegexQuantifier(RegexBuffer buffer)
        {
            int startLocation = buffer.Offset;

            buffer.MoveNext();
            Match match = new Regex(@"(?<n>\d+)(?<Comma>,?)(?<m>\d*)\}").Match(buffer.String);

            if (match.Success)
            {
                if (match.Groups["m"].Length != 0)
                {
                    this.description = string.Format("At least {0}, but not more than {1} times", match.Groups["n"], match.Groups["m"]);
                }
                else if (match.Groups["Comma"].Length != 0)
                {
                    this.description = string.Format("At least {0} times", match.Groups["n"]);
                }
                else
                {
                    this.description = string.Format("Exactly {0} times", match.Groups["n"]);
                }
                buffer.Offset += match.Groups[0].Length;
                if (!buffer.AtEnd && (buffer.Current == '?'))
                {
                    this.description = this.description + " (non-greedy)";
                    buffer.MoveNext();
                }
            }
            else
            {
                this.description = "missing '}' in quantifier";
            }
            buffer.AddLookup(this, startLocation, buffer.Offset - 1);
        }
Beispiel #3
0
 public RegexConditional(RegexBuffer buffer)
 {
     this.startLocation = buffer.Offset;
     this.expression    = new RegexExpression(buffer);
     this.CheckClosingParen(buffer);
     this.yesNo = new RegexExpression(buffer);
     this.CheckClosingParen(buffer);
     buffer.AddLookup(this, this.startLocation, buffer.Offset - 1);
 }
Beispiel #4
0
 public RegexCapture(RegexBuffer buffer)
 {
     this.startLocation = buffer.Offset;
     buffer.MoveNext();
     buffer.ClearInSeries();
     if (buffer.Current == '?')
     {
         bool flag = this.CheckNamed(buffer);
         if (!flag)
         {
             flag = this.CheckBalancedGroup(buffer);
         }
         if (!flag)
         {
             flag = this.CheckNonCapturing(buffer);
         }
         if (!flag)
         {
             flag = this.CheckOptions(buffer);
         }
         if (!flag)
         {
             flag = this.CheckLookahead(buffer);
         }
         if (!flag)
         {
             flag = this.CheckNonBacktracking(buffer);
         }
         if (!flag)
         {
             flag = this.CheckConditional(buffer);
         }
     }
     else if (!this.HandlePlainOldCapture(buffer))
     {
         throw new Exception(string.Format("Unrecognized capture: {0}", buffer.String));
     }
     buffer.AddLookup(this, this.startLocation, buffer.Offset - 1);
 }
 public RegexAlternate(RegexBuffer buffer)
 {
     buffer.AddLookup(this, buffer.Offset, buffer.Offset);
     buffer.MoveNext();
 }
Beispiel #6
0
        public RegexCharacter(RegexBuffer buffer)
        {
            int  startLocation = buffer.Offset;
            bool flag          = false;

            switch (buffer.Current)
            {
            case ' ':
                this.character = "' ' (space)";
                buffer.MoveNext();
                break;

            case '$':
                this.character = "$ (anchor to end of string)";
                buffer.MoveNext();
                break;

            case '*':
                this.character = "* (zero or more times)";
                buffer.MoveNext();
                this.special = true;
                flag         = true;
                break;

            case '+':
                this.character = "+ (one or more times)";
                buffer.MoveNext();
                this.special = true;
                flag         = true;
                break;

            case '.':
                this.character = ". (any character)";
                buffer.MoveNext();
                this.special = true;
                break;

            case '?':
                this.character = "? (zero or one time)";
                buffer.MoveNext();
                this.special = true;
                flag         = true;
                break;

            case '\\':
                this.DecodeEscape(buffer);
                break;

            case '^':
                this.character = "^ (anchor to start of string)";
                buffer.MoveNext();
                break;

            default:
                this.character = buffer.Current.ToString();
                buffer.MoveNext();
                this.special = false;
                break;
            }
            if ((flag && !buffer.AtEnd) && (buffer.Current == '?'))
            {
                this.character = this.character + " (non-greedy)";
                buffer.MoveNext();
            }
            buffer.AddLookup(this, startLocation, buffer.Offset - 1, this.character.Length == 1);
        }