Ejemplo n.º 1
0
        bool CheckNamed(RegexBuffer buffer)
        {
            Regex regex;
            Match match;

            // look for ?<Name> or ?'Name' syntax...
            regex = new Regex(@"
				        ^                         # anchor to start of string
						\?(\<|')                  # ?< or ?'
						(?<Name>[a-zA-Z0-9]+?)    # Capture name
						(\>|')                    # ?> or ?'
						(?<Rest>.+)               # The rest of the string
						"                        ,
                              RegexOptions.IgnorePatternWhitespace);

            match = regex.Match(buffer.String);
            if (match.Success)
            {
                description = String.Format("Capture to <{0}>", match.Groups["Name"]);

                // advance buffer to the rest of the expression
                buffer.Offset += match.Groups["Rest"].Index;
                expression     = new RegexExpression(buffer);

                CheckClosingParen(buffer);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        bool CheckBalancedGroup(RegexBuffer buffer)
        {
            // look for ?<Name1-Name2> or ?'Name1-Name2' syntax...
            // look for ?<Name> or ?'Name' syntax...
            Regex regex = new Regex(@"
				        ^                         # anchor to start of string
						\?[\<|']                  # ?< or ?'
						(?<Name1>[a-zA-Z]+?)       # Capture name1
						-
						(?<Name2>[a-zA-Z]+?)       # Capture name2
						[\>|']                    # ?> or ?'
						(?<Rest>.+)               # The rest of the expression
						"                        ,
                                    RegexOptions.IgnorePatternWhitespace);

            Match match = regex.Match(buffer.String);

            if (match.Success)
            {
                description    = String.Format("Balancing Group <{0}>-<{1}>", match.Groups["Name1"], match.Groups["Name2"]);
                buffer.Offset += match.Groups["Rest"].Index;
                expression     = new RegexExpression(buffer);
                CheckClosingParen(buffer);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
 public void AddLookup(RegexItem item, int startLocation, int endLocation, bool canCoalesce)
 {
     if (inSeries)
     {
         // in a series, add character to the previous one...
         if (canCoalesce)
         {
             RegexRef lastItem = (RegexRef)expressionLookup[expressionLookup.Count - 1];
             lastItem.StringValue += item.ToString(0);
             lastItem.Length      += endLocation - startLocation + 1;
         }
         else
         {
             expressionLookup.Add(new RegexRef(item, startLocation, endLocation));
             inSeries = false;
         }
     }
     else
     {
         if (canCoalesce)
         {
             inSeries = true;
         }
         expressionLookup.Add(new RegexRef(item, startLocation, endLocation));
     }
 }
Ejemplo n.º 4
0
        bool HandlePlainOldCapture(RegexBuffer buffer)
        {
            // we're already at the expression. Just create a new
            // expression, and make sure that we're at a ")" when
            // we're done
            if (buffer.ExplicitCapture)
            {
                description = String.Format("Non-capturing Group");
            }

            expression = new RegexExpression(buffer);
            CheckClosingParen(buffer);
            return(true);
        }
Ejemplo n.º 5
0
        bool CheckOptions(RegexBuffer buffer)
        {
            // look for ?imnsx-imnsx:
            Regex regex = new Regex(@"
				        ^                         # anchor to start of string
						\?(?<Options>[imnsx-]+):
						"                        ,
                                    RegexOptions.IgnorePatternWhitespace);

            Match match = regex.Match(buffer.String);

            if (match.Success)
            {
                string option = match.Groups["Options"].Value;
                description = String.Format("Set options to {0}",
                                            optionNames[option]);
                expression     = null;
                buffer.Offset += match.Groups[0].Length;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
0
        bool CheckLookahead(RegexBuffer buffer)
        {
            Regex regex = new Regex(@"
				        ^                         # anchor to start of string
						\?
						(?<Assertion><=|<!|=|!)   # assertion char
						(?<Rest>.+)               # The rest of the expression
						"                        ,
                                    RegexOptions.IgnorePatternWhitespace);

            Match match = regex.Match(buffer.String);

            if (match.Success)
            {
                switch (match.Groups["Assertion"].Value)
                {
                case "=":
                    description = "zero-width positive lookahead";
                    break;

                case "!":
                    description = "zero-width negative lookahead";
                    break;

                case "<=":
                    description = "zero-width positive lookbehind";
                    break;

                case "<!":
                    description = "zero-width negative lookbehind";
                    break;
                }
                buffer.Offset += match.Groups["Rest"].Index;
                expression     = new RegexExpression(buffer);
                CheckClosingParen(buffer);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        bool CheckConditional(RegexBuffer buffer)
        {
            // Look for conditional (?(name)yesmatch|nomatch)
            // (name can also be an expression)

            Regex regex = new Regex(@"
				        ^                         # anchor to start of string
						\?\(
						(?<Rest>.+)             # The rest of the expression
						"                        ,
                                    RegexOptions.IgnorePatternWhitespace);
            Match match = regex.Match(buffer.String);

            if (match.Success)
            {
                description = String.Format("Conditional Subexpression");

                buffer.Offset += match.Groups["Rest"].Index;
                expression     = new RegexConditional(buffer);

                return(true);
            }
            return(false);
        }
Ejemplo n.º 8
0
        bool CheckNonBacktracking(RegexBuffer buffer)
        {
            // Look for non-backtracking sub-expression ?>

            Regex regex = new Regex(@"
				        ^                         # anchor to start of string
						\?\>
						(?<Rest>.+)             # The rest of the expression
						"                        ,
                                    RegexOptions.IgnorePatternWhitespace);
            Match match = regex.Match(buffer.String);

            if (match.Success)
            {
                description = String.Format("Non-backtracking subexpressio");

                buffer.Offset += match.Groups["Rest"].Index;
                expression     = new RegexExpression(buffer);

                this.CheckClosingParen(buffer);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 9
0
 public RegexRef(RegexItem regexItem, int start, int end)
 {
     stringValue = regexItem.ToString(0);
     this.start = start;
     this.end = end;
 }
Ejemplo n.º 10
0
        bool CheckBalancedGroup(RegexBuffer buffer)
        {
            // look for ?<Name1-Name2> or ?'Name1-Name2' syntax...
            // look for ?<Name> or ?'Name' syntax...
            Regex regex = new Regex(@"
                        ^                         # anchor to start of string
                        \?[\<|']                  # ?< or ?'
                        (?<Name1>[a-zA-Z]+?)       # Capture name1
                        -
                        (?<Name2>[a-zA-Z]+?)       # Capture name2
                        [\>|']                    # ?> or ?'
                        (?<Rest>.+)               # The rest of the expression
                        ",
                RegexOptions.IgnorePatternWhitespace);

            Match match = regex.Match(buffer.String);
            if (match.Success)
            {
                description = String.Format("Balancing Group <{0}>-<{1}>", match.Groups["Name1"], match.Groups["Name2"]);
                buffer.Offset += match.Groups["Rest"].Index;
                expression = new RegexExpression(buffer);
                CheckClosingParen(buffer);
                return true;
            }
            return false;
        }
Ejemplo n.º 11
0
        bool CheckConditional(RegexBuffer buffer)
        {
            // Look for conditional (?(name)yesmatch|nomatch)
            // (name can also be an expression)

            Regex regex = new Regex(@"
                        ^                         # anchor to start of string
                        \?\(
                        (?<Rest>.+)             # The rest of the expression
                        ",
                RegexOptions.IgnorePatternWhitespace);
            Match match = regex.Match(buffer.String);
            if (match.Success)
            {
                description = String.Format("Conditional Subexpression");

                buffer.Offset += match.Groups["Rest"].Index;
                expression = new RegexConditional(buffer);

                return true;
            }
            return false;
        }
Ejemplo n.º 12
0
        bool CheckLookahead(RegexBuffer buffer)
        {
            Regex regex = new Regex(@"
                        ^                         # anchor to start of string
                        \?
                        (?<Assertion><=|<!|=|!)   # assertion char
                        (?<Rest>.+)               # The rest of the expression
                        ",
                RegexOptions.IgnorePatternWhitespace);

            Match match = regex.Match(buffer.String);
            if (match.Success)
            {
                switch (match.Groups["Assertion"].Value)
                {
                    case "=":
                        description = "zero-width positive lookahead";
                        break;

                    case "!":
                        description = "zero-width negative lookahead";
                        break;

                    case "<=":
                        description = "zero-width positive lookbehind";
                        break;

                    case "<!":
                        description = "zero-width negative lookbehind";
                        break;
                }
                buffer.Offset += match.Groups["Rest"].Index;
                expression = new RegexExpression(buffer);
                CheckClosingParen(buffer);
                return true;
            }
            return false;
        }
Ejemplo n.º 13
0
        bool CheckNamed(RegexBuffer buffer)
        {
            Regex regex;
            Match match;

            // look for ?<Name> or ?'Name' syntax...
            regex = new Regex(@"
                        ^                         # anchor to start of string
                        \?(\<|')                  # ?< or ?'
                        (?<Name>[a-zA-Z0-9]+?)    # Capture name
                        (\>|')                    # ?> or ?'
                        (?<Rest>.+)               # The rest of the string
                        ",
                RegexOptions.IgnorePatternWhitespace);

            match = regex.Match(buffer.String);
            if (match.Success)
            {
                description = String.Format("Capture to <{0}>", match.Groups["Name"]);

                    // advance buffer to the rest of the expression
                buffer.Offset += match.Groups["Rest"].Index;
                expression = new RegexExpression(buffer);

                CheckClosingParen(buffer);
                return true;
            }
            return false;
        }
Ejemplo n.º 14
0
 public RegexRef(RegexItem regexItem, int start, int end)
 {
     stringValue = regexItem.ToString(0);
     this.start  = start;
     this.end    = end;
 }
Ejemplo n.º 15
0
        bool CheckNonCapturing(RegexBuffer buffer)
        {
            // Look for non-capturing ?:

            Regex regex = new Regex(@"
                        ^                         # anchor to start of string
                        \?:
                        (?<Rest>.+)             # The rest of the expression
                        ",
                RegexOptions.IgnorePatternWhitespace);
            Match match = regex.Match(buffer.String);
            if (match.Success)
            {
                description = String.Format("Non-capturing Group");

                buffer.Offset += match.Groups["Rest"].Index;
                expression = new RegexExpression(buffer);

                this.CheckClosingParen(buffer);
                return true;
            }
            return false;
        }
Ejemplo n.º 16
0
 public void AddLookup(RegexItem item, int startLocation, int endLocation, bool canCoalesce)
 {
     if (inSeries)
     {
             // in a series, add character to the previous one...
         if (canCoalesce)
         {
             RegexRef lastItem = (RegexRef) expressionLookup[expressionLookup.Count - 1];
             lastItem.StringValue += item.ToString(0);
             lastItem.Length += endLocation - startLocation + 1;
         }
         else
         {
             expressionLookup.Add(new RegexRef(item, startLocation, endLocation));
             inSeries = false;
         }
     }
     else
     {
         if (canCoalesce)
         {
             inSeries = true;
         }
         expressionLookup.Add(new RegexRef(item, startLocation, endLocation));
     }
 }
Ejemplo n.º 17
0
        bool HandlePlainOldCapture(RegexBuffer buffer)
        {
            // we're already at the expression. Just create a new
                // expression, and make sure that we're at a ")" when
                // we're done
            if (buffer.ExplicitCapture)
            {
                description = String.Format("Non-capturing Group");
            }

            expression = new RegexExpression(buffer);
            CheckClosingParen(buffer);
            return true;
        }
Ejemplo n.º 18
0
        bool CheckOptions(RegexBuffer buffer)
        {
            // look for ?imnsx-imnsx:
            Regex regex = new Regex(@"
                        ^                         # anchor to start of string
                        \?(?<Options>[imnsx-]+):
                        ",
                RegexOptions.IgnorePatternWhitespace);

            Match match = regex.Match(buffer.String);
            if (match.Success)
            {
                string option = match.Groups["Options"].Value;
                description = String.Format("Set options to {0}",
                    optionNames[option]);
                expression = null;
                buffer.Offset += match.Groups[0].Length;
                return true;
            }
            return false;
        }
Ejemplo n.º 19
0
 public void AddLookup(RegexItem item, int startLocation, int endLocation)
 {
     AddLookup(item, startLocation, endLocation, false);
 }
Ejemplo n.º 20
0
 public void AddLookup(RegexItem item, int startLocation, int endLocation)
 {
     AddLookup(item, startLocation, endLocation, false);
 }