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.

This commit is contained in:
aarne
2016-09-05 21:15:44 +00:00
parent 06599df74d
commit 8729339d26
2 changed files with 18 additions and 3 deletions

View File

@@ -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]

View File

@@ -2,10 +2,18 @@ C_SOURCES = jpgf.c jsg.c jni_utils.c
JAVA_SOURCES = $(wildcard org/grammaticalframework/pgf/*.java) \
$(wildcard org/grammaticalframework/sg/*.java)
v v v v v v v
JNI_PATH = /usr/lib/jvm/default-java/include
=============
#JNI_PATH = /usr/lib/jvm/default-java/include
JNI_PATH = /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/
*************
JNI_PATH = $(if $(wildcard /usr/lib/jvm/default-java/include/.*), /usr/lib/jvm/default-java/include, \
$(if $(wildcard /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/.*), /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers, \
$(error No JNI headers found)))
^ ^ ^ ^ ^ ^ ^
INSTALL_PATH = /usr/local/lib
LIBTOOL = glibtool --tag=CC
LIBTOOL = $(if $(shell command -v glibtool 2>/dev/null), glibtool --tag=CC, libtool)