diff options
| author | Peter Ljunglöf <peter.ljunglof@heatherleaf.se> | 2019-03-08 18:33:56 +0100 |
|---|---|---|
| committer | Peter Ljunglöf <peter.ljunglof@heatherleaf.se> | 2019-03-08 18:33:56 +0100 |
| commit | 01b9e8da8da56279122395219440760972b4fe49 (patch) | |
| tree | 0dcf1c0ea9aece46487400052f576517c4187225 /src | |
| parent | 926a5cf41475e7aec0b40920d2bc30444afda39c (diff) | |
canonical GF: flatten several concatenations into one json array, and parse the array back into concatenations
Diffstat (limited to 'src')
| -rw-r--r-- | src/compiler/GF/Grammar/CanonicalJSON.hs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/compiler/GF/Grammar/CanonicalJSON.hs b/src/compiler/GF/Grammar/CanonicalJSON.hs index ae2c5fab5..8024fe99a 100644 --- a/src/compiler/GF/Grammar/CanonicalJSON.hs +++ b/src/compiler/GF/Grammar/CanonicalJSON.hs @@ -136,8 +136,6 @@ instance JSON LinType where instance JSON LinValue where showJSON (LiteralValue l ) = showJSON l - -- concatenation is encoded as a JSON array: - showJSON (ConcatValue v v') = showJSON [showJSON v, showJSON v'] -- most values are encoded as JSON objects: showJSON (ParamConstant pv) = makeObj [(".param", showJSON pv)] showJSON (PredefValue p ) = makeObj [(".predef", showJSON p)] @@ -151,6 +149,10 @@ instance JSON LinValue where showJSON (PreValue pre def) = makeObj [(".pre", showJSON pre),(".default", showJSON def)] -- records are encoded directly as JSON records: showJSON (RecordValue rows) = showJSON rows + -- concatenation is encoded as a JSON array: + showJSON v@(ConcatValue _ _) = showJSON (flatten v []) + where flatten (ConcatValue v v') = flatten v . flatten v' + flatten v = (v :) readJSON o = LiteralValue <$> readJSON o <|> ParamConstant <$> o!".param" @@ -164,6 +166,8 @@ instance JSON LinValue where <|> VariantValue <$> o!".variants" <|> PreValue <$> o!".pre" <*> o!".default" <|> RecordValue <$> readJSON o + <|> do vs <- readJSON o :: Result [LinValue] + return (foldr1 ConcatValue vs) instance JSON LinLiteral where -- basic values (Str, Float, Int) are encoded as JSON strings/numbers: |
