From 8729339d2603a7e18ef05a31bfd47f299084cb8f Mon Sep 17 00:00:00 2001 From: aarne Date: Mon, 5 Sep 2016 21:15:44 +0000 Subject: BNF grammars (.bnf or .cf) can have rules without semicolons, as in the GF book examples. However, if the grammar has any multiline rules, all of them must have semicolons. --- src/compiler/GF/Compile/GetGrammar.hs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/GF/Compile/GetGrammar.hs b/src/compiler/GF/Compile/GetGrammar.hs index c8a32ccc6..0813d15d2 100644 --- a/src/compiler/GF/Compile/GetGrammar.hs +++ b/src/compiler/GF/Compile/GetGrammar.hs @@ -66,11 +66,18 @@ getSourceModule opts file0 = getBNFCRules :: Options -> FilePath -> IOE [BNFCRule] getBNFCRules opts fpath = do raw <- liftIO (BS.readFile fpath) +---- debug BS.putStrLn $ raws (optCoding,parsed) <- parseSource opts pBNFCRules raw case parsed of - Left (Pn l c,msg) -> do cwd <- getCurrentDirectory - let location = makeRelative cwd fpath++":"++show l++":"++show c - raise (location++":\n "++msg) + Left _ -> do + let ifToChange s ss = if (BS.all (\c -> elem c [' ','\t']) s || BS.last s == ';') then s else ss -- change if not all space or end with ';' + let raws = BS.concat $ map (\s -> ifToChange s $ BS.concat [s,BS.singleton ';']) $ BS.split '\n' raw -- add semicolon to each line to be able to parse the format in GF book + (optCoding,parseds) <- parseSource opts pBNFCRules raws + case parseds of + Left (Pn l c,msg) -> do cwd <- getCurrentDirectory + let location = makeRelative cwd fpath++":"++show l++":"++show c + raise (location++":\n "++msg) + Right rules -> return rules Right rules -> return rules getEBNFRules :: Options -> FilePath -> IOE [ERule] -- cgit v1.2.3