Package Martel :: Module convert_re
[hide private]
[frames] | no frames]

Module convert_re

source code

Converts a regular expression pattern string into an Expression tree.

This is not meant to be an externally usable module.

This works by using msre_parse.py to parse the pattern. The result is a tree data structure, where the nodes in the tree are tuples. The first element of the tuple is the name of the node type. The format of the other elements depends on the type.

The conversion routine is pretty simple - convert each msre_parse tuple node into a Martel Expression node. It's a recusive implementation.

'msre_parse.py' is a modified version of Secret Labs' 'sre_parse.py'

Classes [hide private]
  GroupNames
Functions [hide private]
 
convert_literal(group_names, name, val) source code
 
convert_not_literal(group_names, name, val) source code
 
convert_at(group_names, name, where) source code
 
convert_any(group_names, name, ignore) source code
 
convert_assert(group_names, name, (direction, terms)) source code
 
convert_assert_not(group_names, name, (direction, terms)) source code
 
convert_branch(group_names, name, (ignore, branches)) source code
 
invert(s)
s -> a string containing all the characters not present in s
source code
 
convert_in(group_names, name, terms) source code
 
convert_subpattern(group_names, name, (id, terms)) source code
 
convert_newline(group_names, name, ignore) source code
 
convert_max_repeat(group_names, name, (min_count, max_count, terms)) source code
 
convert_groupref(group_names, name, id) source code
 
convert_list(group_names, terms) source code
 
make_expression(pattern)
pattern -> the Expression tree for the given pattern string
source code
Variables [hide private]
  categories = {'category_digit': '0123456789', 'category_newlin...
  converter_table = {"any": convert_any, "assert": convert_asser...
Variables Details [hide private]

categories

Value:
{'category_digit': '0123456789',
 'category_newline': '''
\r''',
 'category_not_digit': '''\x00\x01\x02\x03\x04\x05\x06\x07\x08\t
\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\
\x1d\x1e\x1f !"#$%&\'()*+,-./:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`a\
bcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\\
x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9\
...

converter_table

Value:
{"any": convert_any, "assert": convert_assert, "assert_not": convert_a\
ssert_not, "at": convert_at, "branch": convert_branch, "groupref": con\
vert_groupref, "in": convert_in, "literal": convert_literal, "max_repe\
at": convert_max_repeat, "newline": convert_newline, "not_literal": co\
nvert_not_literal, "subpattern": convert_subpattern,}