From cb88b56016f8517ab6d370c3862924f3db806e95 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Sun, 7 Jul 2019 17:35:31 +0200 Subject: Finish compile to PGF JSON, including JSON schema for resulting format. --- src/compiler/GF/Compile/pgf.schema.json | 232 ++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 src/compiler/GF/Compile/pgf.schema.json (limited to 'src/compiler/GF/Compile/pgf.schema.json') diff --git a/src/compiler/GF/Compile/pgf.schema.json b/src/compiler/GF/Compile/pgf.schema.json new file mode 100644 index 000000000..2ad1d5442 --- /dev/null +++ b/src/compiler/GF/Compile/pgf.schema.json @@ -0,0 +1,232 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "http://grammaticalframework.org/pgf.schema.json", + "type": "object", + "title": "PGF JSON Schema", + "required": [ + "abstract", + "concretes" + ], + "properties": { + "abstract": { + "type": "object", + "required": [ + "name", + "startcat", + "funs" + ], + "properties": { + "name": { + "type": "string" + }, + "startcat": { + "type": "string" + }, + "funs": { + "type": "object", + "additionalProperties": { + "type": "object", + "required": [ + "args", + "cat" + ], + "properties": { + "args": { + "type": "array", + "items": { + "type": "string" + } + }, + "cat": { + "type": "string" + } + } + } + } + } + }, + "concretes": { + "type": "object", + "additionalProperties": { + "required": [ + "flags", + "productions", + "functions", + "sequences", + "startCats", + "totalFIds" + ], + "properties": { + "flags": { + "type": "object", + "additionalProperties": { + "type": ["string", "number"] + } + }, + "productions": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/apply" + }, + { + "$ref": "#/definitions/coerce" + } + ] + } + } + }, + "functions": { + "type": "array", + "items": { + "title": "CncFun", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "lins": { + "type": "array", + "items": { + "type": "integer" + } + } + } + } + }, + "sequences": { + "type": "array", + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/sym" + } + } + }, + "startCats": { + "type": "object", + "additionalProperties": { + "title": "CncCat", + "type": "object", + "required": [ + "s", + "e" + ], + "properties": { + "s": { + "type": "integer" + }, + "e": { + "type": "integer" + } + } + } + }, + "totalFIds": { + "type": "integer" + } + } + } + } + }, + "definitions": { + "apply": { + "required": [ + "type", + "fid", + "args" + ], + "properties": { + "type": { + "type": "string", + "enum": ["Apply"] + }, + "fid": { + "type": "integer" + }, + "args": { + "type": "array", + "items": { + "$ref": "#/definitions/parg" + } + } + } + }, + "coerce": { + "required": [ + "type", + "arg" + ], + "properties": { + "type": { + "type": "string", + "enum": ["Coerce"] + }, + "arg": { + "type": "integer" + } + } + }, + "parg": { + "required": [ + "type", + "hypos", + "fid" + ], + "properties": { + "type": { + "type": "string", + "enum": ["PArg"] + }, + "hypos": { + "type": "array", + "items": { + "type": "integer" + } + }, + "fid": { + "type": "integer" + } + } + }, + "sym": { + "title": "Sym", + "required": [ + "type", + "args" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "SymCat", + "SymLit", + "SymVar", + "SymKS", + "SymKP", + "SymNE" + ] + }, + "args": { + "type": "array", + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "integer" + }, + { + "$ref": "#/definitions/sym" + } + ] + } + } + } + } + } +} \ No newline at end of file -- cgit v1.2.3 From a4b1fb03aa88bd501dc7fd2c7c7bd4dae7c4cf72 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Sun, 7 Jul 2019 17:38:07 +0200 Subject: Whitespace fixes --- src/compiler/GF/Compile/PGFtoJSON.hs | 5 ++--- src/compiler/GF/Compile/pgf.schema.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'src/compiler/GF/Compile/pgf.schema.json') diff --git a/src/compiler/GF/Compile/PGFtoJSON.hs b/src/compiler/GF/Compile/PGFtoJSON.hs index 7b585fc89..9a86d3e59 100644 --- a/src/compiler/GF/Compile/PGFtoJSON.hs +++ b/src/compiler/GF/Compile/PGFtoJSON.hs @@ -97,7 +97,7 @@ ffun2json (CncFun f lins) = JSON.makeObj [ ("name", mkJSStr $ showCId f) , ("lins", JSArray (map mkJSInt (Array.elems lins))) - ] + ] seq2json :: Array.Array DotPos Symbol -> JSValue seq2json seq = JSArray [sym2json s | s <- Array.elems seq] @@ -119,7 +119,7 @@ alt2json :: ([Symbol],[String]) -> JSValue alt2json (ps,ts) = new "Alt" [JSArray (map sym2json ps), JSArray (map mkJSStr ts)] new :: String -> [JSValue] -> JSValue -new f xs = +new f xs = JSON.makeObj [ ("type", mkJSStr f) , ("args", JSArray xs) @@ -132,4 +132,3 @@ mkJSStr = JSString . JSON.toJSString -- | Make JSON value from integer mkJSInt :: Integral a => a -> JSValue mkJSInt = JSRational False . toRational - diff --git a/src/compiler/GF/Compile/pgf.schema.json b/src/compiler/GF/Compile/pgf.schema.json index 2ad1d5442..a8f31e399 100644 --- a/src/compiler/GF/Compile/pgf.schema.json +++ b/src/compiler/GF/Compile/pgf.schema.json @@ -229,4 +229,4 @@ } } } -} \ No newline at end of file +} -- cgit v1.2.3 From eab9fb88aaa5408c342927693d8593f1e0ba2b91 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Wed, 10 Jul 2019 08:49:00 +0200 Subject: Minor renamings in JSON format --- src/compiler/GF/Compile/PGFtoJSON.hs | 8 ++++---- src/compiler/GF/Compile/pgf.schema.json | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/compiler/GF/Compile/pgf.schema.json') diff --git a/src/compiler/GF/Compile/PGFtoJSON.hs b/src/compiler/GF/Compile/PGFtoJSON.hs index 3fd3b60cb..e634dae67 100644 --- a/src/compiler/GF/Compile/PGFtoJSON.hs +++ b/src/compiler/GF/Compile/PGFtoJSON.hs @@ -81,16 +81,16 @@ concrete2json (c,cnc) = (showCId c,obj) , ("productions", JSON.makeObj [ (show cat, JSArray (map frule2json (Set.toList set))) | (cat,set) <- IntMap.toList (productions cnc)]) , ("functions", JSArray (map ffun2json (Array.elems (cncfuns cnc)))) , ("sequences", JSArray (map seq2json (Array.elems (sequences cnc)))) - , ("startCats", JSON.makeObj $ map cats2json (Map.assocs (cnccats cnc))) - , ("totalFIds", mkJSInt (totalCats cnc)) + , ("categories", JSON.makeObj $ map cats2json (Map.assocs (cnccats cnc))) + , ("totalfids", mkJSInt (totalCats cnc)) ] cats2json :: (CId, CncCat) -> (String,JSValue) cats2json (c,CncCat start end _) = (showCId c, ixs) where ixs = JSON.makeObj - [ ("s", mkJSInt start) - , ("e", mkJSInt end) + [ ("start", mkJSInt start) + , ("end", mkJSInt end) ] frule2json :: Production -> JSValue diff --git a/src/compiler/GF/Compile/pgf.schema.json b/src/compiler/GF/Compile/pgf.schema.json index a8f31e399..2058e9a70 100644 --- a/src/compiler/GF/Compile/pgf.schema.json +++ b/src/compiler/GF/Compile/pgf.schema.json @@ -53,8 +53,8 @@ "productions", "functions", "sequences", - "startCats", - "totalFIds" + "categories", + "totalfids" ], "properties": { "flags": { @@ -106,26 +106,26 @@ } } }, - "startCats": { + "categories": { "type": "object", "additionalProperties": { "title": "CncCat", "type": "object", "required": [ - "s", - "e" + "start", + "end" ], "properties": { - "s": { + "start": { "type": "integer" }, - "e": { + "end": { "type": "integer" } } } }, - "totalFIds": { + "totalfids": { "type": "integer" } } -- cgit v1.2.3