internal static bool HasLazyQuantifiers(RegExp regExp) { var repetitionRegExp = regExp as RepetitionRegExp; if (repetitionRegExp != null && repetitionRegExp.Greediness == Greediness.LazyQuantification) { return true; } else { bool hasLazyChilds = false; if (regExp.ChildExpressions != null) { foreach (var childExpression in regExp.ChildExpressions) { hasLazyChilds |= HasLazyQuantifiers(childExpression); if (hasLazyChilds) { return true; } } } } return false; }
internal static RegExp FactorizeRegExp(RegExp regExp) { if (!HasLazyQuantifiers(regExp)) { return regExp; // Do nothing, because no lazy quantifiers are used. } return null; }
//TODO: Func<Token, bool> => Predicate<Token> public void IgnoreTerminal(RegExp ignoree, Func<Token, bool> lexicalAction = null) { FiniteAutomata tokenNfa = GetTokenNfa(ignoree); if (lexicalAction != null) { mLexicalActions[tokenNfa.Terminator.TokenClass] = lexicalAction; } mIgnoredTokens.Add(tokenNfa.Terminator.TokenClass); AddTokenToNfa(tokenNfa); }
public extern string ReplaceRegex(RegExp regex, StringReplaceCallback callback);
public extern string ReplaceRegex(RegExp regex, string replaceText);
internal DumbRegexpQuery(Term term, int flags) : base(term.Field) { RegExp re = new RegExp(term.Text(), flags); Automaton = re.ToAutomaton(); }
public Terminal UseTerminal(RegExp regExp, Func<Token, bool> lexicalAction = null) { tokensNumber++; return mTokenizer.UseTerminal(regExp, lexicalAction); }
//TODO: Func<Token, bool> => Predicate<Token> public Terminal UseTerminal(RegExp regExp, Func<Token, bool> lexicalAction = null) { FiniteAutomata tokenNfa = GetTokenNfa(regExp); if (lexicalAction != null) { mLexicalActions[tokenNfa.Terminator.TokenClass] = lexicalAction; } AddTokenToNfa(tokenNfa); var terminal = new Terminal(regExp.ToString(), mClassIdProvider.GetCurrent()); return terminal; }
public string[] Split(RegExp regex) { return(null); }
public int Search(RegExp regex) { return(0); }
public string ReplaceRegex(RegExp regex, StringReplaceCallback callback) { return(null); }
public string ReplaceRegex(RegExp regex, string replaceText) { return(null); }
public string[] Match(RegExp regex) { return(null); }
public NegationRegExp(RegExp regExp, bool createLoopTransitionsOnAcceptingStates = true) { mPositiveRegExp = regExp; this.createLoopTransitionsOnAcceptingStates = createLoopTransitionsOnAcceptingStates; }
public static IEnumerable<object> GetMatching(Context ctx, Coords from, Coords target, int direction, RegExp.Pattern pattern) { IEnumerable<Coords> c; if (pattern.CaptureAll(ctx.GameState, target, from, RegExp.Pattern.Direction.Any, out c)) { return c; } else { return new List<object>(); } }
public string[] Split(RegExp regex, int limit) { return(null); }
public static bool Match(Context ctx, Coords from, Coords target, RegExp.Pattern.Direction direction, RegExp.Pattern pattern) { return pattern.Match(ctx.GameState, target, from, direction); }
public extern int Search(RegExp regex);
private FiniteAutomata GetTokenNfa(RegExp regExp) { FiniteAutomata tokenNfa = regExp.AsNFA(); tokenNfa.Terminator.IsAccepting = true; tokenNfa.Terminator.TokenClass = mClassIdProvider.GetNext(); return tokenNfa; }
public extern string[] Split(RegExp regex);
public void IgnoreTerminal(RegExp regExp) { tokensNumber++; mTokenizer.IgnoreTerminal(regExp); }
public extern string[] Split(RegExp regex, int limit);
internal DumbRegexpQuery(TestRegexpRandom2 outerInstance, Term term, int flags) : base(term.Field()) { this.OuterInstance = outerInstance; RegExp re = new RegExp(term.Text(), flags); Automaton = re.ToAutomaton(); }
public extern string[] Match(RegExp regex);
internal RepeatUntilRegExp(RegExp repeatedRegExp, RegExp suffixRegExp) { mRepeatedRegExp = repeatedRegExp; mSuffixRegExp = suffixRegExp; }
// The idea: // a((a|b)+?|c)d = a((a|b)+?d | cd) // if there is no regexp after lazy quantifier, change it to greedy quantifier. // a(d(a|b)+?|c) --> a(d(a|b)+|c) // otherwise, move the following regexp into the regexp and add it to sequence: // a(d(a|b)+?|c)d(f|g) --> a(d(a|b)+?d(f|g)|cd(f|g)) // ((a(d(a|b)+?|c)d(f|g))|(whatever))something --> // Algorithm: // 1) Find closest parent of type SequenceRegExp // 2) if position of current regexp is last, change lazy to greedy and exit // 3) otherwise public static RegExp Factorize(RegExp regExp) { throw new NotImplementedException(); }