-
Notifications
You must be signed in to change notification settings - Fork 0
Visualizations
Soumik Sarkar edited this page Mar 3, 2024
·
2 revisions
RE
s and Parser
s can be visualized using Regex.Internal.Debug
. Here are some examples.
>>> import Control.Applicative
>>> import qualified Regex.List as R
>>> import qualified Data.CharSet as CS
>>> :{
data URI = URI
{ scheme :: Maybe String
, authority :: Maybe String
, path :: String
, query :: Maybe String
, fragment :: Maybe String
} deriving Show
:}
>>> :{
uriRE :: R.RE Char URI
uriRE = URI
<$> optional (R.someStringOf (CS.not ":/?#") <* R.single ':')
<*> optional (R.list "//" *> R.manyStringOf (CS.not "/?#"))
<*> R.manyStringOf (CS.not "?#")
<*> optional (R.single '?' *> R.manyStringOf (CS.not "#"))
<*> optional (R.single '#' *> R.manyList)
:}
>>>
>>> import Regex.Internal.Debug
>>> writeFile "uri.dot" $ reToDot (Just (CS.elems CS.ascii, dispCharRanges)) uriRE
>>> writeFile "uri_p.dot" $ parserToDot (Just (CS.elems CS.ascii, dispCharRanges)) (R.compile uriRE)
>>> writeFile "uri_p_ignore.dot" $ parserToDot (Just (CS.elems CS.ascii, dispCharRanges)) (R.compile (() <$ uriRE))
>>> :! dot -Tpng -o uri.png uri.dot
>>> :! dot -Tpng -o uri_p.png uri_p.dot
>>> :! dot -Tpng -o uri_p_ignore.png uri_p_ignore.dot
uri.png
uri_p.png
uri_p_ignore.png
>>> import qualified Regex.List as R
>>> import qualified Data.CharSet as CS
>>> re = R.intRangeDec (pure ()) (123,4567)
>>> writeFile "num.dot" $ reToDot (Just (CS.elems CS.ascii, dispCharRanges)) re
>>> writeFile "num_p.dot" $ parserToDot (Just (CS.elems CS.ascii, dispCharRanges)) (R.compile re)
>>> writeFile "num_p_ignore.dot" $ parserToDot (Just (CS.elems CS.ascii, dispCharRanges)) (R.compile (() <$ re))
>>> :! dot -Tpng -o num.png num.dot
>>> :! dot -Tpng -o num_p.png num_p.dot
>>> :! dot -Tpng -o num_p_ignore.png num_p_ignore.dot
num.png
num_p.png
num_p_ignore.png