Skip to content

Create GF source files from a CF file #150

@inariksit

Description

@inariksit

I want to be able to do this:

$ cat myGrammar.cf
S ::= "Hello" "World" ;

$ gf -f gf myGrammar.cf
Writing myGrammar.gf myGrammarCnc.gf

$ cat myGrammar.gf
abstract myGrammar = {
cat S ; 
fun S_Hello_World : S ;
}

concrete myGrammarCnc of myGrammar = {
lincat S = Str ; 
lin S_Hello_World = "Hello" ++ "World" ;
}

I infer from this line that this has been an intention 12 years ago.

cfGF :: FilePath -> IO GF

However, this line shows that it has never worked:

cfGF = error "no cfGF"

I see also that the conversion from cf goes directly into PGF here without going to GF source code first:

compileCFFiles :: Options -> [FilePath] -> IOE ()
compileCFFiles opts fs = do
bnfc_rules <- fmap concat $ mapM (getBNFCRules opts) fs
let rules = bnfc2cf bnfc_rules
startCat <- case rules of
(Rule cat _ _ : _) -> return cat
_ -> fail "empty CFG"
let pgf = cf2pgf (last fs) (mkCFG startCat Set.empty rules)
unless (flag optStopAfterPhase opts == Compile) $
do probs <- liftIO (maybe (return . defaultProbabilities) readProbabilitiesFromFile (flag optProbsFile opts) pgf)
let pgf' = setProbabilities probs $ if flag optOptimizePGF opts then optimizePGF pgf else pgf
writePGF opts pgf'
writeOutputs opts pgf'

Is there any way to piece together generation of GF source code from existing code, such as using any functions that produce canonical GF? I have already tried to use the -f canonical_gf flag, but it doesn't work for cf files as input, only for gf files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions