Skip to content

Instantly share code, notes, and snippets.

@dminuoso

dminuoso/f.hs Secret

Created November 18, 2022 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dminuoso/a73383874e06061c3526049997472f79 to your computer and use it in GitHub Desktop.
Save dminuoso/a73383874e06061c3526049997472f79 to your computer and use it in GitHub Desktop.
topStanza :: Filename -> Bool -> FileTable -> Get [StanzaWithSpan]
topStanza fn i ft = do
$(switch' [| case _ of
"ATTRIBUTE" -> f (attrDef i <?> Msg "attribute definition") <* eofl
"$INCLUDE" -> (includeDef ft <?> Msg "include macro") <* eofl
"MEMBER" -> f (memberDef i <?> Msg "member definition") <* eofl
"VALUE" -> f (valueDef <?> Msg "value definition") <* eofl
"BEGIN-VENDOR" -> f (beginVendor <?> Msg "begin vendor block") <* eofl
"END-VENDOR" -> f (endVendor <?> Msg "end vendor block") <* eofl
"VENDOR" -> f (vendorDef i <?> Msg "vendor definition") <* eofl
"FLAGS" -> literal "internal" *> eofl *> topStanza fn True ft
"END-PROTOCOL" -> FP.empty
_ -> FP.branch FP.eof FP.empty
(FP.empty `cut` [ Msg "ATTRIBUTE"
, Msg "$INCLUDE"
, Msg "MEMBER"
, Msg "VALUE"
, Msg "BEGIN-VENDOR"
, Msg "VENDOR"
, Msg "FLAGS"
])
|])
where
f p = do
FP.withSpan p (\r span -> pure [StanzaWithSpan r fn span])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment