-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | dot language parsing and printing. -- -- This package provides parsing and printing of the dot language. -- --
-- >>> :set -XOverloadedLabels -- -- >>> :set -XOverloadedStrings -- -- >>> import DotParse -- -- >>> import Chart -- -- >>> import DotParse.Examples (exInt) -- -- >>> ex <- processGraph exInt -- -- >>> writeChartSvg "other/ex.svg" (graphToChartWith defaultChartConfig ex) ---- @package dotparse @version 0.0.1 -- | TH stage restriction guff for flatparsing module DotParse.FlatParse.TH -- | Consume whitespace. ws :: Parser e () -- | Consume whitespace after running a parser. token :: Parser e a -> Parser e a -- | Parse a line comment. lineComment :: Parser e () -- | Parse a potentially nested multiline comment. multilineComment :: Parser e () -- | Parse a HTML-Like string by counting the angle brackets htmlLike :: Parser e String -- | First character of a dot identifier. isValidStartChar :: Char -> Bool -- | character of a dot identifier. isValidChar :: Char -> Bool -- | Read a starting character of an identifier. identStartChar :: Parser e Char -- | Read a non-starting character of an identifier. identChar :: Parser e Char -- | Parse a non-keyword string. symbol :: String -> Q Exp -- | Parse a keyword string. keyword :: String -> Q Exp -- | Parser a non-keyword string, throw precise error on failure. symbol' :: String -> Q Exp -- | Parse a keyword string, throw precise error on failure. keyword' :: String -> Q Exp -- | Parse an identifier. ident :: Parser e ByteString -- | Parse an identifier, throw a precise error on failure. ident' :: Parser Error ByteString -- | A parsing error. data Error -- | A precisely known error, like leaving out "in" from "let". Precise :: Pos -> ByteString -> Error -- | An imprecise error, when we expect a number of different things, but -- parse something else. Imprecise :: Pos -> [ByteString] -> Error -- | position of error errorPos :: Error -> Pos -- | Merge two errors. Inner errors (which were thrown at points with more -- consumed inputs) are preferred. If errors are thrown at identical -- input positions, we prefer precise errors to imprecise ones. -- -- The point of prioritizing inner and precise errors is to suppress the -- deluge of "expected" items, and instead try to point to a concrete -- issue to fix. merge :: Error -> Error -> Error -- | Pretty print an error. The ByteString input is the source file. -- The offending line from the source is displayed in the output. prettyError :: ByteString -> Error -> ByteString -- | Imprecise cut: we slap a list of items on inner errors. cut :: Parser Error a -> [ByteString] -> Parser Error a -- | Precise cut: we propagate at most a single error. cut' :: Parser Error a -> ByteString -> Parser Error a instance GHC.Show.Show DotParse.FlatParse.TH.Error instance GHC.Classes.Eq DotParse.FlatParse.TH.Error -- | Lower-level flatparse parsers module DotParse.FlatParse -- | A parsing error. data Error -- | A precisely known error, like leaving out "in" from "let". Precise :: Pos -> ByteString -> Error -- | An imprecise error, when we expect a number of different things, but -- parse something else. Imprecise :: Pos -> [ByteString] -> Error -- | Pretty print an error. The ByteString input is the source file. -- The offending line from the source is displayed in the output. prettyError :: ByteString -> Error -> ByteString -- | Parse a keyword string. keyword :: String -> Q Exp -- | Parse a keyword string, throw precise error on failure. keyword' :: String -> Q Exp -- | Parse a non-keyword string. symbol :: String -> Q Exp -- | Parser a non-keyword string, throw precise error on failure. symbol' :: String -> Q Exp -- | Consume whitespace. ws :: Parser e () -- | Consume whitespace after running a parser. token :: Parser e a -> Parser e a -- | Parse an identifier. ident :: Parser e ByteString -- | Imprecise cut: we slap a list of items on inner errors. cut :: Parser Error a -> [ByteString] -> Parser Error a -- | Precise cut: we propagate at most a single error. cut' :: Parser Error a -> ByteString -> Parser Error a -- | Run parser, print pretty error on failure. testParser :: Show a => Parser Error a -> ByteString -> IO () -- | run a Parser, erroring on leftovers, Fail or Err runParser_ :: Parser Error a -> ByteString -> a -- | (unsigned) Int parser int :: Parser Error Int -- |
-- >>> runParser double "1.234x" -- OK 1.234 "x" ---- --
-- >>> runParser double "." -- Fail ---- --
-- >>> runParser double "123" -- OK 123.0 "" ---- --
-- >>> runParser double ".123" -- OK 0.123 "" ---- --
-- >>> runParser double "123." -- OK 123.0 "" --double :: Parser Error Double -- |
-- >>> runParser (signed double) "-1.234x" -- OK (-1.234) "x" --signed :: Num b => Parser e b -> Parser e b -- | Looks ahead for a "/"" that may be in the quoted string. >>> -- runParser quoted (packUTF8 ""hello"") OK "hello" "" -- --
-- >>> runParser quoted (packUTF8 "\"hello/\"\"") -- OK "hello\"" "" --quoted :: Parser Error String -- | Parse a HTML-Like string by counting the angle brackets htmlLike :: Parser e String -- | optional separators sepP :: Parser e () -- | parse wrapping square brackets wrapSquareP :: Parser Error a -> Parser Error a -- | print wrapping square brackets wrapSquarePrint :: ByteString -> ByteString -- | parse wrapping square brackets wrapCurlyP :: Parser Error a -> Parser Error a -- | print wrapping curly brackets wrapCurlyPrint :: ByteString -> ByteString -- | print wrapping quotes wrapQuotePrint :: ByteString -> ByteString -- | comma separated Point pointP :: Parser Error (Point Double) -- | dot specification of a cubic spline (and an arrow head which is -- ignored here) data Spline Spline :: Maybe (Point Double) -> Maybe (Point Double) -> Point Double -> [(Point Double, Point Double, Point Double)] -> Spline [splineEnd] :: Spline -> Maybe (Point Double) [splineStart] :: Spline -> Maybe (Point Double) [splineP1] :: Spline -> Point Double [splineTriples] :: Spline -> [(Point Double, Point Double, Point Double)] -- | http://www.graphviz.org/docs/attr-types/splineType/ splineP :: Parser Error Spline -- | comma separated rectangle or bounding box rectP :: Parser Error (Rect Double) -- | true | false boolP :: Parser Error Bool -- | NonEmpty version of many nonEmptyP :: Parser e a -> Parser e () -> Parser e (NonEmpty a) instance GHC.Generics.Generic DotParse.FlatParse.Spline instance GHC.Show.Show DotParse.FlatParse.Spline instance GHC.Classes.Eq DotParse.FlatParse.Spline -- | Abstract Grammar for the dot language. -- http://www.graphviz.org/doc/info/lang.html module DotParse.Types -- | printing options, for separators. data DotConfig DotConfig :: ByteString -> ByteString -> ByteString -> ByteString -> DotConfig [topLevelSep] :: DotConfig -> ByteString [statementSep] :: DotConfig -> ByteString [attSep] :: DotConfig -> ByteString [subGraphSep] :: DotConfig -> ByteString -- | default separators defaultDotConfig :: DotConfig -- | A parser & printer class for a graphviz graph and components of -- its dot language class DotParse a dotPrint :: DotParse a => DotConfig -> a -> ByteString dotParse :: DotParse a => Parser Error a -- | dotParse and then dotPrint: -- --
-- >>> import qualified Data.ByteString.Char8 as B
--
-- >>> B.putStrLn $ dotPrint defaultDotConfig defaultGraph
-- digraph {
-- node [height=0.5;shape=circle]
-- graph [overlap=false;size="1!";splines=spline]
-- edge [arrowsize=0]
-- }
--
defaultGraph :: Graph
-- | run a dot string through graphviz, supplying arguments and collecting
-- stdout
processDotWith :: Directed -> [String] -> ByteString -> IO ByteString
-- | run a dot string through graphviz, collecting the augmented dot string
-- output
processDot :: Directed -> ByteString -> IO ByteString
-- | Augment a Graph via the graphviz process
processGraph :: Graph -> IO Graph
-- | Augment a Graph via the graphviz process
processGraphWith :: DotConfig -> Graph -> IO Graph
-- | MergeEdges (strict)
data Strict
MergeEdges :: Strict
NoMergeEdges :: Strict
-- | Default Strict is NoMergeEdges
defStrict :: Last Strict -> Strict
-- | Directed (digraph | graph)
data Directed
Directed :: Directed
UnDirected :: Directed
-- | Default Directed is Directed
defDirected :: Last Directed -> Directed
-- | Identifier as per the dot language specifications.
--
-- -- >>> runDotParser "0" :: ID -- IDInt 0 ---- --
-- >>> runDotParser "-.123" :: ID -- IDDouble (-0.123) ---- --
-- >>> runParser dotParse "apple_1'" :: Result Error ID -- OK (ID "apple_1") "'" ---- --
-- >>> :set -XQuasiQuotes -- -- >>> runParser dotParse "\"hello\"" :: Result Error ID -- OK (IDQuoted "hello") "" ---- --
-- >>> runDotParser "<The <font color='red'><b>foo</b></font>,<br/> the <font point-size='20'>bar</font> and<br/> the <i>baz</i>>" :: ID -- IDHtml "<The <font color='red'><b>foo</b></font>,<br/> the <font point-size='20'>bar</font> and<br/> the <i>baz</i>>" --data ID ID :: ByteString -> ID IDInt :: Int -> ID IDDouble :: Double -> ID IDQuoted :: ByteString -> ID IDHtml :: ByteString -> ID -- | ID as the equivalent plain String -- -- note that the dot language identifier equivalence law is: -- --
-- x == y if label x == label y --label :: ID -> String -- | Compass instructions which are optionally associated with an -- identifier data Compass CompassN :: Compass CompassNE :: Compass CompassE :: Compass CompassSE :: Compass CompassS :: Compass CompassSW :: Compass CompassW :: Compass CompassNW :: Compass CompassC :: Compass Compass_ :: Compass -- | Port instructions which are optionally associated with an identifier newtype Port Port :: These ID Compass -> Port [portID] :: Port -> These ID Compass -- | Category of attribute data AttributeType GraphType :: AttributeType NodeType :: AttributeType EdgeType :: AttributeType -- | Top-level attribute statement -- --
-- >>> runDotParser "graph [overlap=false, splines=spline, size=\"1!\"];" :: Statement
-- StatementAttribute (AttributeStatement {attributeType = GraphType, attributes = fromList [(ID "overlap",ID "false"),(ID "size",IDQuoted "1!"),(ID "splines",ID "spline")]})
--
data AttributeStatement
AttributeStatement :: AttributeType -> Map ID ID -> AttributeStatement
[attributeType] :: AttributeStatement -> AttributeType
[attributes] :: AttributeStatement -> Map ID ID
-- | Node statement
--
--
-- >>> runDotParser "A [shape=diamond; color=blue]" :: Statement
-- StatementNode (NodeStatement {nodeID = ID "A", port = Nothing, nodeAttrs = fromList [(ID "color",ID "blue"),(ID "shape",ID "diamond")]})
--
data NodeStatement
NodeStatement :: ID -> Maybe Port -> Map ID ID -> NodeStatement
[nodeID] :: NodeStatement -> ID
[port] :: NodeStatement -> Maybe Port
[nodeAttrs] :: NodeStatement -> Map ID ID
-- | An edge can be specified in as a NodeID or as a SubGraph
data EdgeID
EdgeID :: ID -> Maybe Port -> EdgeID
EdgeSubGraph :: SubGraphStatement -> EdgeID
-- | An edgeop is -> in directed graphs and -- in undirected graphs.
data EdgeOp
EdgeDirected :: EdgeOp
EdgeUndirected :: EdgeOp
-- | generate an EdgeOp given the type of graph.
fromDirected :: Directed -> EdgeOp
-- | Edge statement
--
--
-- >>> runDotParser "A -> B [style=dashed, color=grey]" :: Statement
-- StatementEdge (EdgeStatement {edgeOp = EdgeDirected, leftEdge = EdgeID (ID "A") Nothing, rightEdges = EdgeID (ID "B") Nothing :| [], edgeAttrs = fromList [(ID "color",ID "grey"),(ID "style",ID "dashed")]})
--
data EdgeStatement
EdgeStatement :: EdgeOp -> EdgeID -> NonEmpty EdgeID -> Map ID ID -> EdgeStatement
[edgeOp] :: EdgeStatement -> EdgeOp
[leftEdge] :: EdgeStatement -> EdgeID
[rightEdges] :: EdgeStatement -> NonEmpty EdgeID
[edgeAttrs] :: EdgeStatement -> Map ID ID
-- | The edge ID or subgraph ID (if any)
edgeID :: EdgeID -> Maybe ID
-- | list of edges in a given EdgeStatement, including anonymous SugGraphs
edgeIDs :: EdgeStatement -> [(Maybe ID, Maybe ID)]
-- | edge IDs
edgeIDsNamed :: EdgeStatement -> [(ID, ID)]
-- | A dot statement as per the dot language specification.
data Statement
StatementNode :: NodeStatement -> Statement
StatementEdge :: EdgeStatement -> Statement
StatementGlobalAttribute :: GlobalAttributeStatement -> Statement
StatementAttribute :: AttributeStatement -> Statement
StatementSubGraph :: SubGraphStatement -> Statement
-- | add a graphviz statement to a Graph
addStatement :: Statement -> Graph -> Graph
-- | add a list of graphviz statements to a Graph
addStatements :: [Statement] -> Graph -> Graph
-- | A subgraph statement.
--
-- Note: each subgraph must have a unique name
--
--
-- >>> runDotParser "subgraph A {A, B, C}" :: Statement
-- StatementSubGraph (SubGraphStatement {subgraphID = Just (ID "A"), subgraphStatements = [StatementNode (NodeStatement {nodeID = ID "A", port = Nothing, nodeAttrs = fromList []}),StatementNode (NodeStatement {nodeID = ID "B", port = Nothing, nodeAttrs = fromList []}),StatementNode (NodeStatement {nodeID = ID "C", port = Nothing, nodeAttrs = fromList []})]})
--
data SubGraphStatement
SubGraphStatement :: Maybe ID -> [Statement] -> SubGraphStatement
[subgraphID] :: SubGraphStatement -> Maybe ID
[subgraphStatements] :: SubGraphStatement -> [Statement]
-- | Bounding Box lens as a Rect
bbL :: Lens' Graph (Maybe (Rect Double))
-- | nodes lens
nodesPortL :: Lens' Graph (Map ID (Maybe Port, Map ID ID))
-- | nodes lens ignoring/forgetting port information
nodesL :: Lens' Graph (Map ID (Map ID ID))
-- | edges lens ignoring/forgetting port information
edgesL :: Lens' Graph (Map (ID, ID) (Map ID ID))
-- | A specific attribute for all nodes in a graph
nodesA :: ID -> Graph -> Map ID (Maybe ID)
-- | Specific attribute for all edges
edgesA :: Graph -> ID -> Map (ID, ID) (Maybe ID)
-- | node position (as a Point)
nodePos :: Graph -> Map ID (Maybe (Point Double))
-- | node width attributes
nodeWidth :: Graph -> Map ID (Maybe Double)
-- | edge path attributes
edgeSpline :: Graph -> Map (ID, ID) (Maybe Spline)
-- | edge width attributes
edgeWidth :: Graph -> Map (ID, ID) (Maybe Double)
-- | typical node information after processing a dot bytestring.
data NodeInfo
NodeInfo :: ID -> Double -> Point Double -> NodeInfo
[nlabel] :: NodeInfo -> ID
[nwidth] :: NodeInfo -> Double
[pos] :: NodeInfo -> Point Double
-- | Create a list of NodeInfo from a graph.
nodeInfo :: Graph -> Double -> [NodeInfo]
-- | typical edge information after processing a dot bytestring.
data EdgeInfo
EdgeInfo :: (ID, ID) -> Double -> [PathData Double] -> EdgeInfo
[elabel] :: EdgeInfo -> (ID, ID)
[ewidth] :: EdgeInfo -> Double
[curve] :: EdgeInfo -> [PathData Double]
-- | Create a list of EdgeInfo from a graph
edgeInfo :: Graph -> Double -> [EdgeInfo]
-- | https://graphviz.org/docs/attr-types/splineType/ format of the
-- example is end point point and then triples (5,8,11 lengths are 1, 2
-- and 3 cubics)
splinePath :: Spline -> [PathData Double]
-- | convert a Graph processed via the graphviz commands to a
-- ChartSvg
--
-- -- >>> import Chart -- -- >>> import DotParse.Examples (exInt) -- -- >>> ex <- processGraph exInt -- -- >>> writeChartSvg "other/ex.svg" (graphToChartWith defaultChartConfig ex) ---- graphToChartWith :: ChartConfig -> Graph -> ChartSvg -- | convert a Graph processed via the graphviz commands to a -- ChartSvg using the default ChartConfig. graphToChart :: Graph -> ChartSvg -- | Various configutaion parameters for the chart-svg Chart data ChartConfig ChartConfig :: Double -> Double -> Double -> Colour -> Colour -> Double -> Double -> Double -> Double -> (ID -> Text) -> ChartConfig [chartHeight] :: ChartConfig -> Double [chartScale] :: ChartConfig -> Double [edgeSize] :: ChartConfig -> Double [chartColor] :: ChartConfig -> Colour [chartBackgroundColor] :: ChartConfig -> Colour [nodeHeight] :: ChartConfig -> Double [nodeSize] :: ChartConfig -> Double [vshift] :: ChartConfig -> Double [textSize] :: ChartConfig -> Double [labelf] :: ChartConfig -> ID -> Text -- | default parameters defaultChartConfig :: ChartConfig -- | create Statements from a (no edge label) algebraic graph toStatements :: Directed -> Graph ByteString -> [Statement] -- | Convert an algebraic graph to a dotparse graph, starting with the -- defaultGraph. toDotGraph :: Graph ByteString -> Graph -- | Convert an algebraic graph to a dotparse graph. toDotGraphWith :: Directed -> Graph -> Graph ByteString -> Graph instance GHC.Generics.Generic DotParse.Types.DotConfig instance GHC.Show.Show DotParse.Types.DotConfig instance GHC.Classes.Eq DotParse.Types.DotConfig instance GHC.Generics.Generic DotParse.Types.Strict instance GHC.Show.Show DotParse.Types.Strict instance GHC.Classes.Eq DotParse.Types.Strict instance GHC.Generics.Generic DotParse.Types.Directed instance GHC.Show.Show DotParse.Types.Directed instance GHC.Classes.Eq DotParse.Types.Directed instance GHC.Classes.Ord DotParse.Types.ID instance GHC.Generics.Generic DotParse.Types.ID instance GHC.Show.Show DotParse.Types.ID instance GHC.Classes.Eq DotParse.Types.ID instance GHC.Generics.Generic DotParse.Types.Compass instance GHC.Show.Show DotParse.Types.Compass instance GHC.Classes.Eq DotParse.Types.Compass instance GHC.Generics.Generic DotParse.Types.Port instance GHC.Show.Show DotParse.Types.Port instance GHC.Classes.Eq DotParse.Types.Port instance GHC.Generics.Generic DotParse.Types.GlobalAttributeStatement instance GHC.Show.Show DotParse.Types.GlobalAttributeStatement instance GHC.Classes.Eq DotParse.Types.GlobalAttributeStatement instance GHC.Generics.Generic DotParse.Types.AttributeType instance GHC.Show.Show DotParse.Types.AttributeType instance GHC.Classes.Eq DotParse.Types.AttributeType instance GHC.Generics.Generic DotParse.Types.AttributeStatement instance GHC.Show.Show DotParse.Types.AttributeStatement instance GHC.Classes.Eq DotParse.Types.AttributeStatement instance GHC.Generics.Generic DotParse.Types.NodeStatement instance GHC.Show.Show DotParse.Types.NodeStatement instance GHC.Classes.Eq DotParse.Types.NodeStatement instance GHC.Generics.Generic DotParse.Types.EdgeOp instance GHC.Show.Show DotParse.Types.EdgeOp instance GHC.Classes.Eq DotParse.Types.EdgeOp instance GHC.Generics.Generic DotParse.Types.EdgeID instance GHC.Show.Show DotParse.Types.EdgeID instance GHC.Classes.Eq DotParse.Types.EdgeID instance GHC.Generics.Generic DotParse.Types.EdgeStatement instance GHC.Show.Show DotParse.Types.EdgeStatement instance GHC.Classes.Eq DotParse.Types.EdgeStatement instance GHC.Generics.Generic DotParse.Types.Statement instance GHC.Show.Show DotParse.Types.Statement instance GHC.Classes.Eq DotParse.Types.Statement instance GHC.Generics.Generic DotParse.Types.SubGraphStatement instance GHC.Show.Show DotParse.Types.SubGraphStatement instance GHC.Classes.Eq DotParse.Types.SubGraphStatement instance GHC.Generics.Generic DotParse.Types.Graph instance GHC.Show.Show DotParse.Types.Graph instance GHC.Classes.Eq DotParse.Types.Graph instance GHC.Generics.Generic DotParse.Types.NodeInfo instance GHC.Show.Show DotParse.Types.NodeInfo instance GHC.Classes.Eq DotParse.Types.NodeInfo instance GHC.Generics.Generic DotParse.Types.EdgeInfo instance GHC.Show.Show DotParse.Types.EdgeInfo instance GHC.Classes.Eq DotParse.Types.EdgeInfo instance GHC.Generics.Generic DotParse.Types.ChartConfig instance GHC.Base.Semigroup DotParse.Types.Graph instance GHC.Base.Monoid DotParse.Types.Graph instance DotParse.Types.DotParse DotParse.Types.Graph instance DotParse.Types.DotParse DotParse.Types.Statement instance DotParse.Types.DotParse DotParse.Types.EdgeID instance DotParse.Types.DotParse DotParse.Types.EdgeStatement instance DotParse.Types.DotParse DotParse.Types.SubGraphStatement instance DotParse.Types.DotParse DotParse.Types.EdgeOp instance DotParse.Types.DotParse DotParse.Types.NodeStatement instance DotParse.Types.DotParse DotParse.Types.AttributeStatement instance DotParse.Types.DotParse DotParse.Types.AttributeType instance DotParse.Types.DotParse DotParse.Types.GlobalAttributeStatement instance DotParse.Types.DotParse DotParse.Types.Port instance DotParse.Types.DotParse DotParse.Types.Compass instance DotParse.Types.DotParse DotParse.Types.ID instance DotParse.Types.DotParse (DotParse.Types.ID, DotParse.Types.ID) instance DotParse.Types.DotParse (Data.Map.Internal.Map DotParse.Types.ID DotParse.Types.ID) instance DotParse.Types.DotParse DotParse.Types.Directed instance DotParse.Types.DotParse DotParse.Types.Strict instance DotParse.Types.DotParse (NumHask.Space.Point.Point GHC.Types.Double) instance DotParse.Types.DotParse (NumHask.Space.Rect.Rect GHC.Types.Double) -- | Parser & Printer for the dot language of graphviz -- -- See DotParse.Examples for usage. module DotParse -- | Parse any Int64 (big-endian). anyInt64be :: Parser e Int64 -- | Parse any Int64 (little-endian). anyInt64le :: Parser e Int64 -- | Parse any Int32 (big-endian). anyInt32be :: Parser e Int32 -- | Parse any Int32 (little-endian). anyInt32le :: Parser e Int32 -- | Parse any Int16 (big-endian). anyInt16be :: Parser e Int16 -- | Parse any Int16 (little-endian). anyInt16le :: Parser e Int16 -- | Parse any Word64 (big-endian). anyWord64be :: Parser e Word64 -- | Parse any Word64 (little-endian). anyWord64le :: Parser e Word64 -- | Parse any Word32 (big-endian). anyWord32be :: Parser e Word32 -- | Parse any Word32 (little-endian). anyWord32le :: Parser e Word32 -- | Parse any Word16 (big-endian). anyWord16be :: Parser e Word16 -- | Parse any Word16 (little-endian). anyWord16le :: Parser e Word16 -- | Parse any Int. anyInt :: Parser e Int -- | Parse any Int64. anyInt64 :: Parser e Int64 -- | Parse any Int32. anyInt32 :: Parser e Int32 -- | Parse any Int16. anyInt16 :: Parser e Int16 -- | Parse any Int8. anyInt8 :: Parser e Int8 -- | Skip any Word. anyWord_ :: Parser e () -- | Parse any Word. anyWord :: Parser e Word -- | Skip any Word64. anyWord64_ :: Parser e () -- | Parse any Word64. anyWord64 :: Parser e Word64 -- | Skip any Word32. anyWord32_ :: Parser e () -- | Parse any Word32. anyWord32 :: Parser e Word32 -- | Skip any Word16. anyWord16_ :: Parser e () -- | Parse any Word16. anyWord16 :: Parser e Word16 -- | Skip any Word8 (byte). anyWord8_ :: Parser e () -- | Parse any Word8 (byte). anyWord8 :: Parser e Word8 -- | Template function, creates a Parser e () which unsafely scans -- a given sequence of bytes. scanBytes# :: [Word] -> Q Exp -- | Decrease the current input position by the given number of bytes. setBack# :: Int -> Parser e () -- | Unsafely read and return a byte from the input. It's not checked that -- the input is non-empty. scanAny8# :: Parser e Word8 -- | Unsafely read eight concrete bytes from the input. It's not checked -- that the input has enough bytes. scan64# :: Word -> Parser e () -- | Unsafely read four concrete bytes from the input. It's not checked -- that the input has enough bytes. scan32# :: Word32 -> Parser e () -- | Unsafely read two concrete bytes from the input. It's not checked that -- the input has enough bytes. scan16# :: Word16 -> Parser e () -- | Unsafely read a concrete byte from the input. It's not checked that -- the input has enough bytes. scan8# :: Word8 -> Parser e () -- | Check that the input has at least the given number of bytes. ensureBytes# :: Int -> Parser e () -- | Convert an UTF-8-coded ByteString to a String. unpackUTF8 :: ByteString -> String -- | Get the rest of the input as a String, but restore the parsing -- state. Assumes UTF-8 encoding. This can be used for debugging. traceRest :: Parser e String -- | Take the rest of the input as a String. Assumes UTF-8 encoding. takeRest :: Parser e String -- | Parse the rest of the current line as a String, but restore the -- parsing state. Assumes UTF-8 encoding. This can be used for debugging. traceLine :: Parser e String -- | Parse the rest of the current line as a String. Assumes UTF-8 -- encoding, throws an error if the encoding is invalid. takeLine :: Parser e String -- | Create a Pos from a line and column number. Throws an error on -- out-of-bounds line and column numbers. mkPos :: ByteString -> (Int, Int) -> Pos -- | Create a ByteString from a Span. The result is invalid -- if the Span points outside the current buffer, or if the -- Span start is greater than the end position. unsafeSpanToByteString :: Span -> Parser e ByteString -- | Compute corresponding line and column numbers for each Pos in a -- list. Throw an error on invalid positions. Note: computing lines and -- columns may traverse the ByteString, but it traverses it only -- once regardless of the length of the position list. posLineCols :: ByteString -> [Pos] -> [(Int, Int)] -- | Check whether a Pos points into a ByteString. validPos :: ByteString -> Pos -> Bool -- | Run a parser in a given input span. The input position and the -- Int state is restored after the parser is finished, so -- inSpan does not consume input and has no side effect. Warning: -- this operation may crash if the given span points outside the current -- parsing buffer. It's always safe to use inSpan if the span -- comes from a previous spanned or spanOf call on the -- current input. inSpan :: Span -> Parser e a -> Parser e a -- | CPS'd version of byteStringOf. Can be more efficient, because -- the result is more eagerly unboxed by GHC. It's more efficient to use -- spanOf or spanned instead. byteStringed :: Parser e a -> (a -> ByteString -> Parser e b) -> Parser e b -- | Return the ByteString consumed by a parser. Note: it's more -- efficient to use spanOf and spanned instead. byteStringOf :: Parser e a -> Parser e ByteString -- | Bind the result together with the span of the result. CPS'd version of -- spanOf for better unboxing. spanned :: Parser e a -> (a -> Span -> Parser e b) -> Parser e b -- | Return the consumed span of a parser. spanOf :: Parser e a -> Parser e Span -- | The end of the input. endPos :: Pos -- | Set the input position. Warning: this can result in crashes if the -- position points outside the current buffer. It is always safe to -- setPos values which came from getPos with the current -- input. setPos :: Pos -> Parser e () -- | Get the current position in the input. getPos :: Parser e Pos -- | Succeed if the first parser succeeds and the second one fails. notFollowedBy :: Parser e a -> Parser e b -> Parser e a -- | Skip a parser one or more times. some_ :: Parser e a -> Parser e () -- | Run a parser one or more times, collect the results in a list. Note: -- for optimal performance, try to avoid this. Often it is possible to -- get rid of the intermediate list by using a combinator or a custom -- parser. some :: Parser e a -> Parser e [a] -- | Skip a parser zero or more times. many_ :: Parser e a -> Parser e () -- | Run a parser zero or more times, collect the results in a list. Note: -- for optimal performance, try to avoid this. Often it is possible to -- get rid of the intermediate list by using a combinator or a custom -- parser. many :: Parser e a -> Parser e [a] -- | An analogue of the list foldr function: parse zero or more -- a-s, terminated by a b, and combine the results in a -- right-nested way using the a -> b -> b function. Note: -- this is not the usual chainr function from the parsec -- libraries! chainr :: (a -> b -> b) -> Parser e a -> Parser e b -> Parser e b -- | An analogue of the list foldl function: first parse a -- b, then parse zero or more a-s, and combine the -- results in a left-nested way by the b -> a -> b -- function. Note: this is not the usual chainl function from the -- parsec libraries! chainl :: (b -> a -> b) -> Parser e b -> Parser e a -> Parser e b -- | Branch on a parser: if the first argument succeeds, continue with the -- second, else with the third. This can produce slightly more efficient -- code than (<|>). Moreover, ḃranch does not -- backtrack from the true/false cases. branch :: Parser e a -> Parser e b -> Parser e b -> Parser e b -- | Choose between two parsers. If the first parser fails, try the second -- one, but if the first one throws an error, propagate the error. (<|>) :: Parser e a -> Parser e a -> Parser e a infixr 6 <|> -- | Read an Integer from the input, as a non-empty digit sequence. readInteger :: Parser e Integer -- | Read an Int from the input, as a non-empty digit sequence. The -- Int may overflow in the result. readInt :: Parser e Int -- | Skip any Char in the ASCII range. More efficient than -- anyChar_ if we're working only with ASCII. anyCharASCII_ :: Parser e () -- | Parse any Char in the ASCII range, fail if the next input -- character is not in the range. This is more efficient than -- anyChar if we are only working with ASCII. anyCharASCII :: Parser e Char -- | Skip any UTF-8-encoded Char. anyChar_ :: Parser e () -- | Parse any UTF-8-encoded Char. anyChar :: Parser e Char -- | Skipping variant of fusedSatisfy. fusedSatisfy_ :: (Char -> Bool) -> (Char -> Bool) -> (Char -> Bool) -> (Char -> Bool) -> Parser e () -- | This is a variant of satisfy which allows more optimization. We -- can pick four testing functions for the four cases for the possible -- number of bytes in the UTF-8 character. So in fusedSatisfy f1 f2 -- f3 f4, if we read a one-byte character, the result is scrutinized -- with f1, for two-bytes, with f2, and so on. This can -- result in dramatic lexing speedups. -- -- For example, if we want to accept any letter, the naive solution would -- be to use isLetter, but this accesses a large lookup table of -- Unicode character classes. We can do better with fusedSatisfy -- isLatinLetter isLetter isLetter isLetter, since here the -- isLatinLetter is inlined into the UTF-8 decoding, and it -- probably handles a great majority of all cases without accessing the -- character table. fusedSatisfy :: (Char -> Bool) -> (Char -> Bool) -> (Char -> Bool) -> (Char -> Bool) -> Parser e Char -- | Skip an ASCII Char for which a predicate holds. Assumption: the -- predicate must only return True for ASCII-range characters. satisfyASCII_ :: (Char -> Bool) -> Parser e () -- | Parse an ASCII Char for which a predicate holds. Assumption: -- the predicate must only return True for ASCII-range characters. -- Otherwise this function might read a 128-255 range byte, thereby -- breaking UTF-8 decoding. satisfyASCII :: (Char -> Bool) -> Parser e Char -- | Skip a UTF-8 Char for which a predicate holds. satisfy_ :: (Char -> Bool) -> Parser e () -- | Parse a UTF-8 Char for which a predicate holds. satisfy :: (Char -> Bool) -> Parser e Char -- | Version of switchWithPost without syntactic sugar. The second -- argument is the list of cases, the third is the default case. rawSwitchWithPost :: Maybe (Q Exp) -> [(String, Q Exp)] -> Maybe (Q Exp) -> Q Exp -- | Switch expression with an optional first argument for performing a -- post-processing action after every successful branch matching. For -- example, if we have ws :: Parser e () for a whitespace -- parser, we might want to consume whitespace after matching on any of -- the switch cases. For that case, we can define a "lexeme" version of -- switch as follows. -- --
-- switch' :: Q Exp -> Q Exp -- switch' = switchWithPost (Just [| ws |]) ---- -- Note that this switch' function cannot be used in the same -- module it's defined in, because of the stage restriction of Template -- Haskell. switchWithPost :: Maybe (Q Exp) -> Q Exp -> Q Exp -- | This is a template function which makes it possible to branch on a -- collection of string literals in an efficient way. By using -- switch, such branching is compiled to a trie of primitive -- parsing operations, which has optimized control flow, vectorized reads -- and grouped checking for needed input bytes. -- -- The syntax is slightly magical, it overloads the usual case -- expression. An example: -- --
-- $(switch [| case _ of -- "foo" -> pure True -- "bar" -> pure False |]) ---- -- The underscore is mandatory in case _ of. Each branch must be -- a string literal, but optionally we may have a default case, like in -- --
-- $(switch [| case _ of -- "foo" -> pure 10 -- "bar" -> pure 20 -- _ -> pure 30 |]) ---- -- All case right hand sides must be parsers with the same type. That -- type is also the type of the whole switch expression. -- -- A switch has longest match semantics, and the order of cases -- does not matter, except for the default case, which may only appear as -- the last case. -- -- If a switch does not have a default case, and no case matches -- the input, then it returns with failure, without having consumed any -- input. A fallthrough to the default case also does not consume any -- input. switch :: Q Exp -> Q Exp -- | Parse a UTF-8 string literal. This is a template function, you can use -- it as $(string "foo"), for example, and the splice has type -- Parser e (). string :: String -> Q Exp -- | Read a sequence of bytes. This is a template function, you can use it -- as $(bytes [3, 4, 5]), for example, and the splice has type -- Parser e (). bytes :: [Word] -> Q Exp -- | Read a Word8. byte :: Word8 -> Parser e () -- | Parse a UTF-8 character literal. This is a template function, you can -- use it as $(char 'x'), for example, and the splice in this -- case has type Parser e (). char :: Char -> Q Exp -- | Succeed if the input is empty. eof :: Parser e () -- | Run the parser, if we get a failure, throw the given error, but if we -- get an error, merge the inner and the newly given errors using the -- e -> e -> e function. This can be useful for -- implementing parsing errors which may propagate hints or accummulate -- contextual information. cutting :: Parser e a -> e -> (e -> e -> e) -> Parser e a -- | CPS'd version of optional. This is usually more efficient, -- since it gets rid of the extra Maybe allocation. optioned :: Parser e a -> (a -> Parser e b) -> Parser e b -> Parser e b -- | Convert a parsing failure to a (). optional_ :: Parser e a -> Parser e () -- | Convert a parsing failure to a Maybe. If possible, use -- optioned instead. optional :: Parser e a -> Parser e (Maybe a) -- | Convert a parsing error into failure. try :: Parser e a -> Parser e a -- | Convert a parsing failure to a success. fails :: Parser e a -> Parser e () -- | Save the parsing state, then run a parser, then restore the state. lookahead :: Parser e a -> Parser e a -- | Throw a parsing error. By default, parser choice (<|>) -- can't backtrack on parser error. Use try to convert an error to -- a recoverable failure. err :: e -> Parser e a -- | The failing parser. By default, parser choice (<|>) -- arbitrarily backtracks on parser failure. empty :: Parser e a -- | Run a parser on a String input. Reminder: -- OverloadedStrings for ByteString does not yield a -- valid UTF-8 encoding! For non-ASCII ByteString literal input, -- use runParserS or packUTF8 for testing. runParserS :: Parser e a -> String -> Result e a -- | Run a parser. runParser :: Parser e a -> ByteString -> Result e a -- | Contains return value and a pointer to the rest of the input buffer. pattern OK# :: a -> Addr# -> Res# e a -- | Constructor for errors which are by default non-recoverable. pattern Err# :: e -> Res# e a -- | Constructor for recoverable failure. pattern Fail# :: Res# e a -- | Primitive result of a parser. Possible results are given by -- OK#, Err# and Fail# pattern synonyms. type Res# e a = (# (# a, Addr# #) | (# #) | (# e #) #) -- | Parser e a has an error type e and a return type -- a. newtype Parser e a Parser :: (ForeignPtrContents -> Addr# -> Addr# -> Res# e a) -> Parser e a [runParser#] :: Parser e a -> ForeignPtrContents -> Addr# -> Addr# -> Res# e a -- | Higher-level boxed data type for parsing results. data Result e a -- | Contains return value and unconsumed input. OK :: a -> !ByteString -> Result e a -- | Recoverable-by-default failure. Fail :: Result e a -- | Unrecoverble-by-default error. Err :: !e -> Result e a -- | Convert a String to an UTF-8-coded ByteString. packUTF8 :: String -> ByteString -- | Slice into a ByteString using a Span. The result is -- invalid if the Span is not a valid slice of the first argument. unsafeSlice :: ByteString -> Span -> ByteString -- |
-- isGreekLetter c = ('Α' <= c && c <= 'Ω') || ('α' <= c && c <= 'ω')
--
isGreekLetter :: Char -> Bool
-- |
-- isLatinLetter c = ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')
--
isLatinLetter :: Char -> Bool
-- | -- isDigit c = '0' <= c && c <= '9' --isDigit :: Char -> Bool -- | Byte offset counted backwards from the end of the buffer. newtype Pos Pos :: Int -> Pos -- | A pair of positions. data Span Span :: !Pos -> !Pos -> Span -- | Example of Dot graph construction for the NumHask class heirarchy. module DotParse.Examples.NumHask data Class Magma :: Class Unital :: Class Associative :: Class Commutative :: Class Invertible :: Class Idempotent :: Class Absorbing :: Class Group :: Class AbelianGroup :: Class Additive :: Class Subtractive :: Class Multiplicative :: Class Divisive :: Class Distributive :: Class Semiring :: Class Ring :: Class IntegralDomain :: Class Field :: Class ExpField :: Class QuotientField :: Class UpperBoundedField :: Class LowerBoundedField :: Class TrigField :: Class AdditiveAction :: Class SubtractiveAction :: Class MultiplicativeAction :: Class DivisiveAction :: Class Module :: Class JoinSemiLattice :: Class MeetSemiLattice :: Class Lattice :: Class BoundedJoinSemiLattice :: Class BoundedMeetSemiLattice :: Class BoundedLattice :: Class Integral :: Class Ratio :: Class Signed :: Class Norm :: Class Basis :: Class Direction :: Class Epsilon :: Class data Family Addition :: Family Multiplication :: Family Actor :: Family data Dependency Dependency :: Class -> Class -> Maybe Family -> Dependency [_class] :: Dependency -> Class [_dep] :: Dependency -> Class [_op] :: Dependency -> Maybe Family dependencies :: [Dependency] classesNH :: [Class] classesModule :: [(Class, Text)] dependenciesNH :: [Dependency] -> [Dependency] -- | NumHask Classes as an algebraic graph graphNHG :: Graph Class -- | NumHask statements in a dot Graph with box shapes for the nodes. dotGraphNH :: Directed -> Graph -- | dotGraphNH after being positionally processed via -- processGraph dotGraphNH' :: Directed -> Graph -- | Convert a node ID to a label for chart-svg charts -- -- Doing this directly in dot doesn't quite work because the engines get -- the width of the link wrong. toLink :: ID -> Text -- | A chart-svg chart with label links -- --
-- writeChartSvg "other/nh.svg" (graphToChart toLink (dotGraphNH' Directed)) ---- writeNHChart :: IO () instance GHC.Classes.Ord DotParse.Examples.NumHask.Class instance GHC.Classes.Eq DotParse.Examples.NumHask.Class instance GHC.Show.Show DotParse.Examples.NumHask.Class instance GHC.Classes.Ord DotParse.Examples.NumHask.Family instance GHC.Classes.Eq DotParse.Examples.NumHask.Family instance GHC.Show.Show DotParse.Examples.NumHask.Family instance GHC.Classes.Ord DotParse.Examples.NumHask.Dependency instance GHC.Classes.Eq DotParse.Examples.NumHask.Dependency instance GHC.Show.Show DotParse.Examples.NumHask.Dependency -- | Examples of conversion from dot ByteStrings module DotParse.Examples -- | minimal definition -- --
-- >>> runDotParser ex0 :: Graph
-- Graph {strict = Last {getLast = Just NoMergeEdges}, directed = Last {getLast = Just UnDirected}, graphid = Last {getLast = Nothing}, nodeAttributes = fromList [], graphAttributes = fromList [], edgeAttributes = fromList [], globalAttributes = fromList [], nodes = [], edges = [], subgraphs = []}
--
--
-- -- >>> testDotParser (Proxy :: Proxy Graph) defaultDotConfig ex0 --ex0 :: ByteString -- | Examples from -- https://renenyffenegger.ch/notes/tools/Graphviz/examples/index -- --
-- >>> testDotParser (Proxy :: Proxy Graph) defaultDotConfig ex1 ---- ex1 :: ByteString -- |
-- >>> testDotParser (Proxy :: Proxy Graph) defaultDotConfig ex2 ---- ex2 :: ByteString -- |
-- >>> testDotParser (Proxy :: Proxy Graph) defaultDotConfig ex3 ---- ex3 :: ByteString ex4 :: ByteString ex5 :: ByteString ex6 :: ByteString ex7 :: ByteString ex8 :: ByteString ex9 :: ByteString ex10 :: ByteString ex11 :: ByteString ex12 :: ByteString ex13 :: ByteString ex14 :: ByteString ex15 :: ByteString -- | Test all the examples testAll :: IO () -- | Render all the examples svgAll :: IO () -- | algebraic graph example exGInt :: Graph Int -- |
-- exInt = defaultGraph & addStatements (toStatements Directed (packUTF8 . show <$> exGInt)) -- import qualified Data.ByteString.Char8 as B -- g <- processGraph exInt -- B.putStrLn $ dotPrint g ---- -- digraph { graph -- [bb="0,0,495.65,493.78";overlap=false;size="1!";splines=spline] node -- [height=0.5;label="N";shape=circle] edge [arrowsize=0] 0 -- [pos="384.5,475.78";width=0.5] 1 [pos="357.5,401.63";width=0.5] 0 -- -> 1 [pos="e,363.57,418.85 378.51,458.77 374.1,446.99 368.12,431.02 -- 363.67,419.13"] 6 [pos="411.5,401.63";width=0.5] 0 -> 6 -- [pos="e,405.43,418.85 390.49,458.77 394.9,446.99 400.87,431.02 -- 405.32,419.13"] 12 [height=0.55967;pos="467.5,401.63";width=0.55967] 0 -- -> 12 [pos="e,452.8,415.41 397.83,463.19 412.75,450.22 -- 436.85,429.27 452.43,415.73"] 2 [pos="330.5,325.33";width=0.5] 1 -> -- 2 [pos="e,336.35,342.42 351.64,384.51 347.15,372.14 340.97,355.15 -- 336.45,342.72"] 7 [pos="384.5,325.33";width=0.5] 1 -> 7 -- [pos="e,378.65,342.42 363.36,384.51 367.85,372.14 374.03,355.15 -- 378.54,342.72"] 13 [height=0.55967;pos="440.5,325.33";width=0.55967] 1 -- -> 13 [pos="e,425.95,339.36 370.47,389.02 385.4,375.66 -- 409.87,353.75 425.58,339.69"] 3 [pos="263.5,249.04";width=0.5] 2 -> -- 3 [pos="e,275.26,263.08 318.83,311.39 306.7,297.94 287.81,277 -- 275.55,263.4"] 8 [pos="419.5,249.04";width=0.5] 2 -> 8 -- [pos="e,406.15,261.18 344.02,313.05 360.71,299.11 388.95,275.54 -- 405.75,261.51"] 14 [height=0.55967;pos="475.5,249.04";width=0.55967] 2 -- -> 14 [pos="e,459.28,261.56 344.39,313.55 348.48,310.63 -- 353.06,307.61 357.5,305.19 394.93,284.71 408.73,289.04 446.5,269.19 -- 450.64,267.01 454.93, 264.4 458.9,261.81"] 18 -- [height=0.55967;pos="239.5,96.445";width=0.55967] 2 -> 18 -- [pos="e,221.18,105.3 313.92,317.87 277.75,302.66 192.9,260.73 -- 166.5,192.89 160,176.2 158.52,168.63 166.5,152.59 177.74,130.02 -- 203.11,114.24 220.76,105.5"] 19 -- [height=0.55967;pos="335.5,96.445";width=0.55967] 2 -> 19 -- [pos="e,335.94,116.84 331.52,307.33 332.98,282.28 335.56,234 -- 336.5,192.89 336.91,174.98 336.66,170.5 336.5,152.59 336.39,140.81 -- 336.16, 127.62 335.94,117.09"] 4 [pos="101.5,172.74";width=0.5] 3 -- -> 4 [pos="e,117.56,181.11 247.37,240.64 216.44,226.46 -- 149.09,195.57 117.92,181.27"] 9 [pos="193.5,172.74";width=0.5] 3 -> -- 9 [pos="e,205.67,186.66 251.62,235.43 238.93,221.96 218.89,200.69 -- 205.97,186.98"] 15 [height=0.55967;pos="287.5,172.74";width=0.55967] 3 -- -> 15 [pos="e,281.6,192.01 268.82,231.55 272.58,219.93 -- 277.61,204.35 281.51,192.29"] 5 [pos="48.498,96.445";width=0.5] 4 -- -> 5 [pos="e,58.506,111.47 91.279,157.42 81.908,144.28 -- 68.101,124.92 58.727,111.78"] 10 -- [height=0.55967;pos="104.5,96.445";width=0.55967] 4 -> 10 -- [pos="e,103.72,116.67 102.19,154.51 102.65,143.28 103.24,128.61 -- 103.71,116.95"] 16 [height=0.55967;pos="162.5,96.445";width=0.55967] 4 -- -> 16 [pos="e,150.12,112.52 112.69,158.11 123.2,145.31 -- 138.91,126.18 149.86,112.83"] 5 -> 0 [pos="e,366.23,475.02 -- 49.439,114.6 50.887,142.55 53.498,199.64 53.498,248.04 53.498,326.33 -- 53.498,326.33 53.498,326.33 53.498,464.3 295.89, 474.85 -- 365.82,475.02"] 11 [height=0.54162;pos="19.498,20.148";width=0.54162] -- 5 -> 11 [pos="e,26.284,38.534 42.206,79.323 37.545,67.382 -- 31.197,51.119 26.397,38.823"] 17 -- [height=0.55967;pos="77.498,20.148";width=0.55967] 5 -> 17 -- [pos="e,70.506,39.061 54.791,79.323 59.386,67.552 65.62,51.579 -- 70.394,39.349"] 15 -> 18 [pos="e,250.12,113.89 276.85,155.25 -- 268.95,143.04 258.24,126.45 250.31,114.18"] 15 -> 19 -- [pos="e,324.88,113.89 298.15,155.25 306.04,143.04 316.76,126.45 -- 324.69,114.18"] 18 -> 3 [pos="e,260.79,231.06 242.53,116.49 -- 247.24,145.99 256.21,202.31 260.74,230.72"] 19 -> 3 -- [pos="e,277.53,237.38 334.82,116.79 333.41,136.85 329.16,168.62 -- 316.5,192.89 307.11,210.88 290.05,227.04 277.82,237.15"] } exInt :: Graph