From a722de9d7b98668fa67d449f45ca4299b128c982 Mon Sep 17 00:00:00 2001 From: Kangjing Huang Date: Mon, 22 Jul 2024 22:34:33 -0400 Subject: [PATCH] Separate and export parse raw CF --- source/src/BNFC/GetCF.hs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/source/src/BNFC/GetCF.hs b/source/src/BNFC/GetCF.hs index 63a4fd53..3a8c681a 100644 --- a/source/src/BNFC/GetCF.hs +++ b/source/src/BNFC/GetCF.hs @@ -18,7 +18,7 @@ -- | Check LBNF input file and turn it into the 'CF' internal representation. module BNFC.GetCF - ( parseCF + ( parseCF, parseRawCF , checkRule, transItem ) where @@ -63,18 +63,23 @@ type Err = Either String -- $setup -- >>> import BNFC.Print --- | Entrypoint. +-- | Parse raw CF from LBNF file without checking backend requirements -parseCF :: SharedOptions -> Target -> String -> IO CF -parseCF opts target content = do - cf <- runErr $ pGrammar (myLexer content) +parseRawCF :: FilePath -> String -> Err CF +parseRawCF fileName content = pGrammar (myLexer content) -- <&> expandRules -- <&> from ghc 8.4 >>= return . expandRules - >>= getCF (lbnfFile opts) + >>= getCF fileName >>= return . markTokenCategories + -- Construct the typing information in 'define' expressions. + >>= runTypeChecker . checkDefinitions + +-- | Entrypoint. Parses full CF from LBNF file and checks against +-- all backend requirements - -- Construct the typing information in 'define' expressions. - cf <- either die return $ runTypeChecker $ checkDefinitions cf +parseCF :: SharedOptions -> Target -> String -> IO CF +parseCF opts target content = do + cf <- runErr $ parseRawCF (lbnfFile opts) content -- Some backends do not allow the grammar name to coincide with -- one of the category or constructor names.