1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2module Parse.Declaration where
4import Control.Applicative ((<$>))
5import Text.Parsec ((<|>), (<?>), choice, digit, optionMaybe, string, try)
7import qualified AST.Declaration as D
8import qualified Parse.Expression as Expr
10import qualified Parse.Type as Type
13declaration :: IParser D.SourceDecl
15 typeDecl <|> infixDecl <|> loopback <|> input <|> output <|> definition
18definition :: IParser D.SourceDecl
20 D.Definition <$> Expr.def
23typeDecl :: IParser D.SourceDecl
25 do try (reserved "type") <?> "type declaration"
27 isAlias <- optionMaybe (string "alias" >> forcedWS)
30 args <- spacePrefix lowVar
35 do tipe <- Type.expr <?> "a type"
36 return (D.TypeAlias name args tipe)
39 do tcs <- pipeSep1 Type.constructor <?> "a constructor for a union type"
40 return $ D.Datatype name args tcs
43infixDecl :: IParser D.SourceDecl
47 [ try (reserved "infixl") >> return D.L
48 , try (reserved "infixr") >> return D.R
49 , try (reserved "infix") >> return D.N
54 D.Fixity assoc (read [n]) <$> anyOp
57input :: IParser D.SourceDecl
59 do name <- wireBegining "input"
60 wireEnding (D.InputAnnotation name) hasType Type.expr
63output :: IParser D.SourceDecl
65 do name <- wireBegining "output"
67 [ wireEnding (D.OutputAnnotation name) hasType Type.expr
68 , wireEnding (D.OutputDefinition name) equals Expr.expr
72loopback :: IParser D.SourceDecl
74 do name <- wireBegining "loopback"
76 [ wireEnding (D.LoopbackAnnotation name) hasType Type.expr
77 --, wireEnding (D.LoopbackDefinition name) equals Expr.expr
81wireBegining :: String -> IParser String
83 do try (reserved keyword)
90wireEnding :: (a -> D.RawWire) -> IParser String -> IParser a -> IParser D.SourceDecl
91wireEnding makeWire op valueParser =
95 return (D.Wire (makeWire value))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list