Commit ac9856c6 authored by Camil Staps's avatar Camil Staps 🐧

Merge branch...

Merge branch 'defunctionalized-functionalized-SVG-functions-plus-paths-for-efficient-lookup' into 'master'

Defunctionalized functionalized svg functions plus paths for efficient lookup

See merge request !258
parents d173f9b4 4777effc
Pipeline #25350 passed with stage
in 3 minutes and 59 seconds
implementation module Graphics.Scalable.Image
from StdList import repeat
import StdMisc
import StdList, StdMisc
from Data.Maybe import :: Maybe (..), instance Functor Maybe, maybeToList
from Data.Functor import class Functor (..)
import Graphics.Scalable.Internal.Image`
......@@ -75,22 +74,32 @@ skewy :: !Angle !(Image m) -> Image m
skewy a image = Skewy` a image
overlay :: ![XYAlign] ![ImageOffset] ![Image m] !(Host m) -> Image m
overlay aligns offsets images host = Overlay` aligns offsets images (toHost` host)
overlay aligns offsets images host = Overlay` (take n aligns) (take n offsets) images (toHost` host)
where
n = length images
collage :: ![ImageOffset] ![Image m] !(Host m) -> Image m
collage offsets images host = Overlay` (repeat (AtLeft,AtTop)) offsets images (toHost` host)
collage offsets images host = Overlay` [] (take n offsets) images (toHost` host)
where
n = length images
beside :: ![YAlign] ![Span] !(Maybe Span) ![ImageOffset] ![Image m] !(Host m) -> Image m
beside ylayouts column_widths row_height offsets imgs host
= Grid` (Rows 1) (RowMajor, LeftToRight, TopToBottom) [(AtLeft, ylayout) \\ ylayout <- ylayouts] column_widths (maybeToList row_height) offsets imgs (toHost` host)
beside ylayouts column_widths row_height offsets images host
= Grid` (Rows 1) (RowMajor, LeftToRight, TopToBottom) [(AtLeft, ylayout) \\ ylayout <- take n ylayouts] (take n column_widths) (maybeToList row_height) (take n offsets) images (toHost` host)
where
n = length images
above :: ![XAlign] ![Span] !(Maybe Span) ![ImageOffset] ![Image m] !(Host m) -> Image m
above xlayouts row_heights column_width offsets imgs host
= Grid` (Columns 1) (ColumnMajor, LeftToRight, TopToBottom) [(xlayout, AtTop) \\ xlayout <- xlayouts] (maybeToList column_width) row_heights offsets imgs (toHost` host)
above xlayouts row_heights column_width offsets images host
= Grid` (Columns 1) (ColumnMajor, LeftToRight, TopToBottom) [(xlayout, AtTop) \\ xlayout <- take n xlayouts] (maybeToList column_width) (take n row_heights) (take n offsets) images (toHost` host)
where
n = length images
grid :: !GridDimension !GridLayout ![XYAlign] ![Span] ![Span] ![ImageOffset] ![Image m] !(Host m) -> Image m
grid dimension layout aligns column_widths row_heights offsets images host
= Grid` dimension layout aligns column_widths row_heights offsets images (toHost` host)
= Grid` dimension layout (take n aligns) (take n column_widths) (take n row_heights) (take n offsets) images (toHost` host)
where
n = length images
:: Host m = NoHost | Host (Image m)
......@@ -139,6 +148,7 @@ instance tuneImage YRadiusAttr where tuneImage image attr = Attr` (BasicImag
instance tuneImage DraggableAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerDraggableAttr attr)) image
instance tuneImage OnClickAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnClickAttr attr)) image
instance tuneImage OnNClickAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnNClickAttr attr)) image
instance tuneImage OnMouseDownAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnMouseDownAttr attr)) image
instance tuneImage OnMouseMoveAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnMouseMoveAttr attr)) image
instance tuneImage OnMouseOutAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnMouseOutAttr attr)) image
......@@ -166,4 +176,4 @@ tag t image = Tag` t image
tagWithSrc :: !*TagSource !(Image m) -> *(!(!Image m, !ImageTag), !*TagSource)
tagWithSrc [(nut, t) : tsrc] image
= ((Tag` t image, nut), tsrc)
tagWithSrc _ _ = abort "empty TagSource in tagWithSrc\n"
tagWithSrc _ _ = abort "empty TagSource in tagWithSrc.\n"
......@@ -38,8 +38,8 @@ import Graphics.Scalable.Internal.Types
| LineMarkerAttr` !(LineMarkerAttr m)
| MaskAttr` !(Image` m)
| HandlerAttr` !(ImgEventhandler m)
:: ImgTables m
= { imgEventhandlers :: !ImgEventhandlers m
:: ImgTables
= { imgEventhandlers :: !ImgEventhandlers`
, imgNewFonts :: !ImgFonts
, imgNewTexts :: !ImgTexts
, imgMasks :: !ImgMasks
......@@ -50,30 +50,48 @@ import Graphics.Scalable.Internal.Types
, imgTags :: !ImgTags
, imgUniqIds :: !ImgTagNo
}
:: FontSpans :== Map FontDef FontDescent // of each font, the font descent
:: ImgFonts :== Set FontDef // the collection of fonts used in the image for which no metrics are available
:: TextSpans :== Map FontDef (Map String TextSpan) // of each font, of each text of that font, the width
:: ImgEventhandlers m :== Map ImgTagNo [ImgEventhandler m] // the registered event handlers of the image identified by the id (once registered, an event handler can not be overruled)
:: ImgTexts :== Map FontDef (Set String) // of each font, the collection of texts
:: ImgMasks :== Map ImgTagNo Img // of each mask, the mask-image (associate the id with (MaskImg id))
:: ImgLineMarkers :== Map ImgTagNo LineMarkers // of each poly(gon/line) with markers, its markers
:: ImgPaths :== Map ImgTagNo ImgPath // of each poly(gon/line), initially its connecting points, and secondly, its span
:: ImgSpans :== Map ImgTagNo ImageSpan // of each image, its (width,height)
:: GridSpans :== Map ImgTagNo GridSpan // of each grid, the spans of its columns and the spans of its rows
:: ImgTags :== Map ImageTag ImgTagNo // map user-tag to system number
:: ViaImg // navigation in Img
= ViaChild !Int // ViaChild i: visit child image with index @i
| ViaHost // ViaHost: visit host image
| ViaAttr // ViaAttr: visit attribute image
:: ImgNodePath :== [ViaImg] // [i:_] visit child with index i; [] arrived at node
:: FontSpans :== Map FontDef FontDescent // of each font, the font descent
:: ImgFonts :== Set FontDef // the collection of fonts used in the image for which no metrics are available
:: TextSpans :== Map FontDef (Map String TextSpan) // of each font, of each text of that font, the width
:: ImgEventhandlers` :== Map ImgTagNo [(ImgNodePath,ImgEventhandler`)] // the defunctionalized version of ImgEventhandlers
:: ImgTexts :== Map FontDef (Set String) // of each font, the collection of texts
:: ImgMasks :== Map ImgTagNo Img // of each mask, the mask-image (associate the id with (MaskImg id))
:: ImgLineMarkers :== Map ImgTagNo LineMarkers // of each poly(gon/line) with markers, its markers
:: ImgPaths :== Map ImgTagNo ImgPath // of each poly(gon/line), initially its connecting points, and secondly, its span
:: ImgSpans :== Map ImgTagNo ImageSpan // of each image, its (width,height)
:: GridSpans :== Map ImgTagNo GridSpan // of each grid, the spans of its columns and the spans of its rows
:: ImgTags :== Map ImageTag ImgTagNo // map user-tag to system number
:: FontDescent :== Real
:: TextSpan :== Real
:: ImgEventhandler m
= ImgEventhandlerOnClickAttr !(OnClickAttr m)
| ImgEventhandlerOnNClickAttr !(OnNClickAttr m)
| ImgEventhandlerOnMouseDownAttr !(OnMouseDownAttr m)
| ImgEventhandlerOnMouseUpAttr !(OnMouseUpAttr m)
| ImgEventhandlerOnMouseOverAttr !(OnMouseOverAttr m)
| ImgEventhandlerOnMouseMoveAttr !(OnMouseMoveAttr m)
| ImgEventhandlerOnMouseOutAttr !(OnMouseOutAttr m)
| ImgEventhandlerDraggableAttr !(DraggableAttr m)
:: ImgEventhandler`
= { handler :: !DefuncImgEventhandler`, local :: !Bool }
:: DefuncImgEventhandler`
= ImgEventhandlerOnClickAttr`
| ImgEventhandlerOnNClickAttr`
| ImgEventhandlerOnMouseDownAttr`
| ImgEventhandlerOnMouseUpAttr`
| ImgEventhandlerOnMouseOverAttr`
| ImgEventhandlerOnMouseMoveAttr`
| ImgEventhandlerOnMouseOutAttr`
| ImgEventhandlerDraggableAttr`
instance == DefuncImgEventhandler`
:: ImgPath
= { pathPoints :: ![ImageOffset] // the connecting points of the path
, pathSpan :: !ImageSpan // the span of the path (also stored in imgSpans after resolving span-expressions)
= { pathPoints :: ![ImageOffset] // the connecting points of the path
, pathSpan :: !ImageSpan // the span of the path (also stored in imgSpans after resolving span-expressions)
}
:: LineMarkers
= { lineStart :: !Maybe Img
......@@ -85,11 +103,11 @@ import Graphics.Scalable.Internal.Types
, row_spans :: ![Span]
}
:: Img
= { uniqId :: !ImgTagNo // the unique system identification within the entire image
, host :: !HostImg // the host of this image
, transform :: !Maybe ImgTransform // the optional transform of the basic/composite image
, overlays :: ![Img] // the back-to-front ordering of images 'on top of' host
, offsets :: ![ImageOffset] // the offsets matching one-by-one with .overlays
= { uniqId :: !ImgTagNo // the unique system identification within the entire image
, host :: !HostImg // the host of this image
, transform :: !Maybe ImgTransform // the optional transform of the basic/composite image
, overlays :: ![Img] // the back-to-front ordering of images 'on top of' host
, offsets :: ![ImageOffset] // the offsets matching one-by-one with .overlays
}
:: HostImg
= BasicHostImg !BasicImg !(Set BasicImgAttr)
......@@ -103,7 +121,7 @@ import Graphics.Scalable.Internal.Types
| EllipseImg
| PolylineImg
| PolygonImg
:: BasicImgAttr // attributes that are applicable only on basic images
:: BasicImgAttr // attributes that are applicable only on basic images
= BasicImgDashAttr ![Int]
| BasicImgFillAttr !SVGColor
| BasicImgFillOpacityAttr !Real
......@@ -126,7 +144,7 @@ import Graphics.Scalable.Internal.Types
| ScaleImg !Real !Real
| FlipXImg
| FlipYImg
| MaskImg !ImgTagNo // the id-img pair is stored in the ImgMasks table
| MaskImg !ImgTagNo // the id-img pair is stored in the ImgMasks table
:: Host` m
= NoHost`
| Host` (Image` m)
......@@ -143,7 +161,9 @@ defaultLineMarkers :: LineMarkers
= { n :: !Span, e :: !Span, s :: !Span, w :: !Span }
defaultMargins` :: Margins`
toImg :: !(Image` m) !FontSpans !TextSpans !(ImgTables m) -> (!Img,!ImgTables m)
toImg :: !(Image` m) !ImgNodePath !FontSpans !TextSpans !ImgTables -> (!Img,!ImgTables)
getImgEventhandler :: !(Image` m) !ImgNodePath -> Maybe (ImgEventhandler m)
:: SpanResolveError :== String
......
definition module Graphics.Scalable.Internal.Types
import Graphics.Scalable.Types
import Text.GenPrint
from Text.GenJSON import generic JSONEncode, generic JSONDecode, :: JSONNode
:: Span
= PxSpan !Real // (PxSpan a) is a pixels
......@@ -21,6 +23,14 @@ import Graphics.Scalable.Types
| PathXSpan !ImageTag // (PathXSpan t) is x-span of path element tagged with t
| PathYSpan !ImageTag // (PathYSpan t) is y-span of path element tagged with t
:: FontDef`
= { fontfamily` :: !String // font family name
, fontysize` :: !Real // font size as span (px -)
, fontstretch` :: !String // default value: "normal"
, fontstyle` :: !String // default value: "normal"
, fontvariant` :: !String // default value: "normal"
, fontweight` :: !String // default value: "normal"
}
class (*.) infixl 7 a :: !a !n -> Span | toReal n
class (/.) infixl 7 a :: !a !n -> Span | toReal n
......@@ -54,3 +64,27 @@ maxSpan :: ![Span] -> Span // (maxSpan as) is the maximum of as
instance == ImageTag
instance < ImageTag
derive gEq FontDef`
derive gPrint FontDef`
derive JSONEncode FontDef`
derive JSONDecode FontDef`
setfontfamily` :: !String !FontDef` -> FontDef`
setfontysize` :: !Real !FontDef` -> FontDef`
setfontstretch` :: !String !FontDef` -> FontDef`
setfontstyle` :: !String !FontDef` -> FontDef`
setfontvariant` :: !String !FontDef` -> FontDef`
setfontweight` :: !String !FontDef` -> FontDef`
getfontfamily` :: !FontDef` -> String
getfontysize` :: !FontDef` -> Real
getfontstretch` :: !FontDef` -> String
getfontstyle` :: !FontDef` -> String
getfontvariant` :: !FontDef` -> String
getfontweight` :: !FontDef` -> String
/** to2dec r:
converts @r to a real value of two decimals in order to avoid errors in communicating real values
with SVG clients
*/
to2dec :: !Real -> Real
implementation module Graphics.Scalable.Internal.Types
import Data.List
import Text.GenPrint
from StdOrdList import minList, maxList
import Graphics.Scalable.Types
import StdBool, StdInt, StdMisc, StdReal, StdString
from Text.GenJSON import generic JSONEncode, generic JSONDecode, :: JSONNode
:: Span
= PxSpan !Real // (PxSpan a) is a pixels
......@@ -23,6 +25,14 @@ import StdBool, StdInt, StdMisc, StdReal, StdString
| TextXSpan !FontDef !String // (TextXSpan a b) is width of text b written in font a
| PathXSpan !ImageTag // (PathXSpan t) is x-span of path element tagged with t
| PathYSpan !ImageTag // (PathYSpan t) is y-span of path element tagged with t
:: FontDef`
= { fontfamily` :: !String // font family name
, fontysize` :: !Real // font size as span (px -)
, fontstretch` :: !String // default value: "normal"
, fontstyle` :: !String // default value: "normal"
, fontvariant` :: !String // default value: "normal"
, fontweight` :: !String // default value: "normal"
}
/* The span computations below simplify their expressions by applying actual computations on (PxSpan _) values as much as possible.
We denote a value (PxSpan _) with a capital letter. If we do not care or do not know, we denote the value with a lowercase letter.
......@@ -217,3 +227,48 @@ instance < ImageTag where < (ImageTagUser n1 s1) (ImageTagUser n2 s2) = n1 < n
< (ImageTagUser _ _) _ = True
< (ImageTagSystem s1) (ImageTagSystem s2) = s1 < s2
< _ _ = False
derive gEq FontDef`
derive JSONEncode FontDef`
derive JSONDecode FontDef`
derive gPrint FontDef`
setfontfamily` :: !String !FontDef` -> FontDef`
setfontfamily` family fontdef = {FontDef` | fontdef & fontfamily` = family}
setfontysize` :: !Real !FontDef` -> FontDef`
setfontysize` ysize fontdef = {FontDef` | fontdef & fontysize` = to2dec ysize}
setfontstretch` :: !String !FontDef` -> FontDef`
setfontstretch` stretch fontdef = {FontDef` | fontdef & fontstretch` = stretch}
setfontstyle` :: !String !FontDef` -> FontDef`
setfontstyle` style fontdef = {FontDef` | fontdef & fontstyle` = style}
setfontvariant` :: !String !FontDef` -> FontDef`
setfontvariant` variant fontdef = {FontDef` | fontdef & fontvariant` = variant}
setfontweight` :: !String !FontDef` -> FontDef`
setfontweight` weight fontdef = {FontDef` | fontdef & fontweight` = weight}
getfontfamily` :: !FontDef` -> String
getfontfamily` {FontDef` | fontfamily`} = fontfamily`
getfontysize` :: !FontDef` -> Real
getfontysize` {FontDef` | fontysize`} = fontysize`
getfontstretch` :: !FontDef` -> String
getfontstretch` {FontDef` | fontstretch`} = fontstretch`
getfontstyle` :: !FontDef` -> String
getfontstyle` {FontDef` | fontstyle`} = fontstyle`
getfontvariant` :: !FontDef` -> String
getfontvariant` {FontDef` | fontvariant`} = fontvariant`
getfontweight` :: !FontDef` -> String
getfontweight` {FontDef` | fontweight`} = fontweight`
to2dec :: !Real -> Real
to2dec r = toReal (toInt (r * 100.0)) / 100.0
definition module Graphics.Scalable.Types
import Data.GenEq
from Data.Maybe import :: Maybe (..)
from Data.Set import :: Set
from Text.HTML import :: SVGColor
......@@ -10,20 +11,27 @@ from Graphics.Scalable.Internal.Types import
instance abs Span, instance ~ Span, instance *. Span, instance *. Real, instance *. Int,
instance /. Span, instance /. Real, instance /. Int,
px, textxspan, imagexspan, imageyspan, columnspan, rowspan, minSpan, maxSpan,
:: ImageTag, instance == ImageTag, instance < ImageTag
:: ImageTag, instance == ImageTag, instance < ImageTag,
:: FontDef`
:: ImageSpan :== (!Span, !Span)
:: ImageOffset :== (!Span, !Span)
:: FontDef
= { fontfamily :: !String
, fontysize :: !Real
, fontstretch :: !String
, fontstyle :: !String
, fontvariant :: !String
, fontweight :: !String
}
normalFontDef :: !String !Real -> FontDef // (normalFontDef family size) sets all other fields to "normal"
:: FontDef :== FontDef`
normalFontDef :: !String !Real -> FontDef // (normalFontDef family size) sets all other fields to "normal"
setfontfamily :: !String !FontDef -> FontDef
setfontysize :: !Real !FontDef -> FontDef
setfontstretch :: !String !FontDef -> FontDef
setfontstyle :: !String !FontDef -> FontDef
setfontvariant :: !String !FontDef -> FontDef
setfontweight :: !String !FontDef -> FontDef
getfontfamily :: !FontDef -> String
getfontysize :: !FontDef -> Real
getfontstretch :: !FontDef -> String
getfontstyle :: !FontDef -> String
getfontvariant :: !FontDef -> String
getfontweight :: !FontDef -> String
instance == FontDef
instance < FontDef
instance toString FontDef
......@@ -46,12 +54,13 @@ instance == LineMarkerPos
:: YAlign = AtTop | AtMiddleY | AtBottom
:: XYAlign :== (!XAlign, !YAlign)
:: OnClickAttr m = { onclick :: !(Int m -> m), local :: !Bool }
:: OnMouseDownAttr m = { onmousedown :: !(m -> m), local :: !Bool }
:: OnMouseUpAttr m = { onmouseup :: !(m -> m), local :: !Bool }
:: OnMouseOverAttr m = { onmouseover :: !(m -> m), local :: !Bool }
:: OnMouseMoveAttr m = { onmousemove :: !(m -> m), local :: !Bool }
:: OnMouseOutAttr m = { onmouseout :: !(m -> m), local :: !Bool }
:: OnClickAttr m = { onclick :: !(m -> m), local :: !Bool } // handle single mouse click, without delay
:: OnNClickAttr m = { onNclick :: !(Int m -> m), local :: !Bool } // handle multiple mouse clicks, this comes with a brief (client dependent) delay
:: OnMouseDownAttr m = { onmousedown :: !(m -> m), local :: !Bool } // handle mouse down event
:: OnMouseUpAttr m = { onmouseup :: !(m -> m), local :: !Bool } // handle mouse up event
:: OnMouseOverAttr m = { onmouseover :: !(m -> m), local :: !Bool } // handle mouse over event (move into associated image)
:: OnMouseMoveAttr m = { onmousemove :: !(m -> m), local :: !Bool } // handle mouse move event (move inside associated image)
:: OnMouseOutAttr m = { onmouseout :: !(m -> m), local :: !Bool } // handle mouse out event (move away from associated image)
:: DraggableAttr m = { draggable :: !(SVGDragFun m) }
:: SVGDragFun m :== (Set ImageTag) (Real,Real) m -> m // \tags (x,y) model: tags is the set of ImageTag-s associated with the 'dragged-on' image, (x,y) the location within that image
:: RGB = { r :: !Int, g :: !Int, b :: !Int }
......
......@@ -5,23 +5,65 @@ import Data.List
import Data.GenEq
from Text.HTML import :: SVGColor (..)
from Data.Set import :: Set, instance == (Set a), instance < (Set a)
import Text.GenPrint
import StdBool, StdInt, StdReal, StdString
import Graphics.Scalable.Internal.Types
:: FontDef :== FontDef`
normalFontDef :: !String !Real -> FontDef // (normalFontDef family size) sets all other fields to "normal"
normalFontDef family size
= {fontfamily = family, fontysize = size, fontstretch = "normal", fontstyle = "normal", fontvariant = "normal", fontweight = "normal"}
= { fontfamily` = family
, fontysize` = to2dec (max zero size) // make sure the size can be converted correctly to the client and vice versa
, fontstretch` = "normal"
, fontstyle` = "normal"
, fontvariant` = "normal"
, fontweight` = "normal"
}
setfontfamily :: !String !FontDef -> FontDef
setfontfamily family fontdef = setfontfamily` family fontdef
setfontysize :: !Real !FontDef -> FontDef
setfontysize ysize fontdef = setfontysize` ysize fontdef
setfontstretch :: !String !FontDef -> FontDef
setfontstretch stretch fontdef = setfontstretch` stretch fontdef
setfontstyle :: !String !FontDef -> FontDef
setfontstyle style fontdef = setfontstyle` style fontdef
setfontvariant :: !String !FontDef -> FontDef
setfontvariant variant fontdef = setfontvariant` variant fontdef
setfontweight :: !String !FontDef -> FontDef
setfontweight weight fontdef = setfontweight` weight fontdef
getfontfamily :: !FontDef -> String
getfontfamily fontdef = getfontfamily` fontdef
getfontysize :: !FontDef -> Real
getfontysize fontdef = getfontysize` fontdef
getfontstretch :: !FontDef -> String
getfontstretch fontdef = getfontstretch` fontdef
getfontstyle :: !FontDef -> String
getfontstyle fontdef = getfontstyle` fontdef
getfontvariant :: !FontDef -> String
getfontvariant fontdef = getfontvariant` fontdef
getfontweight :: !FontDef -> String
getfontweight fontdef = getfontweight` fontdef
instance == FontDef where == fd1 fd2 = fd1 === fd2
instance < FontDef where < fd1 fd2 = fd1.fontfamily < fd2.fontfamily
|| fd1.fontysize < fd2.fontysize
|| fd1.fontstretch < fd2.fontstretch
|| fd1.fontstyle < fd2.fontstyle
|| fd1.fontvariant < fd2.fontvariant
|| fd1.fontweight < fd2.fontweight
derive gEq FontDef
import Text.GenPrint
derive gPrint FontDef
instance < FontDef where < fd1 fd2 = fd1.fontfamily` < fd2.fontfamily`
|| fd1.fontysize` < fd2.fontysize`
|| fd1.fontstretch` < fd2.fontstretch`
|| fd1.fontstyle` < fd2.fontstyle`
|| fd1.fontvariant` < fd2.fontvariant`
|| fd1.fontweight` < fd2.fontweight`
instance toString FontDef where toString font = printToString font
derive gEq LineMarkerPos
......
definition module Text.GenXML
/**
* This module provides data types for easy construction of XML documents and
* a generic printer/parser.
*/
import StdOverloaded, StdGeneric, Data.Either
from Data.Maybe import :: Maybe
from Data.Error import :: MaybeErrorString, :: MaybeError
:: XMLDoc = XMLDoc !(Maybe XMLURI) ![(!XMLNamespacePrefix,!XMLURI)] !XMLNode
:: XMLNode = XMLElem !XMLQName ![XMLAttr] ![XMLNode]
| XMLText !String
:: XMLAttr = XMLAttr !XMLQName !String
:: XMLQName = XMLQName !(Maybe XMLNamespacePrefix) !XMLName
:: XMLNamespacePrefix :== String
:: XMLURI :== String
:: XMLName :== String
/**
* Create an XMLQName containing an unqualified name from a String
* @param Unqualified name
* @return XMLQName containing the unqualified name
*/
uname :: !String -> XMLQName
/**
* Create an XMLQName containing a qualified name from a String
* @param Qualified name
* @return XMLQName containing the qualified name
*/
qname :: !XMLNamespacePrefix !String -> XMLQName
instance toString XMLDoc
instance fromString (MaybeErrorString XMLDoc)
// generic printer
toXML :: !a -> XMLDoc | XMLEncode{|*|} a
toXMLString :: !a -> String | XMLEncode{|*|} a
:: XMLEncodeResult
generic XMLEncode a :: !a -> XMLEncodeResult
// special types for adding attributes to XML data
:: XMLIntAttribute a = XMLIntAttribute !XMLQName !Int !a
:: XMLCharAttribute a = XMLCharAttribute !XMLQName !Char !a
:: XMLRealAttribute a = XMLRealAttribute !XMLQName !Real !a
:: XMLStringAttribute a = XMLStringAttribute !XMLQName !String !a
:: XMLBoolAttribute a = XMLBoolAttribute !XMLQName !Bool !a
derive XMLEncode OBJECT, CONS of d, FIELD of d, PAIR, EITHER, UNIT, Int, Char, Real, String, Bool
derive XMLEncode Maybe, Either, (,), (,,), (,,,), []
derive XMLEncode XMLIntAttribute, XMLCharAttribute, XMLRealAttribute, XMLStringAttribute, XMLBoolAttribute
definition module Text.GenXML
/**
* This module provides data types for easy construction of XML documents and
* a generic printer/parser.
*/
import StdOverloaded, StdGeneric, Data.Either
from Data.Maybe import :: Maybe
from Data.Error import :: MaybeErrorString, :: MaybeError
:: XMLDoc = XMLDoc !(Maybe XMLURI) ![(!XMLNamespacePrefix,!XMLURI)] !XMLNode
:: XMLNode = XMLElem !XMLQName ![XMLAttr] ![XMLNode]
| XMLText !String
:: XMLAttr = XMLAttr !XMLQName !String
:: XMLQName = XMLQName !(Maybe XMLNamespacePrefix) !XMLName
:: XMLNamespacePrefix :== String
:: XMLURI :== String
:: XMLName :== String
/**
* Create an XMLQName containing an unqualified name from a String
* @param Unqualified name
* @return XMLQName containing the unqualified name
*/
uname :: !String -> XMLQName
/**
* Create an XMLQName containing a qualified name from a String
* @param Qualified name
* @return XMLQName containing the qualified name
*/
qname :: !XMLNamespacePrefix !String -> XMLQName
instance toString XMLDoc
instance fromString (MaybeErrorString XMLDoc)
// generic printer
toXML :: !a -> XMLDoc | XMLEncode{|*|} a
toXMLString :: !a -> String | XMLEncode{|*|} a
:: XMLEncodeResult
generic XMLEncode a :: !a -> XMLEncodeResult
// special types for adding attributes to XML data
:: XMLIntAttribute a = XMLIntAttribute !XMLQName !Int !a
:: XMLCharAttribute a = XMLCharAttribute !XMLQName !Char !a
:: XMLRealAttribute a = XMLRealAttribute !XMLQName !Real !a
:: XMLStringAttribute a = XMLStringAttribute !XMLQName !String !a
:: XMLBoolAttribute a = XMLBoolAttribute !XMLQName !Bool !a
derive XMLEncode OBJECT, CONS of d, FIELD of d, PAIR, EITHER, UNIT, Int, Char, Real, String, Bool
derive XMLEncode Maybe, Either, (,), (,,), (,,,), []
derive XMLEncode XMLIntAttribute, XMLCharAttribute, XMLRealAttribute, XMLStringAttribute, XMLBoolAttribute
......@@ -427,6 +427,4 @@ instance html HtmlTag
instance html [a] | html a
instance html (Maybe a) | html a
browserFriendlySVGEltToString :: !SVGElt -> String
escapeStr :: !String -> String
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment