/** * Adds a regular expression match to this automaton. New states * and transitions will be added to extend this automaton to * support the specified string. Note that this method only * supports a subset of the full regular expression syntax, so * a more complete regular expression library must also be * provided. * * @param pattern the regular expression string * @param ignoreCase the case-insensitive match flag * @param value the match value * * @throws RegExpException if the regular expression parsing * failed */ public void AddRegExpMatch(string pattern, bool ignoreCase, TokenPattern value) { TokenRegExpParser parser = new TokenRegExpParser(pattern, ignoreCase); string debug = "DFA regexp; " + parser.GetDebugInfo(); bool isAscii; isAscii = parser.start.IsAsciiOutgoing(); for (int i = 0; isAscii && i < 128; i++) { bool match = false; for (int j = 0; j < parser.start.outgoing.Length; j++) { if (parser.start.outgoing[j].Match((char)i)) { if (match) { isAscii = false; break; } match = true; } } if (match && initialChar[i] != null) { isAscii = false; } } if (parser.start.incoming.Length > 0) { initial.AddOut(new NFAEpsilonTransition(parser.start)); debug += ", uses initial epsilon"; } else if (isAscii && !ignoreCase) { for (int i = 0; isAscii && i < 128; i++) { for (int j = 0; j < parser.start.outgoing.Length; j++) { if (parser.start.outgoing[j].Match((char)i)) { initialChar[i] = parser.start.outgoing[j].state; } } } debug += ", uses ASCII lookup"; } else { parser.start.MergeInto(initial); debug += ", uses initial state"; } parser.end.value = value; value.DebugInfo = debug; }
/** * Adds a regular expression match to this automaton. New states * and transitions will be added to extend this automaton to * support the specified string. Note that this method only * supports a subset of the full regular expression syntax, so * a more complete regular expression library must also be * provided. * * @param pattern the regular expression string * @param ignoreCase the case-insensitive match flag * @param value the match value * * @throws RegExpException if the regular expression parsing * failed */ public void AddRegExpMatch(string pattern, bool ignoreCase, TokenPattern value) { TokenRegExpParser parser = new TokenRegExpParser(pattern, ignoreCase); string debug = "DFA regexp; " + parser.GetDebugInfo(); bool isAscii; isAscii = parser.start.IsAsciiOutgoing(); for (int i = 0; isAscii && i < 128; i++) { bool match = false; for (int j = 0; j < parser.start.outgoing.Length; j++) { if (parser.start.outgoing[j].Match((char) i)) { if (match) { isAscii = false; break; } match = true; } } if (match && initialChar[i] != null) { isAscii = false; } } if (parser.start.incoming.Length > 0) { initial.AddOut(new NFAEpsilonTransition(parser.start)); debug += ", uses initial epsilon"; } else if (isAscii && !ignoreCase) { for (int i = 0; isAscii && i < 128; i++) { for (int j = 0; j < parser.start.outgoing.Length; j++) { if (parser.start.outgoing[j].Match((char) i)) { initialChar[i] = parser.start.outgoing[j].state; } } } debug += ", uses ASCII lookup"; } else { parser.start.MergeInto(initial); debug += ", uses initial state"; } parser.end.value = value; value.DebugInfo = debug; }
/// <summary> /// Adds a regular expression match to this automaton. New states /// and transitions will be added to extend this automaton to /// support the specified string. Note that this method only /// supports a subset of the full regular expression syntax, so /// a more complete regular expression library must also be /// provided. /// </summary> /// <param name="pattern">The regular expression string</param> /// <param name="ignoreCase">The case-insensitive match flag</param> /// <param name="value">The match value</param> /// <exception cref="Grammatica.RE.RegExpException">If the regular expression parsing /// failed</exception> public void AddRegExpMatch( string pattern, bool ignoreCase, TokenPattern value) { TokenRegExpParser parser = new TokenRegExpParser(pattern, ignoreCase); string debug = "DFA regexp; " + parser.DebugInfo; bool isAscii; isAscii = parser.Start.IsAsciiOutgoing; for (int i = 0; isAscii && i < 128; i++) { bool match = false; foreach (var outTrans in parser.Start.Outgoing) { if (outTrans.Match((char)i)) { if (match) { isAscii = false; break; } match = true; } } if (match && this.initialChar[i] != null) { isAscii = false; } } if (parser.Start.Incoming.Count > 0) { this.initial.AddOut(new NFAEpsilonTransition(parser.Start)); debug += ", uses initial epsilon"; } else if (isAscii && !ignoreCase) { for (int i = 0; isAscii && i < 128; i++) { foreach (var outTrans in parser.Start.Outgoing) { if (outTrans.Match((char)i)) { this.initialChar[i] = outTrans.State; } } } debug += ", uses ASCII lookup"; } else { parser.Start.MergeInto(this.initial); debug += ", uses initial state"; } parser.End.Value = value; value.DebugInfo = debug; }