private static void AddTriviaClassifications(RegexToken token, ArrayBuilder <ClassifiedSpan> result) { foreach (var trivia in token.LeadingTrivia) { AddTriviaClassifications(trivia, result); } }
private static void AddTriviaClassifications(RegexToken token, EmbeddedLanguageClassificationContext context) { foreach (var trivia in token.LeadingTrivia) { AddTriviaClassifications(trivia, context); } }
private void AddClassification(RegexToken token, string typeName) { if (!token.IsMissing) { Result.Add(new ClassifiedSpan(typeName, token.GetSpan())); } }
private void AddClassification(RegexToken token, string typeName) { if (!token.IsMissing) { Context.AddClassification(typeName, token.GetSpan()); } }
private void RecordCapture(RegexToken token, TextSpan span) { if (!token.IsMissing) { if (token.Kind == RegexKind.NumberToken) { AddIfMissing(_captureNumberToSpan, list: null, (int)token.Value, span); } else { AddIfMissing(_captureNameToSpan, list: _captureNames, (string)token.Value, span); } } }
public TokenizerResult Tokenize(ITracker tracker) { // Fail if the previoustype is not NA and the type of the previous token doesn´t match if (PreviousType != Token.TokenType.NA && ((tracker.Before?.Type ?? Token.TokenType.None) & PreviousType) == Token.TokenType.NA) { tracker.AddError("'" + (tracker.Before?.ToString() ?? "") + "' Can´t appear in front of " + Type, 1); return(TokenizerResult.Failure); } if (PreviousNames != null && PreviousNames.Length != 0 && !PreviousNames.Contains(tracker.Before?.Name)) { tracker.AddError("'" + (tracker.Before?.ToString() ?? "") + "' Can´t appear in front of " + Type, 1); return(TokenizerResult.Failure); } Match Match = Regex.Match(tracker.Remaining); if (!Match.Success) { return(TokenizerResult.Failure); } if (Match.Index != 0) { return(TokenizerResult.Failure); } if (Match.Length == 0) { return(TokenizerResult.Failure); } string consumed = Match.Value; var t = new RegexToken(new TextRegion(tracker.Index, tracker.Index + consumed.Length), consumed, (Match.Groups as IEnumerable <Group>).Select(g => g.Value).ToArray(), Name, Type); tracker.AddToken(t, consumed.Length); return(TokenizerResult.Success); }
public override string ToTokenString(RegexToken token) { switch (token) { case RegexToken.GroupNameOpen: if (NamedCaptureGroupBracketOption == NamedCaptureGroupBracketOption.AngleBracket) { return("<"); } else if (NamedCaptureGroupBracketOption == NamedCaptureGroupBracketOption.Apostrophe) { return("'"); } else { throw new ArgumentOutOfRangeException(nameof(NamedCaptureGroupBracketOption)); } case RegexToken.GroupNameClose: if (NamedCaptureGroupBracketOption == NamedCaptureGroupBracketOption.AngleBracket) { return(">"); } else if (NamedCaptureGroupBracketOption == NamedCaptureGroupBracketOption.Apostrophe) { return("'"); } else { throw new ArgumentOutOfRangeException(nameof(NamedCaptureGroupBracketOption)); } default: return(base.ToTokenString(token)); } }
private static EmbeddedBraceMatchingResult?CreateResult(RegexToken open, RegexToken close) => open.IsMissing || close.IsMissing ? default(EmbeddedBraceMatchingResult?) : new EmbeddedBraceMatchingResult(open.VirtualChars[0].Span, close.VirtualChars[0].Span);
private static BraceMatchingResult?CreateResult(RegexToken open, RegexToken close) => open.IsMissing || close.IsMissing ? (BraceMatchingResult?)null : new BraceMatchingResult(open.VirtualChars[0].Span, close.VirtualChars[0].Span);
public virtual string ToTokenString(RegexToken token) { switch (token) { case RegexToken.Any: return("."); case RegexToken.GroupOpen: return("("); case RegexToken.GroupNonCapturing: return("?:"); case RegexToken.GroupOptionStart: if (!IsInlineGroupOptionsSupported) { throw new InlineGroupOptionsNotSupportedException(RegexLanguage); } return("?"); case RegexToken.GroupNameOpen: if (!IsNamedCapturingGroupSupported) { throw new NamedCapturingGroupNotSupportedException(RegexLanguage); } else { return("<"); } case RegexToken.GroupNameClose: if (!IsNamedCapturingGroupSupported) { throw new NamedCapturingGroupNotSupportedException(RegexLanguage); } else { return(">"); } case RegexToken.GroupOptionEnd: if (!IsInlineGroupOptionsSupported) { throw new InlineGroupOptionsNotSupportedException(RegexLanguage); } return(":"); case RegexToken.GroupClose: return(")"); case RegexToken.ConditionalOpen: if (!IsConditionalSupported) { throw new ConditionalNotSupportedException(RegexLanguage); } return("(?"); case RegexToken.ConditionalClose: if (!IsConditionalSupported) { throw new ConditionalNotSupportedException(RegexLanguage); } return(")"); case RegexToken.AtomicGroupOpen: if (!IsAtomicGroupSupported) { throw new AtomicGroupNotSupportedException(RegexLanguage); } return("(?>"); case RegexToken.AtomicGroupClose: if (!IsAtomicGroupSupported) { throw new AtomicGroupNotSupportedException(RegexLanguage); } return(")"); case RegexToken.PositiveLookaheadAssertionOpen: if (!IsPositiveLookaheadAssertionSupported) { throw new PositiveLookaheadAssertionNotSupportedException(RegexLanguage); } return("(?="); case RegexToken.PositiveLookaheadAssertionClose: if (!IsPositiveLookaheadAssertionSupported) { throw new PositiveLookaheadAssertionNotSupportedException(RegexLanguage); } return(")"); case RegexToken.NegativeLookaheadAssertionOpen: if (!IsNegativeLookaheadAssertionSupported) { throw new NegativeLookaheadAssertionNotSupportedException(RegexLanguage); } return("(?!"); case RegexToken.NegativeLookaheadAssertionClose: if (!IsNegativeLookaheadAssertionSupported) { throw new NegativeLookaheadAssertionNotSupportedException(RegexLanguage); } return(")"); case RegexToken.PositiveLookbehindAssertionOpen: if (!IsPositiveLookbehindAssertionSupported) { throw new PositiveLookbehindAssertionNotSupportedException(RegexLanguage); } return("(?<="); case RegexToken.PositiveLookbehindAssertionClose: if (!IsPositiveLookbehindAssertionSupported) { throw new PositiveLookbehindAssertionNotSupportedException(RegexLanguage); } return(")"); case RegexToken.NegativeLookbehindAssertionOpen: if (!IsNegativeLookbehindAssertionSupported) { throw new NegativeLookbehindAssertionNotSupportedException(RegexLanguage); } return("(?<!"); case RegexToken.NegativeLookbehindAssertionClose: if (!IsNegativeLookbehindAssertionSupported) { throw new NegativeLookbehindAssertionNotSupportedException(RegexLanguage); } return(")"); case RegexToken.CharacterGroupOpen: return("["); case RegexToken.CharacterGroupNegative: return("^"); case RegexToken.CharacterGroupClose: return("]"); case RegexToken.Alternation: return("|"); case RegexToken.ZeroOrOne: return("?"); case RegexToken.ZeroOrMore: return("*"); case RegexToken.OneOrMore: return("+"); case RegexToken.Lazy: return("?"); case RegexToken.Possessive: return("+"); case RegexToken.QuantifierOpen: return("{"); case RegexToken.QuantifierSeparator: return(","); case RegexToken.QuantifierClose: return("}"); case RegexToken.StringStartAnchor: return("^"); case RegexToken.StringEndAnchor: return("$"); case RegexToken.UnicodeCategoryOpen: if (!IsUnicodeCategorySupported) { throw new UnicodeCategoryNotSupportedException(RegexLanguage); } return(@"\p{"); case RegexToken.UnicodeCategoryClose: if (!IsUnicodeCategorySupported) { throw new UnicodeCategoryNotSupportedException(RegexLanguage); } return("}"); case RegexToken.NegativeUnicodeCategoryOpen: if (!IsUnicodeCategorySupported) { throw new UnicodeCategoryNotSupportedException(RegexLanguage); } return(@"\P{"); case RegexToken.NegativeUnicodeCategoryClose: if (!IsUnicodeCategorySupported) { throw new UnicodeCategoryNotSupportedException(RegexLanguage); } return("}"); default: throw new ArgumentOutOfRangeException(nameof(token), "If you think the token enum is not enough, please create a new issue or submit a pull request (PR)."); } }