-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParseBibATerm.hs
47 lines (37 loc) · 1.41 KB
/
ParseBibATerm.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{-# LANGUAGE Haskell2010 #-}
-- Converts the BibTeX data returned by the BibParser into a textual ATerm representation.
-- Also contains the main function for 'parse-bib'.
module ParseBibATerm where
import Feedback
import BibParser
import ATermParser
import MainModule
import Control.Monad
import Data.List
import Data.Maybe
import System.IO
import Debug.Trace
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as B
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as T
import Data.Text.Lazy.Encoding
-- cco
import CCO.Tree (ATerm (..))
import CCO.Printing
-- Convert a list of entries to an appropriate ATerm representation.
bib2ATerm :: [BibEntry] -> ATerm
bib2ATerm = List . map doEntry
where doEntry entry = App (category entry)
$ [
App "Key" [String $ citeKey entry],
List [App key [String val] | (key,val) <- keyValues entry]
]
-- Pretty-prints an ATerm. Tries to keep the width below 80 so it is easy to read.
printATerm :: ATerm -> Text
printATerm = T.pack . render_ 80 . pp
-- Main operation. Text output in UTF-8 (ASCII, really).
parse_bib :: ProgramOperation
parse_bib input = parseBibFile input >>= return . encodeUtf8 . printATerm . bib2ATerm
main :: IO ()
main = makeMain parse_bib