of a function call. ''' pass class Important(object): '''The '!important' token.''' pass class Delim(str): '''Any other punctuation, such as comma, period, operator.''' pass # Scanner macros # ---------------------------------------------------------------------------- nonascii = re('[^\0-\177]') _h = NoCase(re('[0-9a-f]')) _unicode_num = _h + Opt(_h + Opt(_h + Opt(_h + Opt(_h + Opt(_h))))) unicode = \ (Str('\\') + _unicode_num + Opt(Str('\r\n') | Any(' \n\r\t\f'))) escape = unicode | (Str('\\') + NoCase(re('[^\n\r\f0-9a-f]'))) nmstart = NoCase(re('[_a-z]')) | nonascii | escape nmchar = NoCase(re('[_a-z0-9-]')) | nonascii | escape name = Rep1(nmchar) ident = Opt(Str('-')) + nmstart + Rep(nmchar) num = re('[0-9]+') | re('[0-9]*\\.[0-9]+') nl = Str('\n') | Str('\r\n') | Str('\r') | Str('\f') string1 = (Str('"') + Rep(AnyBut('\n\r\f\\"') | (Str('\\') + nl) | escape) + Str('"')) string2 = (Str("'") +
import Test from Plex.Traditional import re from Plex.Errors import PlexError from Plex import Seq, AnyBut def test_err(s): try: print re(s) except PlexError, e: print e print re("") print re("a") print re("[a]") print re("[ab]") print re("[abc]") print re("[a-c]") print re("[a-cd]") print re("[a-cg-i]") print re("[^a]") print re("[^a-cg-i]") print re("[-]") print re("[-abc]") print re("[abc-]") print re("[]]") print re("[]-]") print re("[^-]")
def test_err(s): try: print re(s) except PlexError, e: print e
FILECHAR = "[A-Za-z_\.]" VARMID = "[:A-Za-z0-9_]" IDTAIL = "[A-Za-z0-9_]" VARTAIL = "%s*%s" % (VARMID, IDTAIL) VAREX = "[$%%]%s(%s)*" % (LETTER, VARTAIL) ID = "%s%s*" % (LETTER, IDTAIL) ILID = "[$%%]%s+%s%s*" % (DIGIT, LETTER, VARTAIL) FILENAME = "%s+" % (FILECHAR) SPACE = "[ \t\v\f]" HEXDIGIT = "[a-fA-F0-9]" DQ = '"' SQ = "'" lex = Lexicon( [ (re("%s+" % (SPACE)), IGNORE), (re("(///[^/][^\n\r]*[\n\r]*)+"), scan_doc_block), (re("//[^\n\r]*"), IGNORE), (re("[\r\n]"), IGNORE), # The scanner instance takes care of linenumbers for us # (re("\"(\\.|[^\"\n\r])*\""), scan_string_atom), (Str('"') + Rep((Str("\\") + AnyChar) | AnyBut('"\n\r')) + Str('"'), scan_string_atom), # (re("'(\\.|[^'\n\r])*'"), scan_tag_atom), (Str("'") + Rep((Str("\\") + AnyChar) | AnyBut('"\n\r')) + Str("'"), scan_string_atom), (Str("=="), (opEQ, opEQ)), (Str("!="), (opNE, opNE)), (Str(">="), (opGE, opGE)), (Str("<="), (opLE, opLE)), (Str("&&"), (opAND, opAND)), (Str("||"), (opOR, opOR)), (Str("::"), (opCOLONCOLON, opCOLONCOLON)), (Str("--"), (opMINUSMINUS, opMINUSMINUS)),
LETTER = "[A-Za-z_]" FILECHAR = "[A-Za-z_\.]" VARMID = "[:A-Za-z0-9_]" IDTAIL = "[A-Za-z0-9_]" VARTAIL = "%s*%s" % (VARMID, IDTAIL) VAREX = "[$%%]%s(%s)*" % (LETTER, VARTAIL) ID = "%s%s*" % (LETTER, IDTAIL) ILID = "[$%%]%s+%s%s*" % (DIGIT, LETTER, VARTAIL) FILENAME = "%s+" % (FILECHAR) SPACE = "[ \t\v\f]" HEXDIGIT = "[a-fA-F0-9]" DQ = '"' SQ = "'" lex = Lexicon([ (re("%s+" % (SPACE)), IGNORE), (re("(///[^/][^\n\r]*[\n\r]*)+"), scan_doc_block), (re("//[^\n\r]*"), IGNORE), (re("[\r\n]"), IGNORE), # The scanner instance takes care of linenumbers for us #(re("\"(\\.|[^\"\n\r])*\""), scan_string_atom), (Str("\"") + Rep((Str("\\") + AnyChar) | AnyBut("\"\n\r")) + Str("\""), scan_string_atom), #(re("'(\\.|[^'\n\r])*'"), scan_tag_atom), (Str("\'") + Rep((Str("\\") + AnyChar) | AnyBut("\"\n\r")) + Str("\'"), scan_string_atom), (Str("=="), (opEQ, opEQ)), (Str("!="), (opNE, opNE)), (Str(">="), (opGE, opGE)), (Str("<="), (opLE, opLE)), (Str("&&"), (opAND, opAND)),
class Important(object): '''The '!important' token.''' pass class Delim(str): '''Any other punctuation, such as comma, period, operator.''' pass # Scanner macros # ---------------------------------------------------------------------------- nonascii = re('[^\0-\177]') _h = NoCase(re('[0-9a-f]')) _unicode_num = _h + Opt(_h + Opt(_h + Opt(_h + Opt(_h + Opt(_h))))) unicode = \ (Str('\\') + _unicode_num + Opt(Str('\r\n') | Any(' \n\r\t\f'))) escape = unicode | (Str('\\') + NoCase(re('[^\n\r\f0-9a-f]'))) nmstart = NoCase(re('[_a-z]')) | nonascii | escape nmchar = NoCase(re('[_a-z0-9-]')) | nonascii | escape name = Rep1(nmchar) ident = Opt(Str('-')) + nmstart + Rep(nmchar) num = re('[0-9]+') | re('[0-9]*\\.[0-9]+') nl = Str('\n') | Str('\r\n') | Str('\r') | Str('\f') string1 = (Str('"') + Rep(AnyBut('\n\r\f\\"') | (Str('\\') + nl) | escape) + Str('"')) string2 = (Str("'") + Rep(AnyBut("\n\r\f\\'") | (Str('\\') + nl) | escape) + Str("'"))
# Test traditional regular expression syntax. import Test from Plex.Traditional import re from Plex.Errors import PlexError from Plex import Seq, AnyBut def test_err(s): try: print re(s) except PlexError, e: print e print re("") print re("a") print re("[a]") print re("[ab]") print re("[abc]") print re("[a-c]") print re("[a-cd]") print re("[a-cg-i]") print re("[^a]") print re("[^a-cg-i]") print re("[-]") print re("[-abc]") print re("[abc-]") print re("[]]") print re("[]-]") print re("[^-]") print re("[^-abc]")