public DFA GenDFA(LinkedList <ASTAlias> aliases) { string replaced = regex_literal; foreach (var alias in aliases) { replaced = alias.matcher.Replace(replaced, "(" + alias.regex_literal + ")"); } RegEx.RegEx regex = new RegEx.RegEx(replaced); return(regex.dfa); }
public void reg_replace() { string src = @"\r\n?|\n"; string patch = "\n"; Dictionary <string, string> tests = new Dictionary <string, string> { { "aaa", "aaa" }, { "babca", "babca" }, { "a\r\nb", "a\nb" } }; RegEx.RegEx regex = new RegEx.RegEx(src); foreach (var test in tests) { Assert.AreEqual(regex.Replace(test.Key, patch), test.Value); } }
public void reg_regex_match() { string src = @"$(\\[^\n\r\t]|[^\n\r\t$\\])*$"; Dictionary <string, bool> tests = new Dictionary <string, bool> { { "$\\\\$", true }, { "$\\\n$", false }, { "$\n$", false }, { "$\\\r\n$", false } }; RegEx.RegEx regex = new RegEx.RegEx(src); foreach (var test in tests) { Assert.AreEqual(regex.Match(test.Key), test.Value); } }
/// <summary> /// Initialize the Lexer code. /// </summary> private Lexer() { _text = new StringBuilder(); List <string> regSrcs = new List <string> { @"\$(\\[^\n\r\t]|[^\n\r\t\$\\])*\$", @"[^\$ \n\r\t%][^\r\n]*", @"[ \n\r\t]+", @"%%", }; _dfas = new List <DFA>(regSrcs.Count()); foreach (string src in regSrcs) { RegEx.RegEx regex = new RegEx.RegEx(src); _dfas.Add(regex.dfa); } }
public void reg_plus_match() { string src = "a+b"; Dictionary <string, bool> tests = new Dictionary <string, bool> { { "b", false }, { "a", false }, { "ab", true }, { "ac", false }, { "aaabc", false }, { "aaaab", true } }; RegEx.RegEx regex = new RegEx.RegEx(src); foreach (var test in tests) { Assert.AreEqual(regex.Match(test.Key), test.Value); } }
public void reg_str_match() { string src = @"L?""(\\(.|\r\n)|[^\n""\\])*"""; Dictionary <string, bool> tests = new Dictionary <string, bool> { { "\"abc\"", true }, { "\"abc", false }, { "abc\"", false }, { "\"\n\"", false }, { "\"\\\n\"", true }, { "\"\\\r\n\"", true }, { "\"ab\r\n\"", false } }; RegEx.RegEx regex = new RegEx.RegEx(src); foreach (var test in tests) { Assert.AreEqual(regex.Match(test.Key), test.Value); } }
public void reg_charset_match() { string src = "[a-zA-Z_][a-zA-Z0-9_]*"; Dictionary <string, bool> tests = new Dictionary <string, bool> { { "reg_charset_match", true }, { "src", true }, { "_Assert", true }, { "/**/", false }, { "\\n\\t\\r", false }, { "0_wrong", false }, { "__init__", true }, { "a", true } }; RegEx.RegEx regex = new RegEx.RegEx(src); foreach (var test in tests) { Assert.AreEqual(regex.Match(test.Key), test.Value); } }
public void reg_wild_match() { string src = "(\\\\.|[^$\\\\])*"; Dictionary <string, bool> tests = new Dictionary <string, bool> { { "\\a", true }, { "abc", true }, { "\\\n", true }, { "\\1", true }, { "\\,", true }, { "\\&", true }, { "\\(", true }, { "\\ad", true }, { "\\acc", true } }; RegEx.RegEx regex = new RegEx.RegEx(src); foreach (var test in tests) { Assert.AreEqual(regex.Match(test.Key), test.Value); } }