godot/xdot_parser.py
def define_parser(self):
        """ Defines xdot grammar.

        @see: http://graphviz.org/doc/info/output.html#d:xdot """

        # Common constructs.
        point = Group(integer.setResultsName("x") +
                      integer.setResultsName("y"))
        n_points = (integer.setResultsName("n") +
            OneOrMore(point).setResultsName("points"))
        n_bytes = Suppress(integer) + Suppress(minus) + \
            Word(printables).setResultsName("b")
        justify = ToInteger(
            Literal("-1") | Literal("0") | Literal("1")
        ).setResultsName("j")

        # Attributes ----------------------------------------------------------

        # Set fill color. The color value consists of the n bytes following
        # the '-'.
        fill = (Literal("C").suppress() + Suppress(integer) + Suppress(minus) +
            colour.setResultsName("color")).setResultsName("fill")

        # Set pen color. The color value consists of the n bytes following '-'.
        stroke = (Literal("c").suppress() + Suppress(integer) +
            Suppress(minus) + colour.setResultsName("color")
        ).setResultsName("stroke")

        # Set font. The font size is s points. The font name consists of the
        # n bytes following '-'.
        font = (Literal("F").suppress() + real.setResultsName("s") +
            n_bytes).setResultsName("font")

        # Set style attribute. The style value consists of the n bytes
        # following '-'. The syntax of the value is the same as specified for
        # a styleItem in style.
        style = (Literal("S").suppress() + n_bytes).setResultsName("style")

        # Shapes --------------------------------------------------------------

        # Filled ellipse ((x-x0)/w)^2 + ((y-y0)/h)^2 = 1
        filled_ellipse = (Literal("E").suppress() +
            integer.setResultsName("x0") + integer.setResultsName("y0") +
            integer.setResultsName("w") + integer.setResultsName("h")
        ).setResultsName("filled_ellipse")

        # Unfilled ellipse ((x-x0)/w)^2 + ((y-y0)/h)^2 = 1
        ellipse = (Literal("e").suppress() +
            integer.setResultsName("x0") + integer.setResultsName("y0") +
            integer.setResultsName("w") + integer.setResultsName("h")
        ).setResultsName("ellipse")

        # Filled polygon using the given n points.
        filled_polygon = (Literal("P").suppress() +
            n_points).setResultsName("filled_polygon")

        # Unfilled polygon using the given n points.
        polygon = (Literal("p").suppress() +
            n_points).setResultsName("polygon")

        # Polyline using the given n points.
        polyline = (Literal("L").suppress() +
            n_points).setResultsName("polyline")

        # B-spline using the given n control points.
        bspline = (Literal("B").suppress() +
            n_points).setResultsName("bspline")

        # Filled B-spline using the given n control points.
        filled_bspline = (Literal("b").suppress() +
            n_points).setResultsName("filled_bspline")

        # Text drawn using the baseline point (x,y). The text consists of the
        # n bytes following '-'. The text should be left-aligned (centered,
        # right-aligned) on the point if j is -1 (0, 1), respectively. The
        # value w gives the width of the text as computed by the library.
        text = (Literal("T").suppress() + integer.setResultsName("x") +
            integer.setResultsName("y") + justify +
            integer.setResultsName("w") + n_bytes).setResultsName("text")

        # Externally-specified image drawn in the box with lower left corner
        # (x,y) and upper right corner (x+w,y+h). The name of the image
        # consists of the n bytes following '-'. This is usually a bitmap
        # image. Note that the image size, even when converted from pixels to
        # points, might be different from the required size (w,h). It is
        # assumed the renderer will perform the necessary scaling.
        image = (Literal("I").suppress() + integer.setResultsName("x") +
            integer.setResultsName("y") + integer.setResultsName("w") +
            integer.setResultsName("h") + n_bytes).setResultsName("image")


        # The value of the drawing attributes consists of the concatenation of
        # some (multi-)set of the 13 rendering or attribute operations.
        value = (Optional(quote).suppress() + OneOrMore(filled_ellipse |
            ellipse | filled_polygon | polygon | polyline | bspline |
            filled_bspline | text | fill | stroke | font | style | image) +
            Optional(quote).suppress()).setResultsName("value")

        # Drawing operation.
#        draw_ = Literal("_draw_") + Suppress(equals) + value
#        # Label drawing.
#        ldraw_ = Literal("_ldraw_") + Suppress(equals) + value
#        # Edge head arrowhead drawing.
#        hdraw_ = Literal("_hdraw_") + Suppress(equals) + value
#        # Edge tail arrowhead drawing.
#        tdraw_ = Literal("_tdraw_") + Suppress(equals) + value
#        # Edge head label drawing.
#        hldraw_ = Literal("_hldraw_") + Suppress(equals) + value
#        # Edge tail label drawing.
#        tldraw_ = Literal("_tldraw_") + Suppress(equals) + value

        # Parse actions.
#        n_points.setParseAction(self.proc_points)

        # Attribute parse actions.
        fill.setParseAction(self.proc_fill_color)
        stroke.setParseAction(self.proc_stroke_color)
        font.setParseAction(self.proc_font)
        style.setParseAction(self.proc_style)

        # Shape parse actions.
        filled_ellipse.setParseAction(self.proc_filled_ellipse)
        ellipse.setParseAction(self.proc_unfilled_ellipse)
        filled_polygon.setParseAction(self.proc_filled_polygon)
        polygon.setParseAction(self.proc_unfilled_polygon)
        polyline.setParseAction(self.proc_polyline)
        bspline.setParseAction(self.proc_unfilled_bspline)
        filled_bspline.setParseAction(self.proc_filled_bspline)
        text.setParseAction(self.proc_text)
        image.setParseAction(self.proc_image)

        return value
def define_parser(self):
        """ Defines xdot grammar.

        @see: http://graphviz.org/doc/info/output.html#d:xdot """

        # Common constructs.
        point = Group(integer.setResultsName("x") +
                      integer.setResultsName("y"))
        n_points = (integer.setResultsName("n") +
            OneOrMore(point).setResultsName("points"))
        n_bytes = Suppress(integer) + Suppress(minus) + \
            Word(printables).setResultsName("b")
        justify = ToInteger(
            Literal("-1") | Literal("0") | Literal("1")
        ).setResultsName("j")

        # Attributes ----------------------------------------------------------

        # Set fill color. The color value consists of the n bytes following
        # the '-'.
        fill = (Literal("C").suppress() + Suppress(integer) + Suppress(minus) +
            colour.setResultsName("color")).setResultsName("fill")

        # Set pen color. The color value consists of the n bytes following '-'.
        stroke = (Literal("c").suppress() + Suppress(integer) +
            Suppress(minus) + colour.setResultsName("color")
        ).setResultsName("stroke")

        # Set font. The font size is s points. The font name consists of the
        # n bytes following '-'.
        font = (Literal("F").suppress() + real.setResultsName("s") +
            n_bytes).setResultsName("font")

        # Set style attribute. The style value consists of the n bytes
        # following '-'. The syntax of the value is the same as specified for
        # a styleItem in style.
        style = (Literal("S").suppress() + n_bytes).setResultsName("style")

        # Shapes --------------------------------------------------------------

        # Filled ellipse ((x-x0)/w)^2 + ((y-y0)/h)^2 = 1
        filled_ellipse = (Literal("E").suppress() +
            integer.setResultsName("x0") + integer.setResultsName("y0") +
            integer.setResultsName("w") + integer.setResultsName("h")
        ).setResultsName("filled_ellipse")

        # Unfilled ellipse ((x-x0)/w)^2 + ((y-y0)/h)^2 = 1
        ellipse = (Literal("e").suppress() +
            integer.setResultsName("x0") + integer.setResultsName("y0") +
            integer.setResultsName("w") + integer.setResultsName("h")
        ).setResultsName("ellipse")

        # Filled polygon using the given n points.
        filled_polygon = (Literal("P").suppress() +
            n_points).setResultsName("filled_polygon")

        # Unfilled polygon using the given n points.
        polygon = (Literal("p").suppress() +
            n_points).setResultsName("polygon")

        # Polyline using the given n points.
        polyline = (Literal("L").suppress() +
            n_points).setResultsName("polyline")

        # B-spline using the given n control points.
        bspline = (Literal("B").suppress() +
            n_points).setResultsName("bspline")

        # Filled B-spline using the given n control points.
        filled_bspline = (Literal("b").suppress() +
            n_points).setResultsName("filled_bspline")

        # Text drawn using the baseline point (x,y). The text consists of the
        # n bytes following '-'. The text should be left-aligned (centered,
        # right-aligned) on the point if j is -1 (0, 1), respectively. The
        # value w gives the width of the text as computed by the library.
        text = (Literal("T").suppress() + integer.setResultsName("x") +
            integer.setResultsName("y") + justify +
            integer.setResultsName("w") + n_bytes).setResultsName("text")

        # Externally-specified image drawn in the box with lower left corner
        # (x,y) and upper right corner (x+w,y+h). The name of the image
        # consists of the n bytes following '-'. This is usually a bitmap
        # image. Note that the image size, even when converted from pixels to
        # points, might be different from the required size (w,h). It is
        # assumed the renderer will perform the necessary scaling.
        image = (Literal("I").suppress() + integer.setResultsName("x") +
            integer.setResultsName("y") + integer.setResultsName("w") +
            integer.setResultsName("h") + n_bytes).setResultsName("image")


        # The value of the drawing attributes consists of the concatenation of
        # some (multi-)set of the 13 rendering or attribute operations.
        value = (Optional(quote).suppress() + OneOrMore(filled_ellipse |
            ellipse | filled_polygon | polygon | polyline | bspline |
            filled_bspline | text | fill | stroke | font | style | image) +
            Optional(quote).suppress()).setResultsName("value")

        # Drawing operation.
#        draw_ = Literal("_draw_") + Suppress(equals) + value
#        # Label drawing.
#        ldraw_ = Literal("_ldraw_") + Suppress(equals) + value
#        # Edge head arrowhead drawing.
#        hdraw_ = Literal("_hdraw_") + Suppress(equals) + value
#        # Edge tail arrowhead drawing.
#        tdraw_ = Literal("_tdraw_") + Suppress(equals) + value
#        # Edge head label drawing.
#        hldraw_ = Literal("_hldraw_") + Suppress(equals) + value
#        # Edge tail label drawing.
#        tldraw_ = Literal("_tldraw_") + Suppress(equals) + value

        # Parse actions.
#        n_points.setParseAction(self.proc_points)

        # Attribute parse actions.
        fill.setParseAction(self.proc_fill_color)
        stroke.setParseAction(self.proc_stroke_color)
        font.setParseAction(self.proc_font)
        style.setParseAction(self.proc_style)

        # Shape parse actions.
        filled_ellipse.setParseAction(self.proc_filled_ellipse)
        ellipse.setParseAction(self.proc_unfilled_ellipse)
        filled_polygon.setParseAction(self.proc_filled_polygon)
        polygon.setParseAction(self.proc_unfilled_polygon)
        polyline.setParseAction(self.proc_polyline)
        bspline.setParseAction(self.proc_unfilled_bspline)
        filled_bspline.setParseAction(self.proc_filled_bspline)
        text.setParseAction(self.proc_text)
        image.setParseAction(self.proc_image)

        return value
def define_parser ( self ) : # Common constructs. point = Group ( integer . setResultsName ( "x" ) + integer . setResultsName ( "y" ) ) n_points = ( integer . setResultsName ( "n" ) + OneOrMore ( point ) . setResultsName ( "points" ) ) n_bytes = Suppress ( integer ) + Suppress ( minus ) + Word ( printables ) . setResultsName ( "b" ) justify = ToInteger ( Literal ( "-1" ) | Literal ( "0" ) | Literal ( "1" ) ) . setResultsName ( "j" ) # Attributes ---------------------------------------------------------- # Set fill color. The color value consists of the n bytes following # the '-'. fill = ( Literal ( "C" ) . suppress ( ) + Suppress ( integer ) + Suppress ( minus ) + colour . setResultsName ( "color" ) ) . setResultsName ( "fill" ) # Set pen color. The color value consists of the n bytes following '-'. stroke = ( Literal ( "c" ) . suppress ( ) + Suppress ( integer ) + Suppress ( minus ) + colour . setResultsName ( "color" ) ) . setResultsName ( "stroke" ) # Set font. The font size is s points. The font name consists of the # n bytes following '-'. font = ( Literal ( "F" ) . suppress ( ) + real . setResultsName ( "s" ) + n_bytes ) . setResultsName ( "font" ) # Set style attribute. The style value consists of the n bytes # following '-'. The syntax of the value is the same as specified for # a styleItem in style. style = ( Literal ( "S" ) . suppress ( ) + n_bytes ) . setResultsName ( "style" ) # Shapes -------------------------------------------------------------- # Filled ellipse ((x-x0)/w)^2 + ((y-y0)/h)^2 = 1 filled_ellipse = ( Literal ( "E" ) . suppress ( ) + integer . setResultsName ( "x0" ) + integer . setResultsName ( "y0" ) + integer . setResultsName ( "w" ) + integer . setResultsName ( "h" ) ) . setResultsName ( "filled_ellipse" ) # Unfilled ellipse ((x-x0)/w)^2 + ((y-y0)/h)^2 = 1 ellipse = ( Literal ( "e" ) . suppress ( ) + integer . setResultsName ( "x0" ) + integer . setResultsName ( "y0" ) + integer . setResultsName ( "w" ) + integer . setResultsName ( "h" ) ) . setResultsName ( "ellipse" ) # Filled polygon using the given n points. filled_polygon = ( Literal ( "P" ) . suppress ( ) + n_points ) . setResultsName ( "filled_polygon" ) # Unfilled polygon using the given n points. polygon = ( Literal ( "p" ) . suppress ( ) + n_points ) . setResultsName ( "polygon" ) # Polyline using the given n points. polyline = ( Literal ( "L" ) . suppress ( ) + n_points ) . setResultsName ( "polyline" ) # B-spline using the given n control points. bspline = ( Literal ( "B" ) . suppress ( ) + n_points ) . setResultsName ( "bspline" ) # Filled B-spline using the given n control points. filled_bspline = ( Literal ( "b" ) . suppress ( ) + n_points ) . setResultsName ( "filled_bspline" ) # Text drawn using the baseline point (x,y). The text consists of the # n bytes following '-'. The text should be left-aligned (centered, # right-aligned) on the point if j is -1 (0, 1), respectively. The # value w gives the width of the text as computed by the library. text = ( Literal ( "T" ) . suppress ( ) + integer . setResultsName ( "x" ) + integer . setResultsName ( "y" ) + justify + integer . setResultsName ( "w" ) + n_bytes ) . setResultsName ( "text" ) # Externally-specified image drawn in the box with lower left corner # (x,y) and upper right corner (x+w,y+h). The name of the image # consists of the n bytes following '-'. This is usually a bitmap # image. Note that the image size, even when converted from pixels to # points, might be different from the required size (w,h). It is # assumed the renderer will perform the necessary scaling. image = ( Literal ( "I" ) . suppress ( ) + integer . setResultsName ( "x" ) + integer . setResultsName ( "y" ) + integer . setResultsName ( "w" ) + integer . setResultsName ( "h" ) + n_bytes ) . setResultsName ( "image" ) # The value of the drawing attributes consists of the concatenation of # some (multi-)set of the 13 rendering or attribute operations. value = ( Optional ( quote ) . suppress ( ) + OneOrMore ( filled_ellipse | ellipse | filled_polygon | polygon | polyline | bspline | filled_bspline | text | fill | stroke | font | style | image ) + Optional ( quote ) . suppress ( ) ) . setResultsName ( "value" ) # Drawing operation. #        draw_ = Literal("_draw_") + Suppress(equals) + value #        # Label drawing. #        ldraw_ = Literal("_ldraw_") + Suppress(equals) + value #        # Edge head arrowhead drawing. #        hdraw_ = Literal("_hdraw_") + Suppress(equals) + value #        # Edge tail arrowhead drawing. #        tdraw_ = Literal("_tdraw_") + Suppress(equals) + value #        # Edge head label drawing. #        hldraw_ = Literal("_hldraw_") + Suppress(equals) + value #        # Edge tail label drawing. #        tldraw_ = Literal("_tldraw_") + Suppress(equals) + value # Parse actions. #        n_points.setParseAction(self.proc_points) # Attribute parse actions. fill . setParseAction ( self . proc_fill_color ) stroke . setParseAction ( self . proc_stroke_color ) font . setParseAction ( self . proc_font ) style . setParseAction ( self . proc_style ) # Shape parse actions. filled_ellipse . setParseAction ( self . proc_filled_ellipse ) ellipse . setParseAction ( self . proc_unfilled_ellipse ) filled_polygon . setParseAction ( self . proc_filled_polygon ) polygon . setParseAction ( self . proc_unfilled_polygon ) polyline . setParseAction ( self . proc_polyline ) bspline . setParseAction ( self . proc_unfilled_bspline ) filled_bspline . setParseAction ( self . proc_filled_bspline ) text . setParseAction ( self . proc_text ) image . setParseAction ( self . proc_image ) return value
Defines xdot grammar.

        @see: http://graphviz.org/doc/info/output.html#d:xdot
Defines xdot grammar .