private void AddMisplacedQuantifier(CharacterBuffer charBuffer) { Character character; character = new Character(charBuffer, true) { IsValid = false }; character.Description = string.Concat(character.Literal, " Misplaced quantifier"); this.Add(character); }
public void Parse(int offset, bool skipFirstCaptureNumber) { Character character; CharacterBuffer charBuffer = new CharacterBuffer(Literal) { Offset = offset, IgnoreWhiteSpace = IgnoreWhitespace, IsEcma = IsEcma }; //Label2: while (!charBuffer.IsAtEnd) { int indexInOriginalBuffer = charBuffer.IndexInOriginalBuffer; HandleWhiteSpace(charBuffer, indexInOriginalBuffer); if (charBuffer.IsAtEnd) break; // Exit the loop char current = charBuffer.CurrentCharacter; if (current > Characters.Dot) { if (current == Characters.QuestionMark) { //goto Label0; AddMisplacedQuantifier(charBuffer); continue; // was goto Label2; } switch (current) { case Characters.SquareBracketOpen: { this.Add(new CharacterClass(charBuffer)); continue; // Move to next iteration } case Characters.BackSlash: { if (!SpecialCharacter.NextIsWhitespace(charBuffer)) { BackReference backReference = new BackReference(); if (!backReference.Parse(charBuffer)) { NamedClass namedClass = new NamedClass(); if (!namedClass.Parse(charBuffer)) { this.Add(new SpecialCharacter(charBuffer)); continue; // Move to next iteration } else { this.Add(namedClass); continue; // Move to next iteration } } else { BackReference.NeedsSecondPass = true; if (!backReference.IsOctal) { this.Add(backReference); continue; // Move to next iteration } else { this.Add(new SpecialCharacter(backReference)); continue; // Move to next iteration } } } else { this.Add(new SpecialCharacter(charBuffer)); continue; // Move to next iteration } } case Characters.SquareBracketClosed: { break; } case Characters.CircumflexAccent: { //goto Label1; AddSpecialCharacter(charBuffer); continue; // was goto Label2; } default: { switch (current) { case Characters.CurlyBraceOpen: { character = new Character(charBuffer, true) { //Description = string.Concat(character.Literal, " Misplaced quantifier"), IsValid = false }; character.Description = string.Concat(character.Literal, " Misplaced quantifier"); if (character.RepeatType != Repeat.Once) { this.Add(character); continue; } else { this.Add(new Character(charBuffer)); continue; } } case Characters.Pipe: { SubExpression subExpression = new SubExpression(this.Clone()) { Literal = charBuffer.Substring(0, charBuffer.CurrentIndex), Start = charBuffer.Offset, End = charBuffer.IndexInOriginalBuffer }; this.alternatives.Add(subExpression); charBuffer.MoveNext(); int num = charBuffer.IndexInOriginalBuffer; charBuffer = new CharacterBuffer(charBuffer.GetToEnd()) { Offset = num, IgnoreWhiteSpace = IgnoreWhitespace, IsEcma = IsEcma }; this.Clear(); continue; } } break; } } } else { switch (current) { case '\t': case '\n': case '\r': { //goto Label1; AddSpecialCharacter(charBuffer); continue; // was goto Label2; } case '\v': case '\f': { break; } default: { switch (current) { case ' ': case '$': case '.': { //goto Label1; AddSpecialCharacter(charBuffer); continue; // was goto Label2; } case '#': { if (!this.IgnoreWhitespace) { this.Add(new Character(charBuffer)); continue; } else { this.Add(new Comment(charBuffer)); continue; } } case '(': { Conditional conditional = new Conditional(); if (!conditional.Parse(charBuffer)) { Group group = new Group(charBuffer, skipFirstCaptureNumber); if (group.Type == GroupType.OptionsOutside) { if (group.SetX == CheckState.Checked) { this.IgnoreWhitespace = true; } else if (group.SetX == CheckState.Unchecked) { this.IgnoreWhitespace = false; } charBuffer.IgnoreWhiteSpace = this.IgnoreWhitespace; } this.Add(group); continue; } else { this.Add(conditional); BackReference.NeedsSecondPass = true; continue; } } case Characters.BracketClosed: { character = new Character(charBuffer) { IsValid = false, Description = "Unbalanced parenthesis" }; this.Add(character); continue; // Move to next character } case Characters.Star: case Characters.Plus: { //goto Label0; AddMisplacedQuantifier(charBuffer); continue; // was goto Label2; } } break; } } } Add(new Character(charBuffer)); } HandleAlternatives(charBuffer); //Label0: // AddMisplacedQuantifier(charBuffer); // goto Label2; //Label1: // AddSpecialCharacter(charBuffer); // goto Label2; }