Safe Haskell | Safe-Infered |
---|
This module takes as an input a string to be parsed into an ATerm, representing BibTex entries. The ATerm should have the following form:
List [App <entrytype> [String <citationkey>, App <fieldname> [ATerm]]]
The last ATerm should match content
or in other words the value a field will have.
This is in most cases a String but can also be a list of Strings or a Tuple.
The output of the program will be another ATerm which represents that HTML datatype that is used
in module PPHtml
. The result will be sorted according to author, year and title.
In the meantime the entries will be validate, meaning that the program results in an error
when a required field is not present. Additionally the user will be given warnings when their are
fields present that are neiter required nor optional. These fields will still be passed on.
- main :: IO ()
- data Entry = Entry {}
- data FieldConstraint
- fieldEq :: FieldConstraint -> [Char] -> Bool
- required :: [Char] -> [FieldConstraint]
- optional :: [Char] -> [FieldConstraint]
- bib2html :: Component String String
- aterm2entries :: Component ATerm [Entry]
- a2Entry :: ATerm -> Feedback Entry
- short :: [Char] -> [Char]
- getF :: [([Char], [Char])] -> [Char] -> [Char]
- fields2pairs :: ATerm -> Feedback [([Char], [Char])]
- field2pair :: ATerm -> Feedback ([Char], [Char])
- fromContent :: ATerm -> Feedback [Char]
- validateEntries :: Component [Entry] [Entry]
- validateEntry :: Entry -> Feedback Entry
- cMatched :: Entry -> FieldConstraint -> Feedback ()
- fPresent :: [Char] -> Entry -> Feedback ()
- confirmEntries :: Component [Entry] [Entry]
- confirmEntry :: Entry -> Feedback Entry
- fUnused :: [FieldConstraint] -> ([Char], [Char]) -> Entry -> Feedback ()
- sortEntries :: Component [Entry] [Entry]
- entries2aterm :: Component [Entry] ATerm
- entry2aterm :: Entry -> ATerm
- field2aterm :: ([Char], [Char]) -> ATerm
Documentation
main :: IO ()
Wrap this modules component
data Entry
Intermediate representation, designed to be especially useful for the sorting we want
data FieldConstraint
Datatype that captures the notion of a choice between required fields some types required for example either an Author or an Editor, not necessarily both
Show FieldConstraint | The show instance for FieldConstraints is used in error messages |
fieldEq :: FieldConstraint -> [Char] -> Bool
Does the given string satisfy the given constraint?
required :: [Char] -> [FieldConstraint]
This set contains all the required fields
optional :: [Char] -> [FieldConstraint]
This set contains all the optional fields
bib2html :: Component String String
The main pipeline
aterm2entries :: Component ATerm [Entry]
Parse the bibtexAterm into our intermediate representation
a2Entry :: ATerm -> Feedback Entry
Creates a single entry from an ATerm of the form:
App <entrytype> [String <citationkey>, <content>]
See fromContent what should be the structure of content
short :: [Char] -> [Char]
Creates the shorthand for the authors names, by taking all uppercase letters
getF :: [([Char], [Char])] -> [Char] -> [Char]
Lookup a value from the given list of key, value pairs. If the key is not present
return a maxBound
for String. We need maxBound
because we sort on fields that are not required
for every type of entry. As a matter of fact, no such fields exists since
there is a type (misc
) that has no required fields at all.
To still be able to sort these entries, such that they end up last, we use maxBound
as if it were the value.
fields2pairs :: ATerm -> Feedback [([Char], [Char])]
Takes a ATerm List and (monadic)maps field2pair over it
field2pair :: ATerm -> Feedback ([Char], [Char])
Takes an ATerm of the form App <key> [<content>] and produces a key,value pair.
In order to do this we need to produce a value out of content
which is done by fromContent.
fromContent :: ATerm -> Feedback [Char]
The content
can be any ATerm and will be produced by the Tree instance of of Field defined in
BibTex
.
If this instance in BibTex
is updated we need to update this function also!
validateEntries :: Component [Entry] [Entry]
Validate the intermediate representation
validateEntry :: Entry -> Feedback Entry
Validate an individual entry by mapping over all required fields to see if they are present in the field list of this entry
cMatched :: Entry -> FieldConstraint -> Feedback ()
Report an error if the field list of the given Entry does not satisfy the given FieldConstraint
fPresent :: [Char] -> Entry -> Feedback ()
Helper function for cMatched which performs the actual check and error reporting
confirmEntries :: Component [Entry] [Entry]
Find fields that are neither required nor optional and warn about them
confirmEntry :: Entry -> Feedback Entry
Map over all the fields in the entry to see if they are either in the set that is the union of the optional and required fields
fUnused :: [FieldConstraint] -> ([Char], [Char]) -> Entry -> Feedback ()
Report a warning with severity 1 when the given field is not present in the given list of FieldConstraints. The third argument is only necessary to report a nicer error message. Namely to show the citation key and the type of the entry
sortEntries :: Component [Entry] [Entry]
Sort the entries
entries2aterm :: Component [Entry] ATerm
Produce the htmlAterm from the entries.
entry2aterm :: Entry -> ATerm
Produces an ATerm, for an entry, of the form:
Ann (Tuple [String <entrytype>, String <citationkey>, String <abbreviation>]) [<field>]
field2aterm :: ([Char], [Char]) -> ATerm
Produce an ATerm of a field which is of the form: Tuple [String <key>, String <value>]