def cback(self, regex0, lp, question, equal, regex1, rp): data0 = (ind.val() for ind in regex0) data1 = (ind.val() for ind in regex1) pattern0 = Pattern(*data0) pattern1 = Pattern(*data1) e = ConsumeBack(pattern0, pattern1) return e
def cnext(self, lp, question, lexer, equal, regex0, rp, regex1): data0 = (ind.val() for ind in regex0) data1 = (ind.val() for ind in regex1) pattern0 = Pattern(*data0) pattern1 = Pattern(*data1) e = ConsumeNext(pattern0, pattern1) return e
def ncnext(self, lp, question, lexer, exlam, regex0, rp, regex1): data0 = (ind.val() for ind in regex0) data1 = (ind.val() for ind in regex1) pattern0 = Pattern(*data0) pattern1 = Pattern(*data1) e = ConsumeNext(pattern0, pattern1, neg=True) return e
def done(self, sof, regex, eof): data = [ind.val() for ind in regex] if len(data) > 1: return Pattern(*data) elif isinstance(data[0], RegexStr): return Pattern(data[0]) return data[0]
def ncback(self, regex0, lp, question, exlam, regex1, rp): data0 = (ind.val() for ind in regex0) data1 = (ind.val() for ind in regex1) pattern0 = Pattern(*data0) pattern1 = Pattern(*data1) e = ConsumeBack(pattern0, pattern1, neg=True) return e
def pipe(self, regex0, pipe, regex1): data0 = [ind.val() for ind in regex0] data1 = [ind.val() for ind in regex1] pattern1 = data1[0] pattern0 = data0[0] if len(data1) > 1: pattern1 = Pattern(*data1) if isinstance(data0[0], Any): pattern0.args.append(pattern1) else: pattern0 = Any(Pattern(*data0), pattern1) return pattern0
def reduce_pipe(self, regex0, regex1): pattern1 = Pattern(*data1) pattern2 = Any(pattern0, pattern1) return pattern2
from crocs.regex import Pattern, Group, X e = Pattern('a', Group('b', X())) e.test() e.hits()
from crocs.regex import Pattern, NamedGroup, X e0 = NamedGroup('beta', 'X', X(), 'B') e1 = Pattern('um', e0, 'dois', e0, 'tres', e0) e1.test() e1.hits()
from crocs.regex import Pattern, Group, X, Include, ZeroOrMore, Repeat, Seq e0 = Group('a') e1 = ZeroOrMore(e0) e2 = Pattern(e0, 'b', e0) print(e2.mkregex()) e2.test()
from crocs.regex import Seq, Include, Repeat, Pattern, NamedGroup, Include # First we define how our Patterns look like. name_letters = Include(Seq('a', 'z')) # The regex {n,m} repeatition. The name should contains more # than 0 chars. name = Repeat(name_letters, 1) # Create a named group to make it available after matching. name = NamedGroup('name', name) # The hostname part looks like the name except # it starts with 'python' in the beginning, hostname = Repeat(name_letters, 1) hostname = NamedGroup('hostname', 'python', hostname) # The Pattern class joins the sub patterns it forms a single one. mail = Pattern(name, '@', hostname, '.', 'br') mail.test() mail.hits()
from crocs.regex import Pattern, ConsumeNext, X e = ConsumeNext(Pattern('a', X(), 'b'), 'def') e.test() e.hits()
from crocs.regex import Pattern, Include, Exclude, Seq e = Pattern(Exclude('abc'), Include(Seq('0', '9'))) e.test() e.hits()
from crocs.regex import Pattern, X e = Pattern('a', X(), 'b') e.test() e.hits()
from crocs.regex import Pattern, Include, Seq e = Pattern('x', Include(Seq('0', '9'))) e.test() e.hits()
from crocs.regex import Pattern, ConsumeBack, X e = ConsumeBack(ConsumeBack(Pattern('a', X(), 'b'), 'def'), 'def') e.test() e.hits()
def done(self, sof, regex, eof): data = [ind.val() for ind in regex] if len(data) > 1: return Pattern(*data) return data[0]
from crocs.regex import Pattern, Repeat, Group e = Pattern('a', Repeat('b'), Repeat(Group('cd'))) e.test() e.hits()