mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-24 02:12:50 -06:00
Export a grammar in source format to JSON
This commit is contained in:
@@ -34,6 +34,7 @@ exportPGF opts fmt pgf =
|
|||||||
FmtPGFPretty -> multi "txt" (showPGF)
|
FmtPGFPretty -> multi "txt" (showPGF)
|
||||||
FmtCanonicalGF -> [] -- canon "gf" (render80 . abstract2canonical)
|
FmtCanonicalGF -> [] -- canon "gf" (render80 . abstract2canonical)
|
||||||
FmtCanonicalJson-> []
|
FmtCanonicalJson-> []
|
||||||
|
FmtSourceJson -> []
|
||||||
FmtHaskell -> multi "hs" (grammar2haskell opts name)
|
FmtHaskell -> multi "hs" (grammar2haskell opts name)
|
||||||
FmtJava -> multi "java" (grammar2java opts name)
|
FmtJava -> multi "java" (grammar2java opts name)
|
||||||
FmtBNF -> single "bnf" bnfPrinter
|
FmtBNF -> single "bnf" bnfPrinter
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ compileSourceFiles opts fs =
|
|||||||
when (FmtCanonicalJson `elem` ofmts) $
|
when (FmtCanonicalJson `elem` ofmts) $
|
||||||
do (gr_canon,_) <- runCheck (grammar2canonical opts absname gr)
|
do (gr_canon,_) <- runCheck (grammar2canonical opts absname gr)
|
||||||
writeExport (render absname ++ ".json", encode (grammar2json gr_canon))
|
writeExport (render absname ++ ".json", encode (grammar2json gr_canon))
|
||||||
|
when (FmtSourceJson `elem` ofmts) $
|
||||||
|
do writeExport (render absname ++ ".json", encode (grammar2json gr))
|
||||||
where
|
where
|
||||||
ofmts = flag optOutputFormats opts
|
ofmts = flag optOutputFormats opts
|
||||||
|
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ data Phase = Preproc | Convert | Compile | Link
|
|||||||
data OutputFormat = FmtPGFPretty
|
data OutputFormat = FmtPGFPretty
|
||||||
| FmtCanonicalGF
|
| FmtCanonicalGF
|
||||||
| FmtCanonicalJson
|
| FmtCanonicalJson
|
||||||
|
| FmtSourceJson
|
||||||
| FmtJavaScript
|
| FmtJavaScript
|
||||||
| FmtJSON
|
| FmtJSON
|
||||||
| FmtPython
|
| FmtPython
|
||||||
@@ -474,6 +475,7 @@ outputFormatsExpl =
|
|||||||
[(("pgf_pretty", FmtPGFPretty),"human-readable pgf"),
|
[(("pgf_pretty", FmtPGFPretty),"human-readable pgf"),
|
||||||
(("canonical_gf", FmtCanonicalGF),"Canonical GF source files"),
|
(("canonical_gf", FmtCanonicalGF),"Canonical GF source files"),
|
||||||
(("canonical_json", FmtCanonicalJson),"Canonical JSON source files"),
|
(("canonical_json", FmtCanonicalJson),"Canonical JSON source files"),
|
||||||
|
(("source_json", FmtSourceJson),"Source grammar as a JSON file"),
|
||||||
(("json", FmtJSON),"JSON (whole grammar)"),
|
(("json", FmtJSON),"JSON (whole grammar)"),
|
||||||
(("haskell", FmtHaskell),"Haskell (abstract syntax)"),
|
(("haskell", FmtHaskell),"Haskell (abstract syntax)"),
|
||||||
(("java", FmtJava),"Java (abstract syntax)"),
|
(("java", FmtJava),"Java (abstract syntax)"),
|
||||||
|
|||||||
Reference in New Issue
Block a user