<s> from __future__ import division , unicode_literals <EOL> VERTICAL_SEPARATION = <NUM_LIT:8> <EOL> ARC_RADIUS = <NUM_LIT:10> <EOL> DIAGRAM_CLASS = '<STR_LIT>' <EOL> TRANSLATE_HALF_PIXEL = True <EOL> INTERNAL_ALIGNMENT = '<STR_LIT>' <EOL> DEBUG = True <EOL> CHARACTER_ADVANCE = <NUM_LIT:8> <EOL> def e ( text ) : <EOL> return str ( text ) . replace ( '<STR_LIT:&>' , '<STR_LIT>' ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) . replace ( '<STR_LIT:<>' , '<STR_LIT>' ) <EOL> def determineGaps ( outer , inner ) : <EOL> diff = outer - inner <EOL> if INTERNAL_ALIGNMENT == '<STR_LIT:left>' : <EOL> return <NUM_LIT:0> , diff <EOL> elif INTERNAL_ALIGNMENT == '<STR_LIT:right>' : <EOL> return diff , <NUM_LIT:0> <EOL> else : <EOL> return diff / <NUM_LIT:2> , diff / <NUM_LIT:2> <EOL> class DiagramItem ( object ) : <EOL> def __init__ ( self , name , attrs = None , text = None ) : <EOL> self . name = name <EOL> self . attrs = attrs or { } <EOL> self . children = [ text ] if text else [ ] <EOL> self . needsSpace = False <EOL> self . raw = None <EOL> self . yAdvance = <NUM_LIT:0> <EOL> def format ( self , x , y , width ) : <EOL> raise NotImplementedError <EOL> def addTo ( self , parent ) : <EOL> parent . children . append ( self ) <EOL> return self <EOL> def writeSvg ( self , write , raw = None ) : <EOL> if raw is None and self . raw is not None : <EOL> raw = self . raw <EOL> write ( '<STR_LIT>' . format ( self . name ) ) <EOL> for name , value in sorted ( self . attrs . items ( ) ) : <EOL> write ( '<STR_LIT>' . format ( name , e ( value ) ) ) <EOL> write ( '<STR_LIT>' ) <EOL> for child in self . children : <EOL> if isinstance ( child , DiagramItem ) : <EOL> child . writeSvg ( write , raw ) <EOL> elif raw : <EOL> write ( child ) <EOL> else : <EOL> write ( e ( child ) ) <EOL> write ( '<STR_LIT>' . format ( self . name ) ) <EOL> class Path ( DiagramItem ) : <EOL> def __init__ ( self , x , y ) : <EOL> DiagramItem . __init__ ( self , '<STR_LIT:path>' , { '<STR_LIT:d>' : '<STR_LIT>' % ( x , y ) } ) <EOL> def m ( self , x , y ) : <EOL> self . attrs [ '<STR_LIT:d>' ] += '<STR_LIT>' . format ( x , y ) <EOL> return self <EOL> def h ( self , val ) : <EOL> self . attrs [ '<STR_LIT:d>' ] += '<STR_LIT>' . format ( val ) <EOL> return self <EOL> right = h <EOL> def left ( self , val ) : <EOL> return self . h ( - val ) <EOL> def v ( self , val ) : <EOL> self . attrs [ '<STR_LIT:d>' ] += '<STR_LIT>' . format ( val ) <EOL> return self <EOL> down = v <EOL> def up ( self , val ) : <EOL> return self . v ( - val ) <EOL> def arc ( self , sweep ) : <EOL> x = ARC_RADIUS <EOL> y = ARC_RADIUS <EOL> if sweep [ <NUM_LIT:0> ] == '<STR_LIT:e>' or sweep [ <NUM_LIT:1> ] == '<STR_LIT:w>' : <EOL> x *= - <NUM_LIT:1> <EOL> if sweep [ <NUM_LIT:0> ] == '<STR_LIT:s>' or sweep [ <NUM_LIT:1> ] == '<STR_LIT:n>' : <EOL> y *= - <NUM_LIT:1> <EOL> cw = <NUM_LIT:1> if sweep == '<STR_LIT>' or sweep == '<STR_LIT>' or sweep == '<STR_LIT>' or sweep == '<STR_LIT>' else <NUM_LIT:0> <EOL> self . attrs [ '<STR_LIT:d>' ] += '<STR_LIT>' . format ( ARC_RADIUS , cw , x , y ) <EOL> return self <EOL> def format ( self ) : <EOL> self . attrs [ '<STR_LIT:d>' ] += '<STR_LIT>' <EOL> return self <EOL> def wrapString ( value ) : <EOL> return value if isinstance ( value , DiagramItem ) else Terminal ( value ) <EOL> class Diagram ( DiagramItem ) : <EOL> def __init__ ( self , * items ) : <EOL> DiagramItem . __init__ ( self , '<STR_LIT>' , { '<STR_LIT:class>' : DIAGRAM_CLASS } ) <EOL> self . items = [ Start ( ) ] + [ wrapString ( item ) for item in items ] + [ End ( ) ] <EOL> self . width = <NUM_LIT:1> + sum ( item . width + ( <NUM_LIT:20> if item . needsSpace else <NUM_LIT:0> ) <EOL> for item in self . items ) <EOL> self . up = <NUM_LIT:0> <EOL> self . down = <NUM_LIT:0> <EOL> for item in self . items : <EOL> self . up = max ( self . up , item . up - self . yAdvance ) <EOL> self . down = max ( self . down , item . down + self . yAdvance ) <EOL> self . yAdvance += item . yAdvance <EOL> self . formatted = False <EOL> def format ( self , paddingTop = <NUM_LIT:20> , paddingRight = None , paddingBottom = None , paddingLeft = None ) : <EOL> if paddingRight is None : <EOL> paddingRight = paddingTop <EOL> if paddingBottom is None : <EOL> paddingBottom = paddingTop <EOL> if paddingLeft is None : <EOL> paddingLeft = paddingRight <EOL> x = paddingLeft <EOL> y = paddingTop + self . up <EOL> g = DiagramItem ( '<STR_LIT:g>' ) <EOL> if TRANSLATE_HALF_PIXEL : <EOL> g . attrs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> for item in self . items : <EOL> if item . needsSpace : <EOL> Path ( x , y ) . h ( <NUM_LIT:10> ) . addTo ( g ) <EOL> x += <NUM_LIT:10> <EOL> item . format ( x , y , item . width ) <EOL> x += item . width <EOL> y += item . yAdvance <EOL> if item . needsSpace : <EOL> Path ( x , y ) . h ( <NUM_LIT:10> ) . addTo ( g ) <EOL> x += <NUM_LIT:10> <EOL> item . addTo ( g ) <EOL> self . attrs [ '<STR_LIT:width>' ] = self . width + paddingLeft + paddingRight <EOL> self . attrs [ '<STR_LIT>' ] = self . up + self . down + paddingTop + paddingBottom <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" . format ( ** self . attrs ) <EOL> g . addTo ( self ) <EOL> self . formatted = True <EOL> return self <EOL> def writeSvg ( self , write ) : <EOL> if not self . formatted : <EOL> self . format ( ) <EOL> return DiagramItem . writeSvg ( self , write ) <EOL> class Sequence ( DiagramItem ) : <EOL> def __init__ ( self , * items ) : <EOL> DiagramItem . __init__ ( self , '<STR_LIT:g>' ) <EOL> self . items = [ wrapString ( item ) for item in items ] <EOL> self . width = sum ( item . width + ( <NUM_LIT:20> if item . needsSpace else <NUM_LIT:0> ) <EOL> for item in self . items ) <EOL> self . up = <NUM_LIT:0> <EOL> self . down = <NUM_LIT:0> <EOL> for item in self . items : <EOL> self . up = max ( self . up , item . up - self . yAdvance ) <EOL> self . down = max ( self . down , item . down + self . yAdvance ) <EOL> self . yAdvance += item . yAdvance <EOL> if DEBUG : <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" . format ( self . up , self . down ) <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> def format ( self , x , y , width ) : <EOL> leftGap , rightGap = determineGaps ( width , self . width ) <EOL> Path ( x , y ) . h ( leftGap ) . addTo ( self ) <EOL> Path ( x + leftGap + self . width , y ) . h ( rightGap ) . addTo ( self ) <EOL> x += leftGap <EOL> for item in self . items : <EOL> if item . needsSpace : <EOL> Path ( x , y ) . h ( <NUM_LIT:10> ) . addTo ( self ) <EOL> x += <NUM_LIT:10> <EOL> item . format ( x , y , item . width ) <EOL> x += item . width <EOL> y += item . yAdvance <EOL> if item . needsSpace : <EOL> Path ( x , y ) . h ( <NUM_LIT:10> ) . addTo ( self ) <EOL> x += <NUM_LIT:10> <EOL> item . addTo ( self ) <EOL> return self <EOL> class Stack ( DiagramItem ) : <EOL> def __init__ ( self , * items ) : <EOL> DiagramItem . __init__ ( self , '<STR_LIT:g>' ) <EOL> self . items = [ wrapString ( item ) for item in items ] <EOL> self . width = ( ARC_RADIUS * <NUM_LIT:4> ) + max ( item . width for item in self . items ) <EOL> item = self . items [ <NUM_LIT:0> ] <EOL> self . up = item . up <EOL> self . down = item . down <EOL> prevItem = item <EOL> for item in self . items [ <NUM_LIT:1> : ] : <EOL> self . down += ( ARC_RADIUS * <NUM_LIT:4> ) + item . up + item . down <EOL> self . yAdvance += ( ARC_RADIUS * <NUM_LIT:4> ) + prevItem . down + item . up <EOL> prevItem = item <EOL> self . yAdvance += prevItem . yAdvance <EOL> def format ( self , x , y , width ) : <EOL> item = self . items [ <NUM_LIT:0> ] <EOL> space = <NUM_LIT:0> <EOL> if ( item . width < width ) : <EOL> space = ( width - item . width ) / <NUM_LIT:2> <EOL> Path ( x , y ) . h ( space ) . addTo ( self ) <EOL> item . format ( x + space , y , item . width ) <EOL> item . addTo ( self ) <EOL> prevItem = item <EOL> for item in self . items [ <NUM_LIT:1> : ] : <EOL> Path ( x + space + prevItem . width , y + prevItem . yAdvance ) . arc ( '<STR_LIT>' ) . v ( prevItem . down - prevItem . yAdvance ) . arc ( '<STR_LIT>' ) . left ( ( prevItem . width / <NUM_LIT:2> ) + ( item . width / <NUM_LIT:2> ) ) . arc ( '<STR_LIT>' ) . v ( item . up ) . arc ( '<STR_LIT>' ) . addTo ( self ) <EOL> space = ( width - item . width ) / <NUM_LIT:2> <EOL> y += ( ARC_RADIUS * <NUM_LIT:4> ) + prevItem . down + item . up <EOL> item . format ( x + space , y , item . width ) <EOL> item . addTo ( self ) <EOL> prevItem = item <EOL> if ( <NUM_LIT:0> < space ) : <EOL> Path ( x + prevItem . width + space , y + prevItem . yAdvance ) . h ( space ) . addTo ( self ) <EOL> class Choice ( DiagramItem ) : <EOL> def __init__ ( self , default , * items ) : <EOL> DiagramItem . __init__ ( self , '<STR_LIT:g>' ) <EOL> assert default < len ( items ) <EOL> self . default = default <EOL> self . items = [ wrapString ( item ) for item in items ] <EOL> self . width = ARC_RADIUS * <NUM_LIT:4> + max ( item . width for item in self . items ) <EOL> self . up = <NUM_LIT:0> <EOL> self . down = <NUM_LIT:0> <EOL> self . yAdvance = self . items [ self . default ] . yAdvance <EOL> for i , item in enumerate ( self . items ) : <EOL> if i < default : <EOL> self . up += max ( ARC_RADIUS , item . up + item . down + VERTICAL_SEPARATION ) <EOL> elif i == default : <EOL> self . up += max ( ARC_RADIUS , item . up ) <EOL> self . down += max ( ARC_RADIUS , item . down ) <EOL> else : <EOL> assert i > default <EOL> self . down += max ( ARC_RADIUS , VERTICAL_SEPARATION + item . up + item . down ) <EOL> if DEBUG : <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" . format ( self . up , self . down ) <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> def format ( self , x , y , width ) : <EOL> leftGap , rightGap = determineGaps ( width , self . width ) <EOL> Path ( x , y ) . h ( leftGap ) . addTo ( self ) <EOL> Path ( x + leftGap + self . width , y ) . h ( rightGap ) . addTo ( self ) <EOL> x += leftGap <EOL> last = len ( self . items ) - <NUM_LIT:1> <EOL> innerWidth = self . width - ( ARC_RADIUS * <NUM_LIT:4> ) <EOL> above = self . items [ : self . default ] <EOL> if above : <EOL> distanceFromY = max ( <EOL> ARC_RADIUS * <NUM_LIT:2> , <EOL> self . items [ self . default ] . up <EOL> + VERTICAL_SEPARATION <EOL> + self . items [ self . default - <NUM_LIT:1> ] . down ) <EOL> for i , item in list ( enumerate ( above ) ) [ : : - <NUM_LIT:1> ] : <EOL> Path ( x , y ) . arc ( '<STR_LIT>' ) . up ( distanceFromY - ( ARC_RADIUS * <NUM_LIT:2> ) ) . arc ( '<STR_LIT>' ) . addTo ( self ) <EOL> item . format ( x + ( ARC_RADIUS * <NUM_LIT:2> ) , y - distanceFromY , innerWidth ) <EOL> Path ( x + ( ARC_RADIUS * <NUM_LIT:2> ) + innerWidth , y + item . yAdvance - distanceFromY ) . arc ( '<STR_LIT>' ) . down ( distanceFromY + self . yAdvance - item . yAdvance - ( ARC_RADIUS * <NUM_LIT:2> ) ) . arc ( '<STR_LIT>' ) . addTo ( self ) <EOL> item . addTo ( self ) <EOL> distanceFromY += max ( <EOL> ARC_RADIUS , <EOL> item . up <EOL> + VERTICAL_SEPARATION <EOL> + ( self . items [ i - <NUM_LIT:1> ] . down if i > <NUM_LIT:0> else <NUM_LIT:0> ) ) <EOL> Path ( x , y ) . right ( ARC_RADIUS * <NUM_LIT:2> ) . addTo ( self ) <EOL> self . items [ self . default ] . format ( x + ( ARC_RADIUS * <NUM_LIT:2> ) , y , innerWidth ) <EOL> Path ( x + ( ARC_RADIUS * <NUM_LIT:2> ) + innerWidth , y + self . yAdvance ) . right ( ARC_RADIUS * <NUM_LIT:2> ) . addTo ( self ) <EOL> self . items [ self . default ] . addTo ( self ) <EOL> below = self . items [ self . default + <NUM_LIT:1> : ] <EOL> for i , item in enumerate ( below ) : <EOL> if i == <NUM_LIT:0> : <EOL> distanceFromY = max ( <EOL> ARC_RADIUS * <NUM_LIT:2> , <EOL> self . items [ self . default ] . down <EOL> + VERTICAL_SEPARATION <EOL> + item . up ) <EOL> Path ( x , y ) . arc ( '<STR_LIT>' ) . down ( distanceFromY - ( ARC_RADIUS * <NUM_LIT:2> ) ) . arc ( '<STR_LIT>' ) . addTo ( self ) <EOL> item . format ( x + ( ARC_RADIUS * <NUM_LIT:2> ) , y + distanceFromY , innerWidth ) <EOL> Path ( x + ( ARC_RADIUS * <NUM_LIT:2> ) + innerWidth , y + distanceFromY + item . yAdvance ) . arc ( '<STR_LIT>' ) . up ( ( distanceFromY + item . yAdvance ) - self . yAdvance - ( ARC_RADIUS * <NUM_LIT:2> ) ) . arc ( '<STR_LIT>' ) . addTo ( self ) <EOL> item . addTo ( self ) <EOL> distanceFromY += max ( <EOL> ARC_RADIUS , <EOL> item . down <EOL> + VERTICAL_SEPARATION <EOL> + ( below [ i + <NUM_LIT:1> ] . up if i + <NUM_LIT:1> < len ( below ) else <NUM_LIT:0> ) ) <EOL> return self <EOL> def Optional ( item , skip = False ) : <EOL> return Choice ( <NUM_LIT:0> if skip else <NUM_LIT:1> , Skip ( ) , item ) <EOL> class OneOrMore ( DiagramItem ) : <EOL> def __init__ ( self , item , repeat = None ) : <EOL> DiagramItem . __init__ ( self , '<STR_LIT:g>' ) <EOL> repeat = repeat or Skip ( ) <EOL> self . item = wrapString ( item ) <EOL> self . rep = wrapString ( repeat ) <EOL> self . width = max ( self . item . width , self . rep . width ) + ( ARC_RADIUS * <NUM_LIT:2> ) <EOL> self . up = self . item . up <EOL> self . down = max ( <EOL> ARC_RADIUS * <NUM_LIT:2> , <EOL> self . item . down + VERTICAL_SEPARATION + self . rep . up + self . rep . down ) <EOL> self . yAdvance = self . item . yAdvance <EOL> self . needsSpace = True <EOL> if DEBUG : <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" . format ( self . up , self . down ) <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> def format ( self , x , y , width ) : <EOL> leftGap , rightGap = determineGaps ( width , self . width ) <EOL> Path ( x , y ) . h ( leftGap ) . addTo ( self ) <EOL> Path ( x + leftGap + self . width , y ) . h ( rightGap ) . addTo ( self ) <EOL> x += leftGap <EOL> Path ( x , y ) . right ( ARC_RADIUS ) . addTo ( self ) <EOL> self . item . format ( x + ARC_RADIUS , y , self . width - ( ARC_RADIUS * <NUM_LIT:2> ) ) <EOL> Path ( x + self . width - ARC_RADIUS , y + self . yAdvance ) . right ( ARC_RADIUS ) . addTo ( self ) <EOL> distanceFromY = max ( ARC_RADIUS * <NUM_LIT:2> , self . item . down + VERTICAL_SEPARATION + self . rep . up ) <EOL> Path ( x + ARC_RADIUS , y ) . arc ( '<STR_LIT>' ) . down ( distanceFromY - ( ARC_RADIUS * <NUM_LIT:2> ) ) . arc ( '<STR_LIT>' ) . addTo ( self ) <EOL> self . rep . format ( x + ARC_RADIUS , y + distanceFromY , self . width - ( ARC_RADIUS * <NUM_LIT:2> ) ) <EOL> Path ( x + self . width - ARC_RADIUS , y + distanceFromY ) . arc ( '<STR_LIT>' ) . up ( distanceFromY - self . yAdvance - ( ARC_RADIUS * <NUM_LIT:2> ) ) . arc ( '<STR_LIT>' ) . addTo ( self ) <EOL> self . item . addTo ( self ) <EOL> self . rep . addTo ( self ) <EOL> return self <EOL> def ZeroOrMore ( item , repeat = None ) : <EOL> result = Optional ( OneOrMore ( item , repeat ) ) <EOL> return result <EOL> class Start ( DiagramItem ) : <EOL> def __init__ ( self ) : <EOL> DiagramItem . __init__ ( self , '<STR_LIT:path>' ) <EOL> self . width = <NUM_LIT:20> <EOL> self . up = <NUM_LIT:10> <EOL> self . down = <NUM_LIT:10> <EOL> if DEBUG : <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" . format ( self . up , self . down ) <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT:start>" <EOL> def format ( self , x , y , _width ) : <EOL> self . attrs [ '<STR_LIT:d>' ] = '<STR_LIT>' . format ( x , y - <NUM_LIT:10> ) <EOL> return self <EOL> class End ( DiagramItem ) : <EOL> def __init__ ( self ) : <EOL> DiagramItem . __init__ ( self , '<STR_LIT:path>' ) <EOL> self . width = <NUM_LIT:20> <EOL> self . up = <NUM_LIT:10> <EOL> self . down = <NUM_LIT:10> <EOL> if DEBUG : <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" . format ( self . up , self . down ) <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT:end>" <EOL> def format ( self , x , y , _width ) : <EOL> self . attrs [ '<STR_LIT:d>' ] = '<STR_LIT>' . format ( x , y ) <EOL> return self <EOL> class TextDiagramItem ( DiagramItem ) : <EOL> def __init__ ( self , prelude ) : <EOL> DiagramItem . __init__ ( self , '<STR_LIT:g>' ) <EOL> self . raw = "<STR_LIT>" in prelude . split ( ) <EOL> class Terminal ( TextDiagramItem ) : <EOL> def __init__ ( self , text , prelude = "<STR_LIT>" ) : <EOL> TextDiagramItem . __init__ ( self , prelude ) <EOL> self . text = text <EOL> self . prelude = prelude <EOL> self . width = len ( text ) * CHARACTER_ADVANCE + <NUM_LIT:20> <EOL> self . up = <NUM_LIT:11> <EOL> self . down = <NUM_LIT:11> <EOL> self . needsSpace = True <EOL> if DEBUG : <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" . format ( self . up , self . down ) <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> def format ( self , x , y , width ) : <EOL> leftGap , rightGap = determineGaps ( width , self . width ) <EOL> Path ( x , y ) . h ( leftGap ) . addTo ( self ) <EOL> Path ( x + leftGap + self . width , y ) . h ( rightGap ) . addTo ( self ) <EOL> DiagramItem ( '<STR_LIT>' , { '<STR_LIT:x>' : x + leftGap , '<STR_LIT:y>' : y - <NUM_LIT:11> , '<STR_LIT:width>' : self . width , <EOL> '<STR_LIT>' : self . up + self . down , '<STR_LIT>' : <NUM_LIT:10> , '<STR_LIT>' : <NUM_LIT:10> } ) . addTo ( self ) <EOL> DiagramItem ( '<STR_LIT:text>' , { '<STR_LIT:x>' : x + width / <NUM_LIT:2> , '<STR_LIT:y>' : y + <NUM_LIT:4> } , self . text ) . addTo ( self ) <EOL> return self <EOL> class NonTerminal ( TextDiagramItem ) : <EOL> def __init__ ( self , text , prelude = "<STR_LIT>" ) : <EOL> TextDiagramItem . __init__ ( self , prelude ) <EOL> self . text = text <EOL> self . prelude = prelude <EOL> self . width = len ( text ) * CHARACTER_ADVANCE + <NUM_LIT:20> <EOL> self . up = <NUM_LIT:11> <EOL> self . down = <NUM_LIT:11> <EOL> self . needsSpace = True <EOL> if DEBUG : <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" . format ( self . up , self . down ) <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> def format ( self , x , y , width ) : <EOL> leftGap , rightGap = determineGaps ( width , self . width ) <EOL> Path ( x , y ) . h ( leftGap ) . addTo ( self ) <EOL> Path ( x + leftGap + self . width , y ) . h ( rightGap ) . addTo ( self ) <EOL> DiagramItem ( '<STR_LIT>' , { '<STR_LIT:x>' : x + leftGap , '<STR_LIT:y>' : y - <NUM_LIT:11> , '<STR_LIT:width>' : self . width , <EOL> '<STR_LIT>' : self . up + self . down } ) . addTo ( self ) <EOL> DiagramItem ( '<STR_LIT:text>' , { '<STR_LIT:x>' : x + width / <NUM_LIT:2> , '<STR_LIT:y>' : y + <NUM_LIT:4> } , self . text ) . addTo ( self ) <EOL> return self <EOL> class Comment ( TextDiagramItem ) : <EOL> def __init__ ( self , text , prelude = "<STR_LIT>" ) : <EOL> TextDiagramItem . __init__ ( self , prelude ) <EOL> self . text = text <EOL> self . prelude = prelude <EOL> self . width = len ( text ) * <NUM_LIT:7> + <NUM_LIT:10> <EOL> self . up = <NUM_LIT:11> <EOL> self . down = <NUM_LIT:11> <EOL> self . needsSpace = True <EOL> if DEBUG : <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" . format ( self . up , self . down ) <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> def format ( self , x , y , width ) : <EOL> leftGap , rightGap = determineGaps ( width , self . width ) <EOL> Path ( x , y ) . h ( leftGap ) . addTo ( self ) <EOL> Path ( x + leftGap + self . width , y ) . h ( rightGap ) . addTo ( self ) <EOL> DiagramItem ( '<STR_LIT:text>' , { '<STR_LIT:x>' : x + width / <NUM_LIT:2> , '<STR_LIT:y>' : y + <NUM_LIT:5> , '<STR_LIT:class>' : '<STR_LIT>' } , self . text ) . addTo ( self ) <EOL> return self <EOL> class Skip ( TextDiagramItem ) : <EOL> def __init__ ( self , prelude = "<STR_LIT>" ) : <EOL> TextDiagramItem . __init__ ( self , prelude ) <EOL> self . prelude = prelude <EOL> self . width = <NUM_LIT:0> <EOL> self . up = <NUM_LIT:0> <EOL> self . down = <NUM_LIT:0> <EOL> if DEBUG : <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" . format ( self . up , self . down ) <EOL> self . attrs [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> def format ( self , x , y , width ) : <EOL> Path ( x , y ) . right ( width ) . addTo ( self ) <EOL> return self <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> def add ( name , diagram ) : <EOL> sys . stdout . write ( '<STR_LIT>' . format ( e ( name ) ) ) <EOL> diagram . writeSvg ( sys . stdout . write ) <EOL> sys . stdout . write ( '<STR_LIT:\n>' ) <EOL> import sys <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> exec ( open ( '<STR_LIT>' ) . read ( ) ) </s>
