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
Imported modules
|
|
import Expression
import msre_parse
import string
|
Functions
|
|
|
|
convert_any
|
convert_any (
group_names,
name,
ignore,
)
Convert an any tuple into a Dot object
|
|
convert_assert
|
convert_assert (
group_names,
name,
(,
)
Convert an assert tuple into a Assert object, as a positive assertion
|
|
convert_assert_not
|
convert_assert_not (
group_names,
name,
(,
)
Convert an assert_not tuple into a Assert object, as a negative assertion
|
|
convert_at
|
convert_at (
group_names,
name,
where,
)
Convert an 'at_beginning" tuple into an AtBeginning object
Convert an 'at_end" tuple into an AtEnd object
Exceptions
|
|
AssertionError("Unknown at name: %s" % repr( where ) )
|
|
|
convert_branch
|
convert_branch (
group_names,
name,
(,
)
Convert a branch tuple into an Alt object
|
|
convert_groupref
|
convert_groupref (
group_names,
name,
id,
)
Convert a groupref tuple into a GroupRef object
|
|
convert_in
|
convert_in (
group_names,
name,
terms,
)
Convert an in tuple into an Any object
Pass in the negate flag if given.
Exceptions
|
|
AssertionError("unknown option for 'in': %s" % c [ 0 ] )
|
|
|
convert_list
|
convert_list ( group_names, terms )
Convert a list of msre_parse tuples into a Seq
Exceptions
|
|
AssertionError, "Do not understand sre expression %s" % repr( name )
|
|
|
convert_literal
|
convert_literal (
group_names,
name,
val,
)
Convert a literal tuple into a Literal object
|
|
convert_max_repeat
|
convert_max_repeat (
group_names,
name,
(,
)
Convert a max_repeat tuple into a MaxRepeat object
|
|
convert_newline
|
convert_newline (
group_names,
name,
ignore,
)
Convert a newline tuple into an AnyEol object
|
|
convert_not_literal
|
convert_not_literal (
group_names,
name,
val,
)
Convert a not_literal tuple into a Literal object
|
|
convert_subpattern
|
convert_subpattern (
group_names,
name,
(,
)
Convert a subpattern tuple into a Group object
Exceptions
|
|
AssertionError("The attribute name %s was found more than once (%d times) in the tag %s" %(repr( k ), len( v ), repr( pattern_name ) ) )
|
|
|
invert
|
invert ( s )
s -> a string containing all the characters not present in s
I know, it's only good for ASCII...
|
|
make_expression
|
make_expression ( pattern )
pattern -> the Expression tree for the given pattern string
Primary entry point
|
Classes
|
|
|
|