diff options
| author | aarne <aarne@chalmers.se> | 2016-09-05 21:15:44 +0000 |
|---|---|---|
| committer | aarne <aarne@chalmers.se> | 2016-09-05 21:15:44 +0000 |
| commit | 8729339d2603a7e18ef05a31bfd47f299084cb8f (patch) | |
| tree | ff3ba47d8649d091036250057f6bc045cb379099 /src/compiler/GF/Compile | |
| parent | 06599df74d53313838dc97199691a81e79f984e7 (diff) | |
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.
Diffstat (limited to 'src/compiler/GF/Compile')
| -rw-r--r-- | src/compiler/GF/Compile/GetGrammar.hs | 13 |
1 files changed, 10 insertions, 3 deletions
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] |
