Expose GF.Grammar.Canonical + some refactoring

to make it available in other tools by depending on the gf package and
importing it
This commit is contained in:
Thomas Hallgren
2019-03-07 17:41:16 +01:00
parent b783299b73
commit 5b401f3880
6 changed files with 105 additions and 53 deletions

View File

@@ -95,10 +95,7 @@ instance JSON LinType where
instance JSON LinValue where
showJSON lv = case lv of
-- basic values (Str, Float, Int) are encoded as JSON strings/numbers:
StrConstant s -> showJSON s
FloatConstant f -> showJSON f
IntConstant n -> showJSON n
LiteralValue l -> showJSON l
-- concatenation is encoded as a JSON array:
ConcatValue v v' -> showJSON [showJSON v, showJSON v']
-- most values are encoded as JSON objects:
@@ -115,6 +112,13 @@ instance JSON LinValue where
-- records are encoded directly as JSON records:
RecordValue rows -> showJSON rows
instance JSON LinLiteral where
showJSON l = case l of
-- basic values (Str, Float, Int) are encoded as JSON strings/numbers:
StrConstant s -> showJSON s
FloatConstant f -> showJSON f
IntConstant n -> showJSON n
instance JSON LinPattern where
showJSON linpat = case linpat of
-- wildcards and patterns without arguments are encoded as strings:
@@ -161,6 +165,10 @@ instance JSON VarId where
showJSON Anonymous = showJSON "_"
showJSON (VarId x) = showJSON x
instance JSON QualId where
showJSON (Qual (ModId m) n) = showJSON (m++"_"++n)
showJSON (Unqual n) = showJSON n
instance JSON Flags where
-- flags are encoded directly as JSON records (i.e., objects):
showJSON (Flags fs) = makeObj [(f,showJSON v) | (f, v) <- fs]