diff options
| author | Thomas Hallgren <th-github@altocumulus.org> | 2019-03-07 17:41:16 +0100 |
|---|---|---|
| committer | Thomas Hallgren <th-github@altocumulus.org> | 2019-03-07 17:41:16 +0100 |
| commit | 5b401f3880f68828272dccfb3787cc3b3abd4cc3 (patch) | |
| tree | acfb27e1a29605946fd7e242c20335b23814da1b /src/compiler/GF/Grammar/CanonicalJSON.hs | |
| parent | b783299b73b5c8a8229a45a830cf9b6be0be4f8c (diff) | |
Expose GF.Grammar.Canonical + some refactoring
to make it available in other tools by depending on the gf package and
importing it
Diffstat (limited to 'src/compiler/GF/Grammar/CanonicalJSON.hs')
| -rw-r--r-- | src/compiler/GF/Grammar/CanonicalJSON.hs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/compiler/GF/Grammar/CanonicalJSON.hs b/src/compiler/GF/Grammar/CanonicalJSON.hs index d791e0d9b..c14716eea 100644 --- a/src/compiler/GF/Grammar/CanonicalJSON.hs +++ b/src/compiler/GF/Grammar/CanonicalJSON.hs @@ -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] |
