Mercurial > hg > Members > shinya > pyrect
changeset 73:a6a0504dea7b
modify bm-filter's implimentation. table-lookup -> switch. it's more simple and beautiful.
author | Ryoma SHINYA <shinya@firefly.cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Nov 2010 02:19:18 +0900 |
parents | 8b9c3a924744 |
children | 2ad03c243524 e06786b3c2dc |
files | pyrect/regexp/analyzer.py pyrect/regexp/ast.py pyrect/translator/grep_translator.py |
diffstat | 3 files changed, 10 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/pyrect/regexp/analyzer.py Sun Nov 07 14:28:39 2010 +0900 +++ b/pyrect/regexp/analyzer.py Mon Nov 08 02:19:18 2010 +0900 @@ -23,7 +23,7 @@ (inf, 6, ['123', '456']) >>> an.analyze(prs.parse('((12)+|3)|456')) (inf, 1, []) - >>> an.analyze(prs.parse('(plus)?(qmark)?')) + >>> an.analyze(prs.parse('^(plus)?(qmark)?')) (9, 0, []) >>> an.analyze(prs.parse('\*+ \[\[')) (inf, 4, ['* [['])
--- a/pyrect/regexp/ast.py Sun Nov 07 14:28:39 2010 +0900 +++ b/pyrect/regexp/ast.py Mon Nov 08 02:19:18 2010 +0900 @@ -123,9 +123,6 @@ class InputNode(Node): __metaclass__ = Singleton - def __add__(self, other): - return FixedString(self, other) - def __hash__(self): return id(self.__str__()) @@ -165,14 +162,6 @@ def __init__(self, char): Character.__init__(self, char) -class FixedString(InputNode): - def __init__(self, char): - self.string = list() - - def appfront(self, input_): - self.string.insert(0, input_) - return self - """ Anchor, is Special-Input rules to match specify text position. BegLine, EndLine,
--- a/pyrect/translator/grep_translator.py Sun Nov 07 14:28:39 2010 +0900 +++ b/pyrect/translator/grep_translator.py Mon Nov 08 02:19:18 2010 +0900 @@ -108,15 +108,9 @@ self.emit('static UCHAR key[] = "%s";' % key) - skip = [str(l)] * 256 - for i in range(l - 1): - skip[ord(key[i])] = str(l-1-i) - - self.emiti( "static const UCHAR skip[256] = {") - for i in range(8): - i = i * 32 - self.emit(",".join(skip[i:i+32]) + ",") - self.emitd( "};") + skip = dict() + for i in range(l-1): + skip[key[i]] = l-1-i self.emit("UCHARP tmp1, *tmp2;", 2) self.emit("int i; buf += %d;" % (l-1)) @@ -127,7 +121,12 @@ self.emit( "if (tmp1 == key) goto next;") self.emitd( "}") self.emitd( "}") - self.emit( "buf += skip[*buf];") + self.emiti( "switch(*buf) {") + for k, v in skip.iteritems(): + self.emiti( "case %d: /* %s */" % (ord(k), Character.ascii(k))) + self.emit( "buf += %d; break;" % v), self.dedent() + self.emiti("default: buf += %d;" % l), self.dedent() + self.emitd( "}") self.emitd("}") self.emit( "return;") self.emit( "next:")