<s> import itertools <EOL> class MarkupGenerator ( object ) : <EOL> def __init__ ( self , construct ) : <EOL> self . construct = construct <EOL> self . children = [ ] <EOL> def addGenerator ( self , generator ) : <EOL> self . children . append ( generator ) <EOL> def addType ( self , type ) : <EOL> if ( type ) : <EOL> self . addText ( type . _leadingSpace ) <EOL> self . children . append ( MarkupType ( self . construct , type ) ) <EOL> self . addText ( type . _semicolon ) <EOL> self . addText ( type . _trailingSpace ) <EOL> def addTypeName ( self , typeName ) : <EOL> if ( typeName ) : <EOL> self . children . append ( MarkupTypeName ( typeName ) ) <EOL> def addName ( self , name ) : <EOL> if ( name ) : <EOL> self . children . append ( MarkupName ( name ) ) <EOL> def addKeyword ( self , keyword ) : <EOL> if ( keyword ) : <EOL> self . children . append ( MarkupKeyword ( keyword ) ) <EOL> def addEnumValue ( self , enumValue ) : <EOL> if ( enumValue ) : <EOL> self . children . append ( MarkupEnumValue ( enumValue ) ) <EOL> def addText ( self , text ) : <EOL> if ( text ) : <EOL> if ( ( <NUM_LIT:0> < len ( self . children ) ) and ( type ( self . children [ - <NUM_LIT:1> ] ) is MarkupText ) ) : <EOL> self . children [ - <NUM_LIT:1> ] . text += unicode ( text ) <EOL> else : <EOL> self . children . append ( MarkupText ( unicode ( text ) ) ) <EOL> @ property <EOL> def text ( self ) : <EOL> return u'<STR_LIT>' . join ( [ child . text for child in self . children ] ) <EOL> def _markup ( self , marker ) : <EOL> if ( self . construct and hasattr ( marker , '<STR_LIT>' ) ) : <EOL> return marker . markupConstruct ( self . text , self . construct ) <EOL> return ( None , None ) <EOL> def markup ( self , marker , parent = None ) : <EOL> head , tail = self . _markup ( marker ) <EOL> output = unicode ( head ) if ( head ) else u'<STR_LIT>' <EOL> output += u'<STR_LIT>' . join ( [ child . markup ( marker , self . construct ) for child in self . children ] ) <EOL> return output + ( unicode ( tail ) if ( tail ) else u'<STR_LIT>' ) <EOL> class MarkupType ( MarkupGenerator ) : <EOL> def __init__ ( self , construct , type ) : <EOL> MarkupGenerator . __init__ ( self , construct ) <EOL> type . _markup ( self ) <EOL> def _markup ( self , marker ) : <EOL> if ( self . construct and hasattr ( marker , '<STR_LIT>' ) ) : <EOL> return marker . markupType ( self . text , self . construct ) <EOL> return ( None , None ) <EOL> class MarkupText ( object ) : <EOL> def __init__ ( self , text ) : <EOL> self . text = text <EOL> def markup ( self , marker , construct ) : <EOL> return unicode ( marker . encode ( self . text ) ) if ( hasattr ( marker , '<STR_LIT>' ) ) else self . text <EOL> class MarkupTypeName ( MarkupText ) : <EOL> def __init__ ( self , type ) : <EOL> MarkupText . __init__ ( self , type ) <EOL> def markup ( self , marker , construct ) : <EOL> head , tail = marker . markupTypeName ( self . text , construct ) if ( hasattr ( marker , '<STR_LIT>' ) ) else ( None , None ) <EOL> output = unicode ( head ) if ( head ) else u'<STR_LIT>' <EOL> output += MarkupText . markup ( self , marker , construct ) <EOL> return output + ( unicode ( tail ) if ( tail ) else u'<STR_LIT>' ) <EOL> class MarkupName ( MarkupText ) : <EOL> def __init__ ( self , name ) : <EOL> MarkupText . __init__ ( self , name ) <EOL> def markup ( self , marker , construct ) : <EOL> head , tail = marker . markupName ( self . text , construct ) if ( hasattr ( marker , '<STR_LIT>' ) ) else ( None , None ) <EOL> output = unicode ( head ) if ( head ) else u'<STR_LIT>' <EOL> output += MarkupText . markup ( self , marker , construct ) <EOL> return output + ( unicode ( tail ) if ( tail ) else u'<STR_LIT>' ) <EOL> class MarkupKeyword ( MarkupText ) : <EOL> def __init__ ( self , keyword ) : <EOL> MarkupText . __init__ ( self , keyword ) <EOL> def markup ( self , marker , construct ) : <EOL> head , tail = marker . markupKeyword ( self . text , construct ) if ( hasattr ( marker , '<STR_LIT>' ) ) else ( None , None ) <EOL> output = unicode ( head ) if ( head ) else u'<STR_LIT>' <EOL> output += MarkupText . markup ( self , marker , construct ) <EOL> return output + ( unicode ( tail ) if ( tail ) else u'<STR_LIT>' ) <EOL> class MarkupEnumValue ( MarkupText ) : <EOL> def __init__ ( self , keyword ) : <EOL> MarkupText . __init__ ( self , keyword ) <EOL> def markup ( self , marker , construct ) : <EOL> head , tail = marker . markupEnumValue ( self . text , construct ) if ( hasattr ( marker , '<STR_LIT>' ) ) else ( None , None ) <EOL> output = unicode ( head ) if ( head ) else u'<STR_LIT>' <EOL> output += MarkupText . markup ( self , marker , construct ) <EOL> return output + ( unicode ( tail ) if ( tail ) else u'<STR_LIT>' ) </s>
