diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-18 08:20:33 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-18 08:20:33 +0000 |
commit | 67025bbbed585e1245cc3f895c6f6fdf5fe35d6d (patch) | |
tree | a6373e2cb572fb01c69fe615d48f3be44699ccfe /bbcode | |
parent | bc956b6977019fb55cac94bf5bc4ab0ae4fe7e2c (diff) | |
download | thermoprint-67025bbbed585e1245cc3f895c6f6fdf5fe35d6d.tar thermoprint-67025bbbed585e1245cc3f895c6f6fdf5fe35d6d.tar.gz thermoprint-67025bbbed585e1245cc3f895c6f6fdf5fe35d6d.tar.bz2 thermoprint-67025bbbed585e1245cc3f895c6f6fdf5fe35d6d.tar.xz thermoprint-67025bbbed585e1245cc3f895c6f6fdf5fe35d6d.zip |
Fixed handling of juxtaposition at toplevel
Diffstat (limited to 'bbcode')
-rw-r--r-- | bbcode/bbcode.cabal | 2 | ||||
-rw-r--r-- | bbcode/bbcode.nix | 2 | ||||
-rw-r--r-- | bbcode/src/Text/BBCode.hs | 16 | ||||
-rw-r--r-- | bbcode/test/Text/BBCodeSpec.hs | 2 |
4 files changed, 13 insertions, 9 deletions
diff --git a/bbcode/bbcode.cabal b/bbcode/bbcode.cabal index 58ea8d1..49e7a01 100644 --- a/bbcode/bbcode.cabal +++ b/bbcode/bbcode.cabal | |||
@@ -2,7 +2,7 @@ | |||
2 | -- documentation, see http://haskell.org/cabal/users-guide/ | 2 | -- documentation, see http://haskell.org/cabal/users-guide/ |
3 | 3 | ||
4 | name: bbcode | 4 | name: bbcode |
5 | version: 1.0.0 | 5 | version: 2.0.0 |
6 | synopsis: A parser for bbcode | 6 | synopsis: A parser for bbcode |
7 | -- description: | 7 | -- description: |
8 | homepage: http://dirty-haskell.org/tags/thermoprint.html | 8 | homepage: http://dirty-haskell.org/tags/thermoprint.html |
diff --git a/bbcode/bbcode.nix b/bbcode/bbcode.nix index 97f8982..ddb055c 100644 --- a/bbcode/bbcode.nix +++ b/bbcode/bbcode.nix | |||
@@ -3,7 +3,7 @@ | |||
3 | }: | 3 | }: |
4 | mkDerivation { | 4 | mkDerivation { |
5 | pname = "bbcode"; | 5 | pname = "bbcode"; |
6 | version = "1.0.0"; | 6 | version = "2.0.0"; |
7 | src = ./.; | 7 | src = ./.; |
8 | libraryHaskellDepends = [ | 8 | libraryHaskellDepends = [ |
9 | attoparsec base case-insensitive containers rosezipper text | 9 | attoparsec base case-insensitive containers rosezipper text |
diff --git a/bbcode/src/Text/BBCode.hs b/bbcode/src/Text/BBCode.hs index 8f04f19..ac56974 100644 --- a/bbcode/src/Text/BBCode.hs +++ b/bbcode/src/Text/BBCode.hs | |||
@@ -50,14 +50,16 @@ type DomForest = [[DomTree]] | |||
50 | dom :: Forest BBLabel -> DomForest | 50 | dom :: Forest BBLabel -> DomForest |
51 | -- ^ Parse semantically constrained rose tree to syntactically constrained version | 51 | -- ^ Parse semantically constrained rose tree to syntactically constrained version |
52 | -- | 52 | -- |
53 | -- Silently drops children of semantically terminal nodes ('BBPlain') and paragraphs anywhere but at top level | 53 | -- Silently drops children of semantically terminal nodes ('BBPlain') |
54 | dom = map fromPar | 54 | -- |
55 | -- We already ensured that paragraphs occur nowhere but at toplevel | ||
56 | dom = map (\(Node BBPar ts) -> map dom' ts) . ensureTopLevelPar | ||
55 | where | 57 | where |
56 | fromPar (Node BBPar ts) = concatMap dom' ts | 58 | ensureTopLevelPar xs@((Node BBPar _):_) = xs |
57 | fromPar x = dom' x | 59 | ensureTopLevelPar xs = pure $ Node BBPar xs |
58 | dom' (Node (BBPlain t) _) = pure $ Content t | 60 | |
59 | dom' (Node (BBTag t attrs) ts) = pure . Element (CI.mk t) (Map.mapKeys CI.mk attrs) $ concatMap dom' ts | 61 | dom' (Node (BBPlain t) _) = Content t |
60 | dom' (Node BBPar _) = [] | 62 | dom' (Node (BBTag t attrs) ts) = Element (CI.mk t) (Map.mapKeys CI.mk attrs) $ map dom' ts |
61 | 63 | ||
62 | -- | Errors encountered during parsing | 64 | -- | Errors encountered during parsing |
63 | data BBCodeError = LexerError String -- ^ Error while parsing input to stream of tokens | 65 | data BBCodeError = LexerError String -- ^ Error while parsing input to stream of tokens |
diff --git a/bbcode/test/Text/BBCodeSpec.hs b/bbcode/test/Text/BBCodeSpec.hs index 241cd76..a6e66b6 100644 --- a/bbcode/test/Text/BBCodeSpec.hs +++ b/bbcode/test/Text/BBCodeSpec.hs | |||
@@ -59,5 +59,7 @@ examples = [ ("[t]test[/t]" | |||
59 | , [[Content "foo"], [Content "bar"]]) | 59 | , [[Content "foo"], [Content "bar"]]) |
60 | , ("[b]foo[/b]\n\n[b]bar[/b]" | 60 | , ("[b]foo[/b]\n\n[b]bar[/b]" |
61 | , [[Element "b" [] [Content "foo"]], [Element "b" [] [Content "bar"]]]) | 61 | , [[Element "b" [] [Content "foo"]], [Element "b" [] [Content "bar"]]]) |
62 | , ("[b]foo[/b][b]bar[/b]" | ||
63 | , [[Element "b" [] [Content "foo"], Element "b" [] [Content "bar"]]]) | ||
62 | ] | 64 | ] |
63 | 65 | ||