#NEWLINE# @ classmethod #NEWLINE# def fromstring( cls , s , * args , **kwargs ) : #NEWLINE# #INDENT# ' Returns a new Pattern from the given string.\n            Constraints are separated by a space.\n            If a constraint contains a space, it must be wrapped in [].\n        ' #NEWLINE# s = s . replace ( '\\(' , '&lparen;' ) #NEWLINE# s = s . replace ( '\\)' , '&rparen;' ) #NEWLINE# s = s . replace ( '\\[' , '&lbrack;' ) #NEWLINE# s = s . replace ( '\\]' , '&rbrack;' ) #NEWLINE# s = s . replace ( '\\{' , '&lcurly;' ) #NEWLINE# s = s . replace ( '\\}' , '&rcurly;' ) #NEWLINE# p = [ ] #NEWLINE# i = 0 #NEWLINE# for m in re . finditer ( '\\[.*?\\]|\\(.*?\\)' , s ) : #NEWLINE# #INDENT# p . append ( s [ i : m . start ( ) ] ) #NEWLINE# p . append ( s [ m . start ( ) : m . end ( ) ] . replace ( ' ' , '&space;' ) ) #NEWLINE# i = m . end ( ) #NEWLINE# #UNINDENT# p . append ( s [ i : ] ) #NEWLINE# s = '' . join ( p ) #NEWLINE# s = s . replace ( '][' , '] [' ) #NEWLINE# s = s . replace ( ')(' , ') (' ) #NEWLINE# s = s . replace ( '\\|' , '&vdash;' ) #NEWLINE# s = re . sub ( '\\s+\\|\\s+' , '|' , s ) #NEWLINE# s = re . sub ( '\\s+' , ' ' , s ) #NEWLINE# s = re . sub ( '\\{\\s+' , '{' , s ) #NEWLINE# s = re . sub ( '\\s+\\}' , '}' , s ) #NEWLINE# s = s . split ( ' ' ) #NEWLINE# s = [ v . replace ( '&space;' , ' ' ) for v in s ] #NEWLINE# P = cls ( [ ] , * args , ** kwargs ) #NEWLINE# ( G , O , i ) = ( [ ] , [ ] , 0 ) #NEWLINE# for s in s : #NEWLINE# #INDENT# constraint = Constraint . fromstring ( s . strip ( '{}' ) , taxonomy = kwargs . get ( 'taxonomy' , TAXONOMY ) ) #NEWLINE# constraint . index = len ( P . sequence ) #NEWLINE# P . sequence . append ( constraint ) #NEWLINE# while s . startswith ( '{' ) : #NEWLINE# #INDENT# s = s [ 1 : ] #NEWLINE# G . append ( ( i , [ ] ) ) #NEWLINE# i += 1 #NEWLINE# O . append ( [ ] ) #NEWLINE# #UNINDENT# for g in G : #NEWLINE# #INDENT# g [ 1 ] . append ( constraint ) #NEWLINE# #UNINDENT# while s . endswith ( '}' ) : #NEWLINE# #INDENT# s = s [ : ( - 1 ) ] #NEWLINE# if G : #NEWLINE# #INDENT# O [ G [ ( - 1 ) ] [ 0 ] ] = G [ ( - 1 ) ] [ 1 ] #NEWLINE# G . pop ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# P . groups = [ g for g in O if g ] #NEWLINE# return P