Skip to content

Commit

Permalink
Parse: export only svd, drop unused
Browse files Browse the repository at this point in the history
  • Loading branch information
sorki committed Dec 25, 2023
1 parent d982426 commit 670c6f6
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions src/Data/SVD/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE RecordWildCards #-}

module Data.SVD.Parse where

import Safe
module Data.SVD.Parse
( svd
)
where

import Control.Arrow.ArrowList
import qualified Data.Char as Char
Expand All @@ -14,6 +15,8 @@ import Text.XML.HXT.Core

import Data.SVD.Types

import qualified Safe

-- atTag doesn't uses deep here
atTag :: ArrowXml cat => String -> cat (NTree XNode) XmlTree
atTag tag = getChildren >>> hasName tag
Expand All @@ -30,24 +33,14 @@ textAtTagOrEmpty tag = withDefault (text <<< atTag tag) ""
att :: ArrowXml cat => String -> cat XmlTree String
att = getAttrValue

-- nonempty attr value
attNE :: ArrowXml cat => String -> cat XmlTree String
attNE x = getAttrValue x >>> isA (/= "")

attMaybe :: ArrowXml cat => String -> String -> cat (NTree XNode) (Maybe String)
attMaybe attname tagname =
withDefault
(arr Just <<< attNE attname <<< atTag tagname)
Nothing

filterCrap :: String -> String
filterCrap =
unwords
. words
. filter (\c -> Char.ord c < 127)
. filter ( not . (`elem` ['\n', '\t', '\r']))

-- svd parser
-- | SVD XML parser
svd :: ArrowXml cat => cat (NTree XNode) Device
svd = atTag "device" >>>
proc x -> do
Expand All @@ -72,13 +65,6 @@ svd = atTag "device" >>>

returnA -< Device{..}

-- loose version of svd that doesn't require device properties
svdPeripherals :: ArrowXml cat => cat (NTree XNode) [Peripheral]
svdPeripherals = atTag "device" >>>
proc x -> do
devicePeripherals <- listA parsePeripheral <<< atTag "peripherals" -< x
returnA -< devicePeripherals

parsePeripheral :: ArrowXml cat => cat (NTree XNode) Peripheral
parsePeripheral = atTag "peripheral" >>>
proc x -> do
Expand Down Expand Up @@ -220,7 +206,7 @@ parseField = atTag "field" >>>
returnA -< Field{..}
where
splitRange :: String -> (Int, Int)
splitRange r = (readNote "splitRange" $ takeWhile (/=':') raw,
readNote "splitRange" $ drop 1 $ dropWhile (/=':') raw)
splitRange r = (Safe.readNote "splitRange" $ takeWhile (/=':') raw,
Safe.readNote "splitRange" $ drop 1 $ dropWhile (/=':') raw)
where
raw = drop 1 $ init r

0 comments on commit 670c6f6

Please sign in to comment.