all parsers now named I believe
This commit is contained in:
parent
17ed883f96
commit
87ca7637d8
|
@ -75,29 +75,33 @@ runParser str = case parse pFile "pFile" preProcessedFile of
|
||||||
|
|
||||||
-- identifiers
|
-- identifiers
|
||||||
pId :: Parser Id
|
pId :: Parser Id
|
||||||
pId = Public <$> pPublicId
|
pId = p <?> name where
|
||||||
<|> Autogen <$> pAutogenId
|
name = "Id"
|
||||||
<?> "Id"
|
p =
|
||||||
|
Public <$> pPublicId
|
||||||
|
<|> Autogen <$> pAutogenId
|
||||||
|
|
||||||
pPublicId :: Parser PublicId
|
pPublicId :: Parser PublicId
|
||||||
pPublicId = PublicId <$> (char '\\' *> many1 pNonWs)
|
pPublicId = (PublicId <$> (char '\\' *> many1 pNonWs))
|
||||||
<?> "PublicId"
|
<?> "PublicId"
|
||||||
|
|
||||||
pAutogenId :: Parser AutogenId
|
pAutogenId :: Parser AutogenId
|
||||||
pAutogenId = AutogenId <$> (char '$' *> many1 pNonWs)
|
pAutogenId = (AutogenId <$> (char '$' *> many1 pNonWs))
|
||||||
<?> "AutogenId"
|
<?> "AutogenId"
|
||||||
|
|
||||||
-- values
|
-- values
|
||||||
pValue :: Parser Value
|
pValue :: Parser Value
|
||||||
pValue = do
|
pValue = p <?> name where
|
||||||
width <- many1 pDecimalDigit
|
name = "Value"
|
||||||
char '\''
|
p =
|
||||||
value <- many pBinaryDigit
|
do
|
||||||
return $ Value (read width) (binaryStringToInt value)
|
width <- many1 pDecimalDigit
|
||||||
<?> "Value"
|
char '\''
|
||||||
|
value <- many pBinaryDigit
|
||||||
|
return $ Value (read width) (binaryStringToInt value)
|
||||||
|
|
||||||
pDecimalDigit :: Parser Char
|
pDecimalDigit :: Parser Char
|
||||||
pDecimalDigit = oneOf "0123456789"
|
pDecimalDigit = oneOf "0123456789" <?> "DecimalDigit"
|
||||||
|
|
||||||
-- update in the future to support 4 state logic
|
-- update in the future to support 4 state logic
|
||||||
-- by converting x and z to 0 and warning about it.
|
-- by converting x and z to 0 and warning about it.
|
||||||
|
@ -105,28 +109,31 @@ pBinaryDigit :: Parser Char
|
||||||
pBinaryDigit = oneOf "01" <?> "BinaryDigit"
|
pBinaryDigit = oneOf "01" <?> "BinaryDigit"
|
||||||
|
|
||||||
pInteger :: Parser Int
|
pInteger :: Parser Int
|
||||||
pInteger = do
|
pInteger = p <?> name where
|
||||||
sign <- optionMaybe (char '-')
|
name = "Integer"
|
||||||
digits <- many1 pDecimalDigit
|
p =
|
||||||
let value = read digits
|
do
|
||||||
return $ case sign of
|
sign <- optionMaybe (char '-')
|
||||||
Just _ -> -value
|
digits <- many1 pDecimalDigit
|
||||||
Nothing -> value
|
let value = read digits
|
||||||
<?> "Integer"
|
return $ case sign of
|
||||||
|
Just _ -> -value
|
||||||
|
Nothing -> value
|
||||||
|
|
||||||
-- strings
|
-- strings
|
||||||
pString :: Parser String
|
pString :: Parser String
|
||||||
pString =
|
pString = p <?> name where
|
||||||
between delimiter delimiter parseString
|
name = "String"
|
||||||
<?> "String"
|
p =
|
||||||
where
|
between delimiter delimiter parseString
|
||||||
delimiter = char '"'
|
where
|
||||||
parseString = many (pEscapedChar <|> noneOf "\\\"")
|
delimiter = char '"'
|
||||||
|
parseString = many (pEscapedChar <|> noneOf "\\\"")
|
||||||
|
|
||||||
-- comments
|
-- comments
|
||||||
-- | Removes entire comment lines starting with '#' and inline comments
|
-- | Removes entire comment lines starting with '#' and inline comments
|
||||||
preProcessDiscardComments :: String -> String
|
preProcessDiscardComments :: String -> String
|
||||||
preProcessDiscardComments input =
|
preProcessDiscardComments input =
|
||||||
unlines $ map stripComment $ filter (not . isCommentLine) $ lines input
|
unlines $ map stripComment $ filter (not . isCommentLine) $ lines input
|
||||||
where
|
where
|
||||||
-- Checks if a line is a comment line (starts with '#')
|
-- Checks if a line is a comment line (starts with '#')
|
||||||
|
@ -141,41 +148,52 @@ preProcessDiscardComments input =
|
||||||
|
|
||||||
-- file
|
-- file
|
||||||
pFile :: Parser File
|
pFile :: Parser File
|
||||||
pFile = File
|
pFile = p <?> name where
|
||||||
<$> pAutoIdxStmt
|
name = "File"
|
||||||
<*> many pModule
|
p =
|
||||||
<?> "File"
|
File
|
||||||
|
<$> pAutoIdxStmt
|
||||||
|
<*> many pModule
|
||||||
|
|
||||||
-- Autoindex statements
|
-- Autoindex statements
|
||||||
pAutoIdxStmt :: Parser AutoIdxStmt
|
pAutoIdxStmt :: Parser AutoIdxStmt
|
||||||
pAutoIdxStmt = AutoIdxStmt
|
pAutoIdxStmt = p <?> name where
|
||||||
<$> (string "autoidx" *> pWs *>
|
name = "AutoIdxStmt"
|
||||||
pInteger <* pEolAndAdvanceToNextNonWs)
|
p =
|
||||||
<?> "AutoIdxStmt"
|
AutoIdxStmt
|
||||||
|
<$> (string "autoidx" *> pWs *>
|
||||||
|
pInteger <* pEolAndAdvanceToNextNonWs)
|
||||||
|
|
||||||
-- Module
|
-- Module
|
||||||
pModule :: Parser Module
|
pModule :: Parser Module
|
||||||
pModule = do
|
pModule = p <?> name where
|
||||||
attrs <- many pAttrStmt
|
name = "Module"
|
||||||
moduleStmt <- pModuleStmt
|
p =
|
||||||
moduleBody <- pModuleBody
|
do
|
||||||
pModuleEndStmt
|
attrs <- many pAttrStmt
|
||||||
return $ Module moduleStmt attrs moduleBody
|
moduleStmt <- pModuleStmt
|
||||||
<?> "Module"
|
moduleBody <- pModuleBody
|
||||||
|
pModuleEndStmt
|
||||||
|
return $ Module moduleStmt attrs moduleBody
|
||||||
|
|
||||||
pModuleStmt :: Parser ModuleStmt
|
pModuleStmt :: Parser ModuleStmt
|
||||||
pModuleStmt = ModuleStmt
|
pModuleStmt = p <?> name where
|
||||||
<$> (string "module" *> pWs *>
|
name = "ModuleStmt"
|
||||||
pId <* pEolAndAdvanceToNextNonWs)
|
p =
|
||||||
<?> "ModuleStmt"
|
ModuleStmt
|
||||||
|
<$> (string "module" *> pWs *>
|
||||||
|
pId <* pEolAndAdvanceToNextNonWs)
|
||||||
|
|
||||||
pModuleBody :: Parser ModuleBody
|
pModuleBody :: Parser ModuleBody
|
||||||
pModuleBody = ModuleBody
|
pModuleBody = p <?> name where
|
||||||
<$> many pModuleBodyVariant
|
name = "ModuleBody"
|
||||||
<?> "ModuleBody"
|
p =
|
||||||
|
ModuleBody
|
||||||
|
<$> many pModuleBodyVariant
|
||||||
|
|
||||||
pModuleBodyVariant :: Parser ModuleBodyVariant
|
pModuleBodyVariant :: Parser ModuleBodyVariant
|
||||||
pModuleBodyVariant =
|
pModuleBodyVariant = p <?> name where
|
||||||
|
name = "ModuleBodyVariant"
|
||||||
-- `pWire`, `pMemory`, `pCell`, `pProcess` all
|
-- `pWire`, `pMemory`, `pCell`, `pProcess` all
|
||||||
-- start by parsing attribute statements, so we
|
-- start by parsing attribute statements, so we
|
||||||
-- need backtracking since we can't determin which
|
-- need backtracking since we can't determin which
|
||||||
|
@ -183,24 +201,26 @@ pModuleBodyVariant =
|
||||||
-- we encounter alone. `pParamStmt` technically doesn't
|
-- we encounter alone. `pParamStmt` technically doesn't
|
||||||
-- need to be prefixed by `try`, so that is a stylistic
|
-- need to be prefixed by `try`, so that is a stylistic
|
||||||
-- choice.
|
-- choice.
|
||||||
try (ModuleBodyParamStmt <$> pParamStmt) <|>
|
p =
|
||||||
try (ModuleBodyWire <$> pWire ) <|>
|
try (ModuleBodyParamStmt <$> pParamStmt) <|>
|
||||||
try (ModuleBodyMemory <$> pMemory ) <|>
|
try (ModuleBodyWire <$> pWire ) <|>
|
||||||
try (ModuleBodyCell <$> pCell ) <|>
|
try (ModuleBodyMemory <$> pMemory ) <|>
|
||||||
(ModuleBodyProcess <$> pProcess )
|
try (ModuleBodyCell <$> pCell ) <|>
|
||||||
<?> "ModuleBodyVariant"
|
(ModuleBodyProcess <$> pProcess )
|
||||||
|
|
||||||
pParamStmt :: Parser ParamStmt
|
pParamStmt :: Parser ParamStmt
|
||||||
pParamStmt = ParamStmt
|
pParamStmt = p <?> name where
|
||||||
<$> (string "parameter" *> pWs *> pId <* pWs)
|
name = "ParamStmt"
|
||||||
<*> optionMaybe pConstant
|
p =
|
||||||
<* pEolAndAdvanceToNextNonWs
|
ParamStmt
|
||||||
<?> "ParamStmt"
|
<$> (string "parameter" *> pWs *> pId <* pWs)
|
||||||
|
<*> optionMaybe pConstant
|
||||||
|
<* pEolAndAdvanceToNextNonWs
|
||||||
|
|
||||||
pConstant :: Parser Constant
|
pConstant :: Parser Constant
|
||||||
pConstant = p <?> name where
|
pConstant = p <?> name where
|
||||||
name = "Constant"
|
name = "Constant"
|
||||||
p =
|
p =
|
||||||
try (ConstantValue <$> pValue )
|
try (ConstantValue <$> pValue )
|
||||||
<|> (ConstantInteger <$> pInteger)
|
<|> (ConstantInteger <$> pInteger)
|
||||||
<|> (ConstantString <$> pString )
|
<|> (ConstantString <$> pString )
|
||||||
|
@ -208,14 +228,14 @@ pConstant = p <?> name where
|
||||||
pModuleEndStmt :: Parser ()
|
pModuleEndStmt :: Parser ()
|
||||||
pModuleEndStmt = p <?> name where
|
pModuleEndStmt = p <?> name where
|
||||||
name = "ModuleEndStmt"
|
name = "ModuleEndStmt"
|
||||||
p =
|
p =
|
||||||
void (string "end")
|
void (string "end")
|
||||||
|
|
||||||
-- Attribute statements
|
-- Attribute statements
|
||||||
pAttrStmt :: Parser AttrStmt
|
pAttrStmt :: Parser AttrStmt
|
||||||
pAttrStmt = p <?> name where
|
pAttrStmt = p <?> name where
|
||||||
name = "AttrStmt"
|
name = "AttrStmt"
|
||||||
p =
|
p =
|
||||||
AttrStmt
|
AttrStmt
|
||||||
<$> (string "attribute" *> pWs *> pId)
|
<$> (string "attribute" *> pWs *> pId)
|
||||||
<*> (pWs *> pConstant)
|
<*> (pWs *> pConstant)
|
||||||
|
@ -237,7 +257,7 @@ pSigSpec = p <?> name where
|
||||||
pSigSpecConcat :: Parser SigSpec
|
pSigSpecConcat :: Parser SigSpec
|
||||||
pSigSpecConcat = p <?> name where
|
pSigSpecConcat = p <?> name where
|
||||||
name = "SigSpecConcat"
|
name = "SigSpecConcat"
|
||||||
p =
|
p =
|
||||||
do
|
do
|
||||||
char '{' <* pWs
|
char '{' <* pWs
|
||||||
sigspecs <- pSigSpec `sepBy` pWs
|
sigspecs <- pSigSpec `sepBy` pWs
|
||||||
|
@ -293,13 +313,13 @@ pWireStmt = p <?> name where
|
||||||
pWireId :: Parser WireId
|
pWireId :: Parser WireId
|
||||||
pWireId = p <?> name where
|
pWireId = p <?> name where
|
||||||
name = "WireId"
|
name = "WireId"
|
||||||
p =
|
p =
|
||||||
WireId <$> pId
|
WireId <$> pId
|
||||||
|
|
||||||
pWireOption :: Parser WireOption
|
pWireOption :: Parser WireOption
|
||||||
pWireOption = p <?> name where
|
pWireOption = p <?> name where
|
||||||
name = "WireOption"
|
name = "WireOption"
|
||||||
p =
|
p =
|
||||||
try (WireOptionWidth <$> (string "width" *> pWs *> pInteger)) <|>
|
try (WireOptionWidth <$> (string "width" *> pWs *> pInteger)) <|>
|
||||||
try (WireOptionOffset <$> (string "offset" *> pWs *> pInteger)) <|>
|
try (WireOptionOffset <$> (string "offset" *> pWs *> pInteger)) <|>
|
||||||
try (WireOptionInput <$> (string "input" *> pWs *> pInteger)) <|>
|
try (WireOptionInput <$> (string "input" *> pWs *> pInteger)) <|>
|
||||||
|
@ -310,189 +330,262 @@ pWireOption = p <?> name where
|
||||||
|
|
||||||
-- Memories
|
-- Memories
|
||||||
pMemory :: Parser Memory
|
pMemory :: Parser Memory
|
||||||
pMemory = do
|
pMemory = p <?> name where
|
||||||
attrs <- many pAttrStmt
|
name = "Memory"
|
||||||
memoryStmt <- pMemoryStmt
|
p =
|
||||||
return $ Memory memoryStmt attrs
|
do
|
||||||
|
attrs <- many pAttrStmt
|
||||||
|
memoryStmt <- pMemoryStmt
|
||||||
|
return $ Memory memoryStmt attrs
|
||||||
|
|
||||||
pMemoryStmt :: Parser MemoryStmt
|
pMemoryStmt :: Parser MemoryStmt
|
||||||
pMemoryStmt = do
|
pMemoryStmt = p <?> name where
|
||||||
(string "memory" <* pWs)
|
name = "MemoryStmt"
|
||||||
options <- (many pMemoryOption <* pWs)
|
p =
|
||||||
memoryId <- MemoryID <$> pId
|
do
|
||||||
pEolAndAdvanceToNextNonWs
|
(string "memory" <* pWs)
|
||||||
return $ MemoryStmt memoryId options
|
options <- (many pMemoryOption <* pWs)
|
||||||
|
memoryId <- MemoryID <$> pId
|
||||||
|
pEolAndAdvanceToNextNonWs
|
||||||
|
return $ MemoryStmt memoryId options
|
||||||
|
|
||||||
pMemoryOption :: Parser MemoryOption
|
pMemoryOption :: Parser MemoryOption
|
||||||
pMemoryOption =
|
pMemoryOption = p <?> name where
|
||||||
try (MemoryOptionWidth <$> (string "width" *> pWs *> pInteger)) <|>
|
name = "MemoryOption"
|
||||||
try (MemoryOptionSize <$> (string "size" *> pWs *> pInteger)) <|>
|
p =
|
||||||
try (MemoryOptionOffset <$> (string "offset" *> pWs *> pInteger))
|
try (MemoryOptionWidth <$> (string "width" *> pWs *> pInteger)) <|>
|
||||||
|
try (MemoryOptionSize <$> (string "size" *> pWs *> pInteger)) <|>
|
||||||
|
try (MemoryOptionOffset <$> (string "offset" *> pWs *> pInteger))
|
||||||
|
|
||||||
-- Cells
|
-- Cells
|
||||||
pCell :: Parser Cell
|
pCell :: Parser Cell
|
||||||
pCell = do
|
pCell = p <?> name where
|
||||||
attrStmts <- many pAttrStmt
|
name = "Cell"
|
||||||
cellStmt <- pCellStmt
|
p =
|
||||||
cellBodyStmts <- many pCellBodyStmt <* pCellEndStmt
|
do
|
||||||
return $ Cell cellStmt attrStmts cellBodyStmts
|
attrStmts <- many pAttrStmt
|
||||||
|
cellStmt <- pCellStmt
|
||||||
|
cellBodyStmts <- many pCellBodyStmt <* pCellEndStmt
|
||||||
|
return $ Cell cellStmt attrStmts cellBodyStmts
|
||||||
|
|
||||||
pCellStmt :: Parser CellStmt
|
pCellStmt :: Parser CellStmt
|
||||||
pCellStmt = do
|
pCellStmt = p <?> name where
|
||||||
string "cell"
|
name = "CellStmt"
|
||||||
pWs
|
p =
|
||||||
cellType <- CellType <$> pId
|
do
|
||||||
pWs
|
string "cell"
|
||||||
cellId <- CellId <$> pId
|
pWs
|
||||||
pEolAndAdvanceToNextNonWs
|
cellType <- CellType <$> pId
|
||||||
return $ CellStmt cellId cellType
|
pWs
|
||||||
|
cellId <- CellId <$> pId
|
||||||
|
pEolAndAdvanceToNextNonWs
|
||||||
|
return $ CellStmt cellId cellType
|
||||||
|
|
||||||
pCellBodyStmt :: Parser CellBodyStmt
|
pCellBodyStmt :: Parser CellBodyStmt
|
||||||
pCellBodyStmt = pCellBodyParameter <|> pCellBodyConnect
|
pCellBodyStmt = p <?> name where
|
||||||
|
name = "CellBodyStmt"
|
||||||
|
p =
|
||||||
|
pCellBodyParameter <|> pCellBodyConnect
|
||||||
|
|
||||||
pParameterSign :: Parser ParameterSign
|
pParameterSign :: Parser ParameterSign
|
||||||
pParameterSign =
|
pParameterSign = p <?> name where
|
||||||
(Signed <$ string "signed") <|>
|
name = "ParameterSign"
|
||||||
(Real <$ string "real")
|
p =
|
||||||
|
(Signed <$ string "signed") <|>
|
||||||
|
(Real <$ string "real")
|
||||||
|
|
||||||
pCellBodyParameter :: Parser CellBodyStmt
|
pCellBodyParameter :: Parser CellBodyStmt
|
||||||
pCellBodyParameter = do
|
pCellBodyParameter = p <?> name where
|
||||||
string "parameter" <* pWs
|
name = "CellBodyParameter"
|
||||||
sign <- optionMaybe pParameterSign <* pMaybeWs
|
p =
|
||||||
id <- pId
|
do
|
||||||
const <- pConstant <* pEolAndAdvanceToNextNonWs
|
string "parameter" <* pWs
|
||||||
return $ CellBodyParameter sign id const
|
sign <- optionMaybe pParameterSign <* pMaybeWs
|
||||||
|
id <- pId
|
||||||
|
const <- pConstant <* pEolAndAdvanceToNextNonWs
|
||||||
|
return $ CellBodyParameter sign id const
|
||||||
|
|
||||||
pCellBodyConnect :: Parser CellBodyStmt
|
pCellBodyConnect :: Parser CellBodyStmt
|
||||||
pCellBodyConnect = do
|
pCellBodyConnect = p <?> name where
|
||||||
string "connect" <* pWs
|
name = "CellBodyConnect"
|
||||||
id <- pId <* pWs
|
p =
|
||||||
sigSpec <- pSigSpec <* pEolAndAdvanceToNextNonWs
|
do
|
||||||
return $ CellConnect id sigSpec
|
string "connect" <* pWs
|
||||||
|
id <- pId <* pWs
|
||||||
|
sigSpec <- pSigSpec <* pEolAndAdvanceToNextNonWs
|
||||||
|
return $ CellConnect id sigSpec
|
||||||
|
|
||||||
pCellEndStmt :: Parser ()
|
pCellEndStmt :: Parser ()
|
||||||
pCellEndStmt = void (string "end" <* pEolAndAdvanceToNextNonWs)
|
pCellEndStmt = void (string "end" <* pEolAndAdvanceToNextNonWs)
|
||||||
|
<?> "CellEndStmt"
|
||||||
|
|
||||||
-- Processes
|
-- Processes
|
||||||
pProcess :: Parser Process
|
pProcess :: Parser Process
|
||||||
pProcess = do
|
pProcess = p <?> name where
|
||||||
attrs <- many pAttrStmt
|
name = "Process"
|
||||||
procStmt <- pProcStmt
|
p =
|
||||||
processBody <- pProcessBody
|
do
|
||||||
pProcEndStmt
|
attrs <- many pAttrStmt
|
||||||
return $ Process procStmt attrs processBody
|
procStmt <- pProcStmt
|
||||||
|
processBody <- pProcessBody
|
||||||
|
pProcEndStmt
|
||||||
|
return $ Process procStmt attrs processBody
|
||||||
|
|
||||||
pProcStmt :: Parser ProcStmt
|
pProcStmt :: Parser ProcStmt
|
||||||
pProcStmt = ProcStmt
|
pProcStmt = p <?> name where
|
||||||
<$> (string "process" *> pWs *> pId)
|
name = "ProcStmt"
|
||||||
<* pEolAndAdvanceToNextNonWs
|
p =
|
||||||
|
ProcStmt
|
||||||
|
<$> (string "process" *> pWs *> pId)
|
||||||
|
<* pEolAndAdvanceToNextNonWs
|
||||||
|
|
||||||
pProcessBody :: Parser ProcessBody
|
pProcessBody :: Parser ProcessBody
|
||||||
pProcessBody = do
|
pProcessBody = p <?> name where
|
||||||
-- Since the pAssignStmt parser begins with "assign" and the pSwitch
|
name = "ProcessBody"
|
||||||
-- parser technically begins with "attribute", these both starting
|
p =
|
||||||
-- with the character 'a', we need to be able to rewind failed
|
do
|
||||||
-- attempts for `pAssignStmt` and `pSwitch` parsers as the first
|
-- Since the pAssignStmt parser begins with "assign" and the pSwitch
|
||||||
-- character being an 'a' would have been consumed.
|
-- parser technically begins with "attribute", these both starting
|
||||||
assignStmtsBefore <- many $ try pAssignStmt
|
-- with the character 'a', we need to be able to rewind failed
|
||||||
switch <- optionMaybe $ try pSwitch
|
-- attempts for `pAssignStmt` and `pSwitch` parsers as the first
|
||||||
assignStmtsAfter <- many pAssignStmt
|
-- character being an 'a' would have been consumed.
|
||||||
syncs <- many pSync
|
assignStmtsBefore <- many $ try pAssignStmt
|
||||||
return $ ProcessBody assignStmtsBefore switch assignStmtsAfter syncs
|
switch <- optionMaybe $ try pSwitch
|
||||||
|
assignStmtsAfter <- many pAssignStmt
|
||||||
|
syncs <- many pSync
|
||||||
|
return $ ProcessBody assignStmtsBefore switch assignStmtsAfter syncs
|
||||||
|
|
||||||
pAssignStmt :: Parser AssignStmt
|
pAssignStmt :: Parser AssignStmt
|
||||||
pAssignStmt = AssignStmt
|
pAssignStmt = p <?> name where
|
||||||
<$> (string "assign" *> pWs *> pDestSigSpec)
|
name = "AssignStmt"
|
||||||
<*> (pWs *> pSrcSigSpec <* pEolAndAdvanceToNextNonWs)
|
p =
|
||||||
|
AssignStmt
|
||||||
|
<$> (string "assign" *> pWs *> pDestSigSpec)
|
||||||
|
<*> (pWs *> pSrcSigSpec <* pEolAndAdvanceToNextNonWs)
|
||||||
|
|
||||||
pDestSigSpec :: Parser DestSigSpec
|
pDestSigSpec :: Parser DestSigSpec
|
||||||
pDestSigSpec = DestSigSpec <$> pSigSpec
|
pDestSigSpec = (DestSigSpec <$> pSigSpec) <?> "DestSigSpec"
|
||||||
|
|
||||||
pSrcSigSpec :: Parser SrcSigSpec
|
pSrcSigSpec :: Parser SrcSigSpec
|
||||||
pSrcSigSpec = SrcSigSpec <$> pSigSpec
|
pSrcSigSpec = (SrcSigSpec <$> pSigSpec) <?> "SrcSigSpec"
|
||||||
|
|
||||||
pProcEndStmt :: Parser ()
|
pProcEndStmt :: Parser ()
|
||||||
pProcEndStmt = void (string "end" <* pEolAndAdvanceToNextNonWs)
|
pProcEndStmt = void (string "end" <* pEolAndAdvanceToNextNonWs)
|
||||||
|
<?> "ProcEndStmt"
|
||||||
|
|
||||||
-- Switches
|
-- Switches
|
||||||
pSwitch :: Parser Switch
|
pSwitch :: Parser Switch
|
||||||
pSwitch = Switch
|
pSwitch = p <?> name where
|
||||||
<$> pSwitchStmt
|
name = "Switch"
|
||||||
<*> (many pCase <* pSwitchEndStmt)
|
p =
|
||||||
|
Switch
|
||||||
|
<$> pSwitchStmt
|
||||||
|
<*> (many pCase <* pSwitchEndStmt)
|
||||||
|
|
||||||
pSwitchStmt :: Parser SwitchStmt
|
pSwitchStmt :: Parser SwitchStmt
|
||||||
pSwitchStmt = do
|
pSwitchStmt = p <?> name where
|
||||||
attrs <- many pAttrStmt
|
name = "SwitchStmt"
|
||||||
string "switch" <* pWs
|
p =
|
||||||
sigspec <- pSigSpec <* pEolAndAdvanceToNextNonWs
|
do
|
||||||
return $ SwitchStmt sigspec attrs
|
attrs <- many pAttrStmt
|
||||||
|
string "switch" <* pWs
|
||||||
|
sigspec <- pSigSpec <* pEolAndAdvanceToNextNonWs
|
||||||
|
return $ SwitchStmt sigspec attrs
|
||||||
|
|
||||||
pCase :: Parser Case
|
pCase :: Parser Case
|
||||||
pCase = Case
|
pCase = p <?> name where
|
||||||
<$> pCaseStmt
|
name = "Case"
|
||||||
<*> many pAttrStmt
|
p =
|
||||||
<*> pCaseBody
|
Case
|
||||||
|
<$> pCaseStmt
|
||||||
|
<*> many pAttrStmt
|
||||||
|
<*> pCaseBody
|
||||||
|
|
||||||
pCaseStmt :: Parser CaseStmt
|
pCaseStmt :: Parser CaseStmt
|
||||||
pCaseStmt = CaseStmt
|
pCaseStmt = p <?> name where
|
||||||
<$> (
|
name = "CaseStmt"
|
||||||
string "case" *> pWs
|
p =
|
||||||
*> optionMaybe pCompare
|
CaseStmt
|
||||||
<* pEolAndAdvanceToNextNonWs)
|
<$> (
|
||||||
|
string "case" *> pWs
|
||||||
|
*> optionMaybe pCompare
|
||||||
|
<* pEolAndAdvanceToNextNonWs)
|
||||||
|
|
||||||
pCompare :: Parser Compare
|
pCompare :: Parser Compare
|
||||||
pCompare = Compare
|
pCompare = p <?> name where
|
||||||
<$> pSigSpec `sepBy` (pMaybeWs *> char ',' *> pMaybeWs)
|
name = "Compare"
|
||||||
|
p =
|
||||||
|
Compare
|
||||||
|
<$> pSigSpec `sepBy` (pMaybeWs *> char ',' *> pMaybeWs)
|
||||||
|
|
||||||
pCaseBody :: Parser CaseBody
|
pCaseBody :: Parser CaseBody
|
||||||
pCaseBody = CaseBody <$> many pCaseBodyVariant
|
pCaseBody = (CaseBody <$> many pCaseBodyVariant) <?> "CaseBody"
|
||||||
|
|
||||||
pCaseBodyVariant :: Parser CaseBodyVariants
|
pCaseBodyVariant :: Parser CaseBodyVariants
|
||||||
pCaseBodyVariant =
|
pCaseBodyVariant = p <?> name where
|
||||||
try (CaseBodySwitchVariant <$> pSwitch ) <|>
|
name = "CaseBodyVariant"
|
||||||
(CaseBodyAssignVariant <$> pAssignStmt)
|
p =
|
||||||
|
try (CaseBodySwitchVariant <$> pSwitch ) <|>
|
||||||
|
(CaseBodyAssignVariant <$> pAssignStmt)
|
||||||
|
|
||||||
pSwitchEndStmt :: Parser ()
|
pSwitchEndStmt :: Parser ()
|
||||||
pSwitchEndStmt = void (string "end" *> pEolAndAdvanceToNextNonWs)
|
pSwitchEndStmt = void (string "end" *> pEolAndAdvanceToNextNonWs)
|
||||||
|
<?> "SwitchEndStmt"
|
||||||
|
|
||||||
-- Syncs
|
-- Syncs
|
||||||
pSync :: Parser Sync
|
pSync :: Parser Sync
|
||||||
pSync = Sync
|
pSync = p <?> name where
|
||||||
<$> pSyncStmt
|
name = "Sync"
|
||||||
<*> many pUpdateStmt
|
p =
|
||||||
|
Sync
|
||||||
|
<$> pSyncStmt
|
||||||
|
<*> many pUpdateStmt
|
||||||
|
|
||||||
pSyncStmt :: Parser SyncStmt
|
pSyncStmt :: Parser SyncStmt
|
||||||
pSyncStmt = pKeywordSync *>
|
pSyncStmt = p <?> name where
|
||||||
pSigSpecPredicatedSyncStmt <|>
|
name = "SyncStmt"
|
||||||
pNonSigSpecPredicatedSyncStmt
|
p =
|
||||||
where pKeywordSync = string "sync" *> pWs
|
pKeywordSync *>
|
||||||
|
pSigSpecPredicatedSyncStmt <|>
|
||||||
|
pNonSigSpecPredicatedSyncStmt
|
||||||
|
where pKeywordSync = string "sync" *> pWs
|
||||||
|
|
||||||
pSigSpecPredicatedSyncStmt :: Parser SyncStmt
|
pSigSpecPredicatedSyncStmt :: Parser SyncStmt
|
||||||
pSigSpecPredicatedSyncStmt = do
|
pSigSpecPredicatedSyncStmt = p <?> name where
|
||||||
syncType <- pSyncType <* pWs
|
name = "SigSpecPredicatedSyncStmt"
|
||||||
sigSpec <- pSigSpec <* pEolAndAdvanceToNextNonWs
|
p =
|
||||||
return $ SigSpecPredicated sigSpec syncType
|
do
|
||||||
|
syncType <- pSyncType <* pWs
|
||||||
|
sigSpec <- pSigSpec <* pEolAndAdvanceToNextNonWs
|
||||||
|
return $ SigSpecPredicated sigSpec syncType
|
||||||
|
|
||||||
pNonSigSpecPredicatedSyncStmt :: Parser SyncStmt
|
pNonSigSpecPredicatedSyncStmt :: Parser SyncStmt
|
||||||
pNonSigSpecPredicatedSyncStmt =
|
pNonSigSpecPredicatedSyncStmt = p <?> name where
|
||||||
keyword <* pEolAndAdvanceToNextNonWs
|
name = "NonSigSpecPredicatedSyncStmt"
|
||||||
where keyword =
|
p =
|
||||||
(Global <$ string "global" ) <|>
|
keyword <* pEolAndAdvanceToNextNonWs
|
||||||
(Init <$ string "init" ) <|>
|
where keyword =
|
||||||
(Always <$ string "always" )
|
(Global <$ string "global" ) <|>
|
||||||
|
(Init <$ string "init" ) <|>
|
||||||
|
(Always <$ string "always" )
|
||||||
|
|
||||||
pSyncType :: Parser SyncType
|
pSyncType :: Parser SyncType
|
||||||
pSyncType =
|
pSyncType = p <?> name where
|
||||||
(Low <$ string "low" ) <|>
|
name = "SyncType"
|
||||||
(High <$ string "high" ) <|>
|
p =
|
||||||
(Posedge <$ string "posedge" ) <|>
|
(Low <$ string "low" ) <|>
|
||||||
(Negedge <$ string "negedge" ) <|>
|
(High <$ string "high" ) <|>
|
||||||
(Edge <$ string "edge" )
|
(Posedge <$ string "posedge" ) <|>
|
||||||
|
(Negedge <$ string "negedge" ) <|>
|
||||||
|
(Edge <$ string "edge" )
|
||||||
|
|
||||||
pUpdateStmt :: Parser UpdateStmt
|
pUpdateStmt :: Parser UpdateStmt
|
||||||
pUpdateStmt = UpdateStmt
|
pUpdateStmt = p <?> name where
|
||||||
<$> (string "update" *> pWs *> pDestSigSpec)
|
name = "UpdateStmt"
|
||||||
<*> (pWs *> pSrcSigSpec <* pEolAndAdvanceToNextNonWs)
|
p =
|
||||||
|
UpdateStmt
|
||||||
|
<$> (string "update" *> pWs *> pDestSigSpec)
|
||||||
|
<*> (pWs *> pSrcSigSpec <* pEolAndAdvanceToNextNonWs)
|
||||||
|
|
||||||
-- would correspond to `123456789[0:9][0:8]`
|
-- would correspond to `123456789[0:9][0:8]`
|
||||||
exampleSigSpecSlice =
|
exampleSigSpecSlice =
|
||||||
|
|
Loading…
Reference in a new issue