51 lines
1.2 KiB
Haskell
51 lines
1.2 KiB
Haskell
|
module Parse -- (Step (Step),Parse,Ind,Arc,(+<-),(+->),(<<),nextId,size,len,trees,ep,eps)
|
||
|
where
|
||
|
|
||
|
-- import Data.List (intercalate)
|
||
|
import Base
|
||
|
import Step
|
||
|
|
||
|
import Data.List
|
||
|
|
||
|
type Parse τ c = [Step τ c]
|
||
|
|
||
|
ep = []
|
||
|
eps = [ep]
|
||
|
|
||
|
infixl 4 <<, +->, +<-
|
||
|
(<<) :: Parse τ κ -> Step τ κ -> Parse τ κ
|
||
|
p << s = s : p
|
||
|
|
||
|
addNode = (<<)
|
||
|
|
||
|
(+->),(+<-) :: Parse τ κ -> Arc τ -> Parse τ κ
|
||
|
(Step i c [] d : p) +-> a = Step i c [a] d : p
|
||
|
(Step i c h d : p) +<- a = Step i c h (a:d) : p
|
||
|
|
||
|
linkHead = (+->)
|
||
|
linkDep = (+<-)
|
||
|
|
||
|
nextId :: Parse τ κ -> Ind
|
||
|
nextId [] = 1
|
||
|
nextId (Step i _ _ _:_) = i + 1
|
||
|
|
||
|
len :: Parse τ κ -> Int
|
||
|
len p = length p
|
||
|
|
||
|
size :: Parse τ κ -> Int
|
||
|
size p = sum (map stepSize p) where stepSize (Step _ _ h ds) = length (h ++ ds)
|
||
|
|
||
|
trees :: Parse τ κ -> Int
|
||
|
trees p = len p - size p
|
||
|
|
||
|
|
||
|
showParse :: (Show τ, Show κ) => Parse τ κ -> String
|
||
|
showParse = concatMap shortStep
|
||
|
where
|
||
|
shortStep (Step i c h ds) = "<" ++ show i ++ "|" ++ showArcs h ++ "|" ++ showArcs ds ++ ">"
|
||
|
showArcs = intercalate "," . map showArc
|
||
|
showArc (Head r i) = show r ++ ":" ++ show i
|
||
|
showArc (Dep r i) = show r ++ ":" ++ show i
|
||
|
|
||
|
|