I believe I've finished the sync parser

This commit is contained in:
Yehowshua Immanuel 2024-12-08 23:42:03 -05:00
parent db6034db40
commit 405d6ecc55
3 changed files with 29 additions and 3 deletions

View file

@ -25,9 +25,11 @@
- [ ] may want to also derive equality statements
- [x] replace both `pEol *> pMaybeWs` and `pEol <* pMaybeWs`
with `pEolAndAdvanceToNextNonWs`
- [ ] Check inline sequencing of whitespace parsers in do blocks.
Terminating instances of `pWs` should be preceeded by `<*`
# Parser Development
- [ ] Sync
- [x] Sync
- [ ] Process
- [ ] Module

View file

@ -154,7 +154,7 @@ data CaseBody = CaseBody [CaseBodyVariants] deriving (Show)
-- Syncs
data Sync = Sync SyncStmt [UpdateStmt] deriving (Show)
data SyncStmt = SigSpecPredicated SyncType SigSpec
data SyncStmt = SigSpecPredicated SigSpec SyncType
| Global
| Init
| Always

View file

@ -330,6 +330,31 @@ pSwitchEndStmt :: Parser ()
pSwitchEndStmt = void (string "end" *> pEolAndAdvanceToNextNonWs)
-- Syncs
pSync :: Parser Sync
pSync = Sync
<$> pSyncStmt
<*> many pUpdateStmt
pSyncStmt :: Parser SyncStmt
pSyncStmt = pKeywordSync *>
pSigSpecPredicatedSyncStmt <|>
pNonSigSpecPredicatedSyncStmt
where pKeywordSync = string "sync" *> pWs
pSigSpecPredicatedSyncStmt :: Parser SyncStmt
pSigSpecPredicatedSyncStmt = do
syncType <- pSyncType <* pWs
sigSpec <- pSigSpec <* pEolAndAdvanceToNextNonWs
return $ SigSpecPredicated sigSpec syncType
pNonSigSpecPredicatedSyncStmt :: Parser SyncStmt
pNonSigSpecPredicatedSyncStmt =
keyword <* pEolAndAdvanceToNextNonWs
where keyword =
(Global <$ string "global" ) <|>
(Init <$ string "init" ) <|>
(Always <$ string "always" )
pSyncType :: Parser SyncType
pSyncType =
(Low <$ string "low" ) <|>
@ -343,7 +368,6 @@ pUpdateStmt = UpdateStmt
<$> (string "update" *> pWs *> pDestSigSpec)
<*> (pWs *> pSrcSigSpec <* pEolAndAdvanceToNextNonWs)
-- would correspond to `123456789[0:9][0:8]`
exampleSigSpecSlice =
SigSpecSlice