From d300632cbc2346f6d95188426e5db5fbeb7c9f34 Mon Sep 17 00:00:00 2001 From: Nathan Collins Date: Thu, 11 May 2017 02:47:55 -0700 Subject: Improve documenation of Haddock markup (#614) * Improve documentation of Haddock markup. - document that Haddock supports inferring types top-level functions with without type signatures, but also explain why using this feature is discouraged. Looks like this feature has been around since version 2.0.0.0 in 2008! - rework the "Module description" section: - move the general discussion of field formatting to the section intro and add examples illustrating the prose for multiline fields. - mention that newlines are preserved in some multiline fields, but not in others (I also noticed that commas in the `Copyright` field are not preserved; I'll look into this bug later). - add a subsection for the module description fields documentation, and put the field keywords in code formatting (double back ticks) instead of double quotes, to be consistent with the typesetting of keywords in other parts of the documentation. - mention that "Named chunks" are not supported in the long-form "Module description" documentation. - fix formatting of keywords in the "Module attributes" section. Perhaps these errors were left over from an automatic translation to ReST from some other format as part of the transition to using Sphinx for Haddock documentation? Also, add a missing reference here; it just said "See ?"! - update footnote about special treatment for re-exporting partially imported modules not being implemented. In my tests it's not implemented at all -- I tried re-exporting both `import B hiding (f)` and `import B (a, b)` style partial imports, and in both cases got the same result as with full imports `import B`: I only get a module reference. * Rework the `Controlling the documentation structure` section. My main goal was to better explain how to use Haddock without an export list, since that's my most common use case, but I hope I improved the section overall: - remove the incomplete `Omitting the export list` section and fold it into the other sections. In particular, summarize the differences between using and not using an export list -- i.e. control over what and in what order is documented -- in the section lead. - add "realistic" examples that use the structure markup, both with and without an export list. I wanted a realistic example here to capture how it can be useful to explain the relationship between a group of functions in a section, in addition to documenting their individual APIs. - make it clear that you can associate documentation chunks with documentation sections when you aren't using an export list, and that doing it in the most obvious way -- i.e. with `-- |`, as you can in the export list -- doesn't work without an export list. It took me a while to figure this out the first time, since the docs didn't explain it at all before. - add a "no export list" example to the section header section. - add more cross references. * Add examples of gotchas for markup in `@...@`. I'm not sure this will help anyone, since I think most people first learn about `@...@` by reading other people's Haddocks, but I've documented the mistakes which I've made and then gotten confused by. * Use consistent Capitalization of Titles. Some titles were in usual title caps, and others only had the first word capitalized. I chose making them all use title caps because that seems to make the cross references look better. --- doc/markup.rst | 450 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 357 insertions(+), 93 deletions(-) (limited to 'doc') diff --git a/doc/markup.rst b/doc/markup.rst index b0ebc738..d0b9392d 100644 --- a/doc/markup.rst +++ b/doc/markup.rst @@ -8,7 +8,7 @@ will just generate documentation that contains the type signatures, data type declarations, and class declarations exported by each of the modules being processed. -Documenting a top-level declaration +Documenting a Top-Level Declaration ----------------------------------- The simplest example of a documentation annotation is for documenting @@ -35,6 +35,8 @@ the following: - A type signature for a top-level function, +- A definition for a top-level function with no type signature, + - A ``data`` declaration, - A ``newtype`` declaration, @@ -57,9 +59,12 @@ this is possible in Haddock too: :: -- ^The 'square' function squares an integer. square x = x * x -Note that Haddock doesn't contain a Haskell type system — if you don't -write the type signature for a function, then Haddock can't tell what -its type is and it won't be included in the documentation. +Since Haddock uses the GHC API internally, it can infer types for +top-level functions without type signatures. However, you're +encouraged to add explicit type signatures for all top-level +functions, to make your source code more readable for your users, and +at times to avoid GHC inferring overly general type signatures that +are less helpful to your users. Documentation annotations may span several lines; the annotation continues until the first non-comment line in the source file. For @@ -81,13 +86,13 @@ comments: :: square :: Int -> Int square x = x * x -Documenting parts of a declaration +Documenting Parts of a Declaration ---------------------------------- In addition to documenting the whole declaration, in some cases we can also document individual parts of the declaration. -Class methods +Class Methods ~~~~~~~~~~~~~ Class methods are documented in the same way as top level type @@ -99,7 +104,7 @@ signatures, by using either the ``-- |`` or ``-- ^`` annotations: :: -- | This is the documentation for the 'g' method g :: Int -> a -Constructors and record fields +Constructors and Record Fields ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Constructors are documented like so: :: @@ -150,7 +155,7 @@ would join up documentation of each field and render the result. The reason for this seemingly weird behaviour is the fact that ``someField`` is actually the same (partial) function. -Function arguments +Function Arguments ~~~~~~~~~~~~~~~~~~ Individual arguments to a function may be documented like this: :: @@ -159,7 +164,9 @@ Individual arguments to a function may be documented like this: :: -> Float -- ^ The 'Float' argument -> IO () -- ^ The return value -The module description +.. _module-description: + +The Module Description ---------------------- A module itself may be documented with multiple fields that can then be @@ -183,50 +190,100 @@ module documentation example and then talk about the fields. :: module W where ... -The “Module” field should be clear. It currently doesn't affect the -output of any of the backends but you might want to include it for human -information or for any other tools that might be parsing these comments +All fields are optional but they must be in order if they do appear. +Multi-line fields are accepted but the consecutive lines have to start +indented more than their label. If your label is indented one space as +is often the case with the ``--`` syntax, the consecutive lines have +to start at two spaces at the very least. For example, above we saw a +multiline ``Copyright`` field: :: + + {-| + ... + Copyright : (c) Some Guy, 2013 + Someone Else, 2014 + ... + -} + +That could equivalently be written as :: + + -- | ... + -- Copyright: + -- (c) Some Guy, 2013 + -- Someone Else, 2014 + -- ... + +or as :: + + -- | ... + -- Copyright: (c) Some Guy, 2013 + -- Someone Else, 2014 + -- ... + +but not as :: + + -- | ... + -- Copyright: (c) Some Guy, 2013 + -- Someone Else, 2014 + -- ... + +since the ``Someone`` needs to be indented more than the +``Copyright``. + +Whether new lines and other formatting in multiline fields is +preserved depends on the field type. For example, new lines in the +``Copyright`` field are preserved, but new lines in the +``Description`` field are not; leading whitespace is not preserved in +either [#backend]_. Please note that we do not enforce the format for +any of the fields and the established formats are just a convention. + +.. [#backend] Technically, whitespace and newlines in the + ``Description`` field are preserved verbatim by the HTML backend, + but because most browsers collapse whitespace in HTML, they don't + render as such. But other backends may render this whitespace. + +Fields of the Module Description +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The ``Module`` field specifies the current module name. Since the module +name can be inferred automatically from the source file, it doesn't +affect the output of any of the backends. But you might want to +include it for any other tools that might be parsing these comments without the help of GHC. -The “Description” field accepts some short text which outlines the +The ``Description`` field accepts some short text which outlines the general purpose of the module. If you're generating HTML, it will show up next to the module link in the module index. -The “Copyright”, “License”, “Maintainer” and “Stability” fields should -be obvious. An alternative spelling for the “License” field is accepted -as “Licence” but the output will always prefer “License”. +The ``Copyright``, ``License``, ``Maintainer`` and ``Stability`` fields should +be obvious. An alternative spelling for the ``License`` field is accepted +as ``Licence`` but the output will always prefer ``License``. -The “Portability” field has seen varied use by different library +The ``Portability`` field has seen varied use by different library authors. Some people put down things like operating system constraints there while others put down which GHC extensions are used in the module. -Note that you might want to consider using the “show-extensions” module -flag for the latter. +Note that you might want to consider using the ``show-extensions`` module +flag for the latter (see :ref:`module-attrs`). -Finally, a module may contain a documentation comment before the module -header, in which case this comment is interpreted by Haddock as an -overall description of the module itself, and placed in a section -entitled “Description” in the documentation for the module. All usual -Haddock markup is valid in this comment. +Finally, a module may contain a documentation comment before the +module header, in which case this comment is interpreted by Haddock as +an overall description of the module itself, and placed in a section +entitled ``Description`` in the documentation for the module. All the +usual Haddock :ref:`markup` is valid in this comment. -All fields are optional but they must be in order if they do appear. -Multi-line fields are accepted but the consecutive lines have to start -indented more than their label. If your label is indented one space as -is often the case with “--” syntax, the consecutive lines have to start -at two spaces at the very least. Please note that we do not enforce the -format for any of the fields and the established formats are just a -convention. - -Controlling the documentation structure +Controlling the Documentation Structure --------------------------------------- Haddock produces interface documentation that lists only the entities -actually exported by the module. The documentation for a module will +actually exported by the module. If there is no export list then all +entities defined by the module are exported. + +The documentation for a module will include *all* entities exported by that module, even if they were -re-exported by another module. The only exception is when Haddock can't +re-exported from another module. The only exception is when Haddock can't see the declaration for the re-exported entity, perhaps because it isn't part of the batch of modules currently being processed. -However, to Haddock the export list has even more significance than just +To Haddock the export list has even more significance than just specifying the entities to be included in the documentation. It also specifies the *order* that entities will be listed in the generated documentation. This leaves the programmer free to implement functions in @@ -237,9 +294,154 @@ is often used as a kind of ad-hoc interface documentation, with headings, groups of functions, type signatures and declarations in comments. +In the next section we give examples illustrating most of the +structural markup features. After the examples we go into more detail +explaining the related markup, namely :ref:`section-headings`, +:ref:`named-chunks`, and :ref:`re-exporting-entire-module`. + +.. _structure-examples: + +Documentation Structure Examples +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +We now give several examples that produce similar results and +illustrate most of the structural markup features. The first two +example use an export list, but the third example does not. + +The first example, using an export list with :ref:`section-headings` +and inline section descriptions: :: + + module Image + ( -- * Image importers + -- + -- | There is a "smart" importer, 'readImage', that determines + -- the image format from the file extension, and several + -- "dumb" format-specific importers that decode the file at + -- the specified type. + readImage + , readPngImage + , readGifImage + , ... + -- * Image exporters + -- ... + ) where + + import Image.Types ( Image ) + + -- | Read an image, guessing the format from the file name. + readImage :: FilePath -> IO Image + readImage = ... + + -- | Read a GIF. + readGifImage :: FilePath -> IO Image + readGifImage = ... + + -- | Read a PNG. + readPngImage :: FilePath -> IO Image + readPngImage = ... + + ... + +Note that the order of the entities ``readPngImage`` and +``readGifImage`` in the export list is different from the order of the +actual declarations farther down; the order in the export list is the +order used in the generated docs. Also, the imported ``Image`` type +itself is not re-exported, so it will not be included in the rendered +docs (see :ref:`hyperlinking-re-exported`). + +The second example, using an export list with a section description +defined elsewhere (the ``$imageImporters``; see :ref:`named-chunks`): +:: + + module Image + ( -- * Image importers + -- + -- $imageImporters + readImage + , readPngImage + , readGifImage + , ... + -- * Image exporters + -- ... + ) where + + import Image.Types ( Image ) + + -- $imageImporters + -- + -- There is a "smart" importer, 'readImage', that determines the + -- image format from the file extension, and several "dumb" + -- format-specific importers that decode the file at the specified + -- type. + + -- | Read an image, guessing the format from the file name. + readImage :: FilePath -> IO Image + readImage = ... + + -- | Read a GIF. + readGifImage :: FilePath -> IO Image + readGifImage = ... + + -- | Read a PNG. + readPngImage :: FilePath -> IO Image + readPngImage = ... + + ... + +This produces the same rendered docs as the first example, but the +source code itself is arguably more readable, since the documentation +for the group of importer functions is closer to their definitions. + +The third example, without an export list: :: + + module Image where + + import Image.Types ( Image ) + + -- * Image importers + -- + -- $imageImporters + -- + -- There is a "smart" importer, 'readImage', that determines the + -- image format from the file extension, and several "dumb" + -- format-specific importers that decode the file at the specified + -- type. + + -- | Read an image, guessing the format from the file name. + readImage :: FilePath -> IO Image + readImage = ... + + -- | Read a GIF. + readGifImage :: FilePath -> IO Image + readGifImage = ... + + -- | Read a PNG. + readPngImage :: FilePath -> IO Image + readPngImage = ... + + ... + + -- * Image exporters + -- ... + +Note that the section headers (e.g. ``-- * Image importers``) now +appear in the module body itself, and that the section documentation +is still given using :ref:`named-chunks`. Unlike in the first example +when using an export list, the named chunk syntax ``$imageImporters`` +*must* be used for the section documentation; attempting to use the +``-- | ...`` syntax to document the image importers here will wrongly +associate the documentation chunk with the next definition! + +.. _section-headings: + +Section Headings +~~~~~~~~~~~~~~~~ + You can insert headings and sub-headings in the documentation by -including annotations at the appropriate point in the export list. For -example: :: +including annotations at the appropriate point in the export list, or +in the module body directly when not using an export list. + +For example: :: module Foo ( -- * Classes @@ -276,7 +478,31 @@ line is also supported. e.g.: :: , g ) where -Re-exporting an entire module +When not using an export list, you may insert section headers in the +module body. Such section headers associate with all entities +declaried up until the next section header. For example: :: + + module Foo where + + -- * Classes + class C a where ... + + -- * Types + -- ** A data type + data T = ... + + -- ** A record + data R = ... + + -- * Some functions + f :: ... + f = ... + g :: ... + g = ... + +.. _re-exporting-entire-module: + +Re-Exporting an Entire Module ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Haskell allows you to re-export the entire contents of a module (or at @@ -292,8 +518,10 @@ What will the Haddock-generated documentation for this module look like? Well, it depends on how the modules ``B`` and ``C`` are imported. If they are imported wholly and without any ``hiding`` qualifiers, then the documentation will just contain a cross-reference to the documentation -for ``B`` and ``C``. However, if the modules are not *completely* -re-exported, for example: :: +for ``B`` and ``C``. + +However, if the modules are not *completely* re-exported, for example: +:: module A ( module B, @@ -304,48 +532,39 @@ re-exported, for example: :: import C (a, b) then Haddock behaves as if the set of entities re-exported from ``B`` -and ``C`` had been listed explicitly in the export list [2]_. +and ``C`` had been listed explicitly in the export list [#notImplemented]_. + +.. Comment: was this ever implemented? Perhaps this part of the docs + should just be removed until it is implemented? -.. [2] - NOTE: this is not fully implemented at the time of writing (version - 0.2). At the moment, Haddock always inserts a cross-reference. +.. [#notImplemented] This is not implemented at the time of writing + (Haddock version 2.17.3 with GHC 8.0.2). At the moment, Haddock + always inserts a module cross-reference. The exception to this rule is when the re-exported module is declared -with the ``hide`` attribute (:ref:`module-attrs`), in which case the module is +with the ``hide`` attribute (see :ref:`module-attrs`), in which +case the module is never cross-referenced; the contents are always expanded in place in the re-exporting module. -Omitting the export list -~~~~~~~~~~~~~~~~~~~~~~~~ - -If there is no export list in the module, how does Haddock generate -documentation? Well, when the export list is omitted, e.g.: :: - - module Foo where - -this is equivalent to an export list which mentions every entity defined -at the top level in this module, and Haddock treats it in the same way. -Furthermore, the generated documentation will retain the order in which -entities are defined in the module. In this special case the module body -may also include section headings (normally they would be ignored by -Haddock). :: +.. _named-chunks: - module Foo where - - -- * This heading will now appear before foo. - - -- | Documentation for 'foo'. - foo :: Integer - foo = 5 +(Named) Chunks of Documentation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Named chunks of documentation ------------------------------ +It is often desirable to include a chunk of documentation which is not +attached to any particular Haskell declaration, for example, when +giving summary documentation for a group of related definitions (see +:ref:`structure-examples`). In addition to including such documenation +chunks at the top of the file, as part of the +:ref:`module-description`, you can also associate them with +:ref:`section-headings`. -Occasionally it is desirable to include a chunk of documentation which -is not attached to any particular Haskell declaration. There are two -ways to do this: +There are several ways to associate documentation chunks with section +headings, depending on whether you are using an export list or not: -- The documentation can be included in the export list directly, e.g.: :: +- The documentation can be included in the export list directly, by + preceding it with a ``-- |``. For example: :: module Foo ( -- * A section heading @@ -354,11 +573,13 @@ ways to do this: ... ) where + In this case the chunk is not "named". + - If the documentation is large and placing it inline in the export list might bloat the export list and obscure the structure, then it can be given a name and placed out of line in the body of the module. This is achieved with a special form of documentation annotation - “``-- $``”: :: + ``-- $``, which we call a *named chunk*: :: module Foo ( -- * A section heading @@ -371,11 +592,48 @@ ways to do this: -- Here is a large chunk of documentation which may be referred to by -- the name $doc. - The documentation chunk is given a name, which is the sequence of - alphanumeric characters directly after the “``-- $``”, and it may be - referred to by the same name in the export list. + The documentation chunk is given a name of your choice (here + ``doc``), which is the sequence of alphanumeric characters directly + after the ``-- $``, and it may be referred to by the same name in + the export list. Note that named chunks must come *after* any + imports in the module body. + +- If you aren't using an export list, then your only choice is to use + a named chunk with the ``-- $`` syntax. For example: :: + + module Foo where + + -- * A section heading + -- + -- $doc + -- Here is a large chunk of documentation which may be referred to by + -- the name $doc. + + Just like with entity declariations when not using an export list, + named chunks of documentation are associated with the preceding + section header here, or with the implicit top-level documentation + section if there is no preceding section header. + + **Warning**: the form used in the first bullet above, where the + chunk is not named, *does not work* when you aren't using an + export list. For example :: -Hyperlinking and re-exported entities + module Foo where + + -- * A section heading + -- + -- | Some documentation not attached to a particular Haskell entity + + -- | The fooifier. + foo :: ... + + will result in ``Some documentation not ...`` being attached to + *next* entity declaration, here ``foo``, in addition to any other + documentation that next entity already has! + +.. _hyperlinking-re-exported: + +Hyperlinking and Re-Exported Entities ------------------------------------- When Haddock renders a type in the generated documentation, it @@ -455,26 +713,27 @@ The options and module description can be in either order. The following attributes are currently understood by Haddock: -``hide`` ``hide`` +``hide`` Omit this module from the generated documentation, but nevertheless propagate definitions and documentation from within this module to modules that re-export those definitions. -``hide`` ``prune`` +``prune`` Omit definitions that have no documentation annotations from the generated documentation. -``ignore-exports`` ``ignore-exports`` +``ignore-exports`` Ignore the export list. Generate documentation as if the module had no export list - i.e. all the top-level declarations are exported, and section headings may be given in the body of the module. -``not-home`` ``not-home`` +``not-home`` Indicates that the current module should not be considered to be the home module for each entity it exports, unless that entity is not - exported from any other module. See ? for more details. + exported from any other module. See :ref:`hyperlinking-re-exported` + for more details. -``show-extensions`` ``show-extensions`` +``show-extensions`` Indicates that we should render the extensions used in this module in the resulting documentation. This will only render if the output format supports it. If Language is set, it will be shown as well and @@ -482,6 +741,8 @@ The following attributes are currently understood by Haddock: be rendered, including those implied by their more powerful versions. +.. _markup: + Markup ------ @@ -497,7 +758,7 @@ Paragraphs One or more blank lines separates two paragraphs in a documentation comment. -Special characters +Special Characters ~~~~~~~~~~~~~~~~~~ The following characters have special meanings in documentation @@ -514,7 +775,7 @@ Furthermore, the character sequence ``>>>`` has a special meaning at the beginning of a line. To escape it, just prefix the characters in the sequence with a backslash. -Character references +Character References ~~~~~~~~~~~~~~~~~~~~ Although Haskell source files may contain any character from the Unicode @@ -546,7 +807,9 @@ call these “bird tracks”). For example: :: There is an important difference between the two forms of code block: in the bird-track form, the text to the right of the ‘\ ``>``\ ’ is interpreted literally, whereas the ``@...@`` form interprets markup as -normal inside the code block. +normal inside the code block. In particular, ``/`` is markup for italics, +and so e.g. ``@x / y / z@`` renders as ``x`` followed by italic +``y`` with no slashes, followed by ``z``. Examples ~~~~~~~~ @@ -621,7 +884,7 @@ markup is accepted [3]_: ```T'``. because strictly speaking the ````` character should not be used as a left quote, it is a grave accent. -Emphasis, Bold and Monospaced text +Emphasis, Bold and Monospaced Text ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Emphasis may be added by surrounding text with ``/.../``. Other markup @@ -637,9 +900,10 @@ underscore if you need it bold: Monospaced (or typewriter) text is indicated by surrounding it with ``@...@``. Other markup is valid inside a monospaced span: for example ``@'f' a b@`` will hyperlink the identifier ``f`` inside the code -fragment. +fragment, but ``@__FILE__@`` will render ``FILE`` in bold with no +underscores, which may not be what you had in mind. -Linking to modules +Linking to Modules ~~~~~~~~~~~~~~~~~~ Linking to a module is done by surrounding the module name with double @@ -652,7 +916,7 @@ is valid before turning it into a link but unlike with identifiers, whether the module is in scope isn't checked and will always be turned into a link. -Itemized and Enumerated lists +Itemized and Enumerated Lists ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A bulleted item is represented by preceding a paragraph with either @@ -732,7 +996,7 @@ which was unexpected. :: * bar -} -Definition lists +Definition Lists ~~~~~~~~~~~~~~~~ Definition lists are written as follows: :: @@ -833,7 +1097,7 @@ and will be removed in the future. Headings ~~~~~~~~ -Headings inside of comment documentation are possible be preceding them +Headings inside of comment documentation are possible by preceding them with a number of ``=``\ s. From 1 to 6 are accepted. Extra ``=``\ s will be treated as belonging to the text of the heading. Note that it's up to the output format to decide how to render the different levels. :: -- cgit v1.2.3 From fb2759d1c7c19d5790c0fe1b719ccc93539a6884 Mon Sep 17 00:00:00 2001 From: Herbert Valerio Riedel Date: Thu, 20 Jul 2017 12:08:53 +0200 Subject: Import @aisamanra's Haddock cheatsheet from https://github.com/aisamanra/haddock-cheatsheet --- doc/cheatsheet/LICENSE | 428 ++++++++++++++++++++++++++++++ doc/cheatsheet/README.md | 9 + doc/cheatsheet/haddocks.md | 120 +++++++++ doc/cheatsheet/haddocks.pdf | Bin 0 -> 30765 bytes doc/cheatsheet/haddocks.svg | 624 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1181 insertions(+) create mode 100644 doc/cheatsheet/LICENSE create mode 100644 doc/cheatsheet/README.md create mode 100644 doc/cheatsheet/haddocks.md create mode 100644 doc/cheatsheet/haddocks.pdf create mode 100644 doc/cheatsheet/haddocks.svg (limited to 'doc') diff --git a/doc/cheatsheet/LICENSE b/doc/cheatsheet/LICENSE new file mode 100644 index 00000000..fd662a7e --- /dev/null +++ b/doc/cheatsheet/LICENSE @@ -0,0 +1,428 @@ +Attribution-ShareAlike 4.0 International + +======================================================================= + +Creative Commons Corporation ("Creative Commons") is not a law firm and +does not provide legal services or legal advice. Distribution of +Creative Commons public licenses does not create a lawyer-client or +other relationship. Creative Commons makes its licenses and related +information available on an "as-is" basis. Creative Commons gives no +warranties regarding its licenses, any material licensed under their +terms and conditions, or any related information. Creative Commons +disclaims all liability for damages resulting from their use to the +fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and +conditions that creators and other rights holders may use to share +original works of authorship and other material subject to copyright +and certain other rights specified in the public license below. The +following considerations are for informational purposes only, are not +exhaustive, and do not form part of our licenses. + + Considerations for licensors: Our public licenses are + intended for use by those authorized to give the public + permission to use material in ways otherwise restricted by + copyright and certain other rights. Our licenses are + irrevocable. Licensors should read and understand the terms + and conditions of the license they choose before applying it. + Licensors should also secure all rights necessary before + applying our licenses so that the public can reuse the + material as expected. Licensors should clearly mark any + material not subject to the license. This includes other CC- + licensed material, or material used under an exception or + limitation to copyright. More considerations for licensors: + wiki.creativecommons.org/Considerations_for_licensors + + Considerations for the public: By using one of our public + licenses, a licensor grants the public permission to use the + licensed material under specified terms and conditions. If + the licensor's permission is not necessary for any reason--for + example, because of any applicable exception or limitation to + copyright--then that use is not regulated by the license. Our + licenses grant only permissions under copyright and certain + other rights that a licensor has authority to grant. Use of + the licensed material may still be restricted for other + reasons, including because others have copyright or other + rights in the material. A licensor may make special requests, + such as asking that all changes be marked or described. + Although not required by our licenses, you are encouraged to + respect those requests where reasonable. More_considerations + for the public: + wiki.creativecommons.org/Considerations_for_licensees + +======================================================================= + +Creative Commons Attribution-ShareAlike 4.0 International Public +License + +By exercising the Licensed Rights (defined below), You accept and agree +to be bound by the terms and conditions of this Creative Commons +Attribution-ShareAlike 4.0 International Public License ("Public +License"). To the extent this Public License may be interpreted as a +contract, You are granted the Licensed Rights in consideration of Your +acceptance of these terms and conditions, and the Licensor grants You +such rights in consideration of benefits the Licensor receives from +making the Licensed Material available under these terms and +conditions. + + +Section 1 -- Definitions. + + a. Adapted Material means material subject to Copyright and Similar + Rights that is derived from or based upon the Licensed Material + and in which the Licensed Material is translated, altered, + arranged, transformed, or otherwise modified in a manner requiring + permission under the Copyright and Similar Rights held by the + Licensor. For purposes of this Public License, where the Licensed + Material is a musical work, performance, or sound recording, + Adapted Material is always produced where the Licensed Material is + synched in timed relation with a moving image. + + b. Adapter's License means the license You apply to Your Copyright + and Similar Rights in Your contributions to Adapted Material in + accordance with the terms and conditions of this Public License. + + c. BY-SA Compatible License means a license listed at + creativecommons.org/compatiblelicenses, approved by Creative + Commons as essentially the equivalent of this Public License. + + d. Copyright and Similar Rights means copyright and/or similar rights + closely related to copyright including, without limitation, + performance, broadcast, sound recording, and Sui Generis Database + Rights, without regard to how the rights are labeled or + categorized. For purposes of this Public License, the rights + specified in Section 2(b)(1)-(2) are not Copyright and Similar + Rights. + + e. Effective Technological Measures means those measures that, in the + absence of proper authority, may not be circumvented under laws + fulfilling obligations under Article 11 of the WIPO Copyright + Treaty adopted on December 20, 1996, and/or similar international + agreements. + + f. Exceptions and Limitations means fair use, fair dealing, and/or + any other exception or limitation to Copyright and Similar Rights + that applies to Your use of the Licensed Material. + + g. License Elements means the license attributes listed in the name + of a Creative Commons Public License. The License Elements of this + Public License are Attribution and ShareAlike. + + h. Licensed Material means the artistic or literary work, database, + or other material to which the Licensor applied this Public + License. + + i. Licensed Rights means the rights granted to You subject to the + terms and conditions of this Public License, which are limited to + all Copyright and Similar Rights that apply to Your use of the + Licensed Material and that the Licensor has authority to license. + + j. Licensor means the individual(s) or entity(ies) granting rights + under this Public License. + + k. Share means to provide material to the public by any means or + process that requires permission under the Licensed Rights, such + as reproduction, public display, public performance, distribution, + dissemination, communication, or importation, and to make material + available to the public including in ways that members of the + public may access the material from a place and at a time + individually chosen by them. + + l. Sui Generis Database Rights means rights other than copyright + resulting from Directive 96/9/EC of the European Parliament and of + the Council of 11 March 1996 on the legal protection of databases, + as amended and/or succeeded, as well as other essentially + equivalent rights anywhere in the world. + + m. You means the individual or entity exercising the Licensed Rights + under this Public License. Your has a corresponding meaning. + + +Section 2 -- Scope. + + a. License grant. + + 1. Subject to the terms and conditions of this Public License, + the Licensor hereby grants You a worldwide, royalty-free, + non-sublicensable, non-exclusive, irrevocable license to + exercise the Licensed Rights in the Licensed Material to: + + a. reproduce and Share the Licensed Material, in whole or + in part; and + + b. produce, reproduce, and Share Adapted Material. + + 2. Exceptions and Limitations. For the avoidance of doubt, where + Exceptions and Limitations apply to Your use, this Public + License does not apply, and You do not need to comply with + its terms and conditions. + + 3. Term. The term of this Public License is specified in Section + 6(a). + + 4. Media and formats; technical modifications allowed. The + Licensor authorizes You to exercise the Licensed Rights in + all media and formats whether now known or hereafter created, + and to make technical modifications necessary to do so. The + Licensor waives and/or agrees not to assert any right or + authority to forbid You from making technical modifications + necessary to exercise the Licensed Rights, including + technical modifications necessary to circumvent Effective + Technological Measures. For purposes of this Public License, + simply making modifications authorized by this Section 2(a) + (4) never produces Adapted Material. + + 5. Downstream recipients. + + a. Offer from the Licensor -- Licensed Material. Every + recipient of the Licensed Material automatically + receives an offer from the Licensor to exercise the + Licensed Rights under the terms and conditions of this + Public License. + + b. Additional offer from the Licensor -- Adapted Material. + Every recipient of Adapted Material from You + automatically receives an offer from the Licensor to + exercise the Licensed Rights in the Adapted Material + under the conditions of the Adapter's License You apply. + + c. No downstream restrictions. You may not offer or impose + any additional or different terms or conditions on, or + apply any Effective Technological Measures to, the + Licensed Material if doing so restricts exercise of the + Licensed Rights by any recipient of the Licensed + Material. + + 6. No endorsement. Nothing in this Public License constitutes or + may be construed as permission to assert or imply that You + are, or that Your use of the Licensed Material is, connected + with, or sponsored, endorsed, or granted official status by, + the Licensor or others designated to receive attribution as + provided in Section 3(a)(1)(A)(i). + + b. Other rights. + + 1. Moral rights, such as the right of integrity, are not + licensed under this Public License, nor are publicity, + privacy, and/or other similar personality rights; however, to + the extent possible, the Licensor waives and/or agrees not to + assert any such rights held by the Licensor to the limited + extent necessary to allow You to exercise the Licensed + Rights, but not otherwise. + + 2. Patent and trademark rights are not licensed under this + Public License. + + 3. To the extent possible, the Licensor waives any right to + collect royalties from You for the exercise of the Licensed + Rights, whether directly or through a collecting society + under any voluntary or waivable statutory or compulsory + licensing scheme. In all other cases the Licensor expressly + reserves any right to collect such royalties. + + +Section 3 -- License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the +following conditions. + + a. Attribution. + + 1. If You Share the Licensed Material (including in modified + form), You must: + + a. retain the following if it is supplied by the Licensor + with the Licensed Material: + + i. identification of the creator(s) of the Licensed + Material and any others designated to receive + attribution, in any reasonable manner requested by + the Licensor (including by pseudonym if + designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of + warranties; + + v. a URI or hyperlink to the Licensed Material to the + extent reasonably practicable; + + b. indicate if You modified the Licensed Material and + retain an indication of any previous modifications; and + + c. indicate the Licensed Material is licensed under this + Public License, and include the text of, or the URI or + hyperlink to, this Public License. + + 2. You may satisfy the conditions in Section 3(a)(1) in any + reasonable manner based on the medium, means, and context in + which You Share the Licensed Material. For example, it may be + reasonable to satisfy the conditions by providing a URI or + hyperlink to a resource that includes the required + information. + + 3. If requested by the Licensor, You must remove any of the + information required by Section 3(a)(1)(A) to the extent + reasonably practicable. + + b. ShareAlike. + + In addition to the conditions in Section 3(a), if You Share + Adapted Material You produce, the following conditions also apply. + + 1. The Adapter's License You apply must be a Creative Commons + license with the same License Elements, this version or + later, or a BY-SA Compatible License. + + 2. You must include the text of, or the URI or hyperlink to, the + Adapter's License You apply. You may satisfy this condition + in any reasonable manner based on the medium, means, and + context in which You Share Adapted Material. + + 3. You may not offer or impose any additional or different terms + or conditions on, or apply any Effective Technological + Measures to, Adapted Material that restrict exercise of the + rights granted under the Adapter's License You apply. + + +Section 4 -- Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that +apply to Your use of the Licensed Material: + + a. for the avoidance of doubt, Section 2(a)(1) grants You the right + to extract, reuse, reproduce, and Share all or a substantial + portion of the contents of the database; + + b. if You include all or a substantial portion of the database + contents in a database in which You have Sui Generis Database + Rights, then the database in which You have Sui Generis Database + Rights (but not its individual contents) is Adapted Material, + + including for purposes of Section 3(b); and + c. You must comply with the conditions in Section 3(a) if You Share + all or a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not +replace Your obligations under this Public License where the Licensed +Rights include other Copyright and Similar Rights. + + +Section 5 -- Disclaimer of Warranties and Limitation of Liability. + + a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE + EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS + AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF + ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, + IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, + WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR + PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, + ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT + KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT + ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. + + b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE + TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, + NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, + INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, + COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR + USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN + ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR + DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR + IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. + + c. The disclaimer of warranties and limitation of liability provided + above shall be interpreted in a manner that, to the extent + possible, most closely approximates an absolute disclaimer and + waiver of all liability. + + +Section 6 -- Term and Termination. + + a. This Public License applies for the term of the Copyright and + Similar Rights licensed here. However, if You fail to comply with + this Public License, then Your rights under this Public License + terminate automatically. + + b. Where Your right to use the Licensed Material has terminated under + Section 6(a), it reinstates: + + 1. automatically as of the date the violation is cured, provided + it is cured within 30 days of Your discovery of the + violation; or + + 2. upon express reinstatement by the Licensor. + + For the avoidance of doubt, this Section 6(b) does not affect any + right the Licensor may have to seek remedies for Your violations + of this Public License. + + c. For the avoidance of doubt, the Licensor may also offer the + Licensed Material under separate terms or conditions or stop + distributing the Licensed Material at any time; however, doing so + will not terminate this Public License. + + d. Sections 1, 5, 6, 7, and 8 survive termination of this Public + License. + + +Section 7 -- Other Terms and Conditions. + + a. The Licensor shall not be bound by any additional or different + terms or conditions communicated by You unless expressly agreed. + + b. Any arrangements, understandings, or agreements regarding the + Licensed Material not stated herein are separate from and + independent of the terms and conditions of this Public License. + + +Section 8 -- Interpretation. + + a. For the avoidance of doubt, this Public License does not, and + shall not be interpreted to, reduce, limit, restrict, or impose + conditions on any use of the Licensed Material that could lawfully + be made without permission under this Public License. + + b. To the extent possible, if any provision of this Public License is + deemed unenforceable, it shall be automatically reformed to the + minimum extent necessary to make it enforceable. If the provision + cannot be reformed, it shall be severed from this Public License + without affecting the enforceability of the remaining terms and + conditions. + + c. No term or condition of this Public License will be waived and no + failure to comply consented to unless expressly agreed to by the + Licensor. + + d. Nothing in this Public License constitutes or may be interpreted + as a limitation upon, or waiver of, any privileges and immunities + that apply to the Licensor or You, including from the legal + processes of any jurisdiction or authority. + + +======================================================================= + +Creative Commons is not a party to its public +licenses. Notwithstanding, Creative Commons may elect to apply one of +its public licenses to material it publishes and in those instances +will be considered the “Licensor.” The text of the Creative Commons +public licenses is dedicated to the public domain under the CC0 Public +Domain Dedication. Except for the limited purpose of indicating that +material is shared under a Creative Commons public license or as +otherwise permitted by the Creative Commons policies published at +creativecommons.org/policies, Creative Commons does not authorize the +use of the trademark "Creative Commons" or any other trademark or logo +of Creative Commons without its prior written consent including, +without limitation, in connection with any unauthorized modifications +to any of its public licenses or any other arrangements, +understandings, or agreements concerning use of licensed material. For +the avoidance of doubt, this paragraph does not form part of the +public licenses. + +Creative Commons may be contacted at creativecommons.org. + diff --git a/doc/cheatsheet/README.md b/doc/cheatsheet/README.md new file mode 100644 index 00000000..c5856217 --- /dev/null +++ b/doc/cheatsheet/README.md @@ -0,0 +1,9 @@ +![License: CC BY-SA 4.0](https://img.shields.io/badge/License-CC%20BY--SA%204.0-lightgrey.svg) + +# Haddock Markup Quick Reference + +This page is a single-page quick reference for the markup used in GHC's [Haddock](https://www.haskell.org/haddock/) documentation format. It doesn't list all the details of the format, just the basic markup, so for the vagaries and edge-cases of the syntax, it would be helpful to consult the [Haddock user guide](http://haskell-haddock.readthedocs.io/en/latest/index.html). + +## License + +This document is licensed under the CC BY-SA 4.0 license. diff --git a/doc/cheatsheet/haddocks.md b/doc/cheatsheet/haddocks.md new file mode 100644 index 00000000..fbe71392 --- /dev/null +++ b/doc/cheatsheet/haddocks.md @@ -0,0 +1,120 @@ +# Code Sections + +``` + -- * Section + -- ** Sub-section + -- *** Sub-sub-section + -- et cetera +``` + +# Named Documentation Chunks + +``` + -- $name +[...] + -- $name + -- Here is the documentation text + -- which is embedded elsewhere +``` + +# Code Blocks + +``` +With internal markup: + -- @ + -- fact n = product [1..n] + -- @ +With literal text: + -- > fact n = product [1..n] +``` + +# REPL Examples + +``` + -- >>> fact 5 + -- 120 +``` + +# Properties + +``` + -- prop> a + b = b + a +``` + +# Hyperlinked Identifiers + +``` + -- The value 'x' of type 'T' + -- The out-of-scope 'MyModule.x' + -- The "MyModule" module +``` + +# Textual Markup + +``` + -- Emphasis: /forward slashes/. + -- Bolding: __underscores__. + -- Monospaced text: @ampersands@. +``` + +# Links and Images + +``` + -- A raw link + -- [a link](http://example.com) + -- ![description](imagepath.png) +``` + +# Lists + +``` +itemized with "*" or "-" + -- * first item + -- * second item +numbered with "(n)" or "n." + -- 1. first item + -- 2. second item +definitions with "[thing]" + -- [one] first item + -- [two] second item +``` + +# Mathematics/LaTeX + +``` + -- \[ + -- f(n) = \Sum_{i=1}^{n} i + -- \] + \\ when \(n > 0\) +``` + +# Headings in Documentation + +``` + -- = Heading + -- == Sub-heading + -- === Sub-sub-heading +``` + +# Metadata + +``` + -- @since 1.2.3 +``` + +# Module Attributes + +``` +{-# OPTIONS_HADDOCK hide #-} + Omit this module from the docs +{-# OPTIONS_HADDOCK prune #-} + Omit definitions without docs +{-# OPTIONS_HADDOCK ignore-exports #-} + Treat this module as though all + top-level items are exported +{-# OPTIONS_HADDOCK not-home #-} + Do not treat this module as the + "home" of identifiers it exports +{-# OPTIONS_HADDOCK show-extensions #-} + Show all enabled LANGUAGE extensions +``` diff --git a/doc/cheatsheet/haddocks.pdf b/doc/cheatsheet/haddocks.pdf new file mode 100644 index 00000000..130e8595 Binary files /dev/null and b/doc/cheatsheet/haddocks.pdf differ diff --git a/doc/cheatsheet/haddocks.svg b/doc/cheatsheet/haddocks.svg new file mode 100644 index 00000000..ea08781f --- /dev/null +++ b/doc/cheatsheet/haddocks.svg @@ -0,0 +1,624 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + Code Sections -- * Section -- ** Sub-section -- *** Sub-sub-section -- et cetera + Named Documentation Chunks -- $name[...] -- $name -- Here is the documentation text -- which is embedded elsewhere + Code BlocksWith internal markup: -- @ -- fact n = product [1..n] -- @With literal text: -- > fact n = product [1..n] + REPL Examples -- >>> fact 5 -- 120 + Properties -- prop> a + b = b + a + Hyperlinked Identifiers -- The value 'x' of type 'T' -- The out-of-scope 'MyModule.x' -- The "MyModule" module + Textual Markup -- Emphasis: /forward slashes/. -- Bolding: __underscores__. -- Monospaced text: @at signs@. + Links and Images -- A raw link <http://example.com> -- [a link](http://example.com) -- ![description](imagepath.png) + Listsitemized with "*" or "-" -- * first item -- * second itemnumbered with "(n)" or "n." -- 1. first item -- 2. second itemdefinitions with "[thing]" -- [one] first item -- [two] second item + Mathematics/LaTeX -- \[ -- f(n) = \Sum_{i=1}^{n} i -- \] -- when \(n > 0\) + Headings in Documentation -- = Heading -- == Sub-heading -- === sub-sub-heading + Metadata -- @since 1.2.3 + Module Attributes{-# OPTIONS_HADDOCK hide #-} Omit this module from the docs{-# OPTIONS_HADDOCK prune #-} Omit definitions without docs{-# OPTIONS_HADDOCK ignore-exports #-} Treat this module as though all top-level items are exported{-# OPTIONS_HADDOCK not-home #-} Do not treat this module as the "home" of identifiers it exports{-# OPTIONS_HADDOCK show-extensions #-} Show all enabled LANGUAGE extensions + Haddock Markup + + + Haddock Markup Cheat-sheet, Version 1.1Getty Ritter (@aisamanra)github.com/aisamanra/haddock-cheatsheetThis work is licensed under a Creative CommonsAttribution-ShareAlike 4.0 International License + + -- cgit v1.2.3 From f1d326b53fbed5d37f2a83c66e73dbbc94a4354f Mon Sep 17 00:00:00 2001 From: Alexander Biehl Date: Sun, 6 Aug 2017 13:18:02 +0200 Subject: Provide --show-interface option to dump interfaces (#645) * WIP: Provide --show-interface option to dump interfaces Like ghcs own --show-iface this flag dumps a binary interface file to stdout in a human (and machine) readable fashion. Currently it uses json as output format. * Fill all the jsonNull stubs * Rework Bifunctor instance of DocH, update changelog and documentation * replace changelog, bring DocMarkupH doc back * Update CHANGES.md * Update CHANGES.md * Move Control.Arrow up It would result in unused import if the Bifunctor instance is not generated. --- doc/invoking.rst | 5 + haddock-api/haddock-api.cabal | 1 + haddock-api/src/Haddock.hs | 7 ++ haddock-api/src/Haddock/Interface/Json.hs | 109 +++++++++++++++++++++ haddock-api/src/Haddock/Options.hs | 6 ++ haddock-library/CHANGES.md | 6 ++ haddock-library/src/Documentation/Haddock/Types.hs | 33 ++++++- haddock.cabal | 1 + 8 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 haddock-api/src/Haddock/Interface/Json.hs (limited to 'doc') diff --git a/doc/invoking.rst b/doc/invoking.rst index 83087bac..fc1e4410 100644 --- a/doc/invoking.rst +++ b/doc/invoking.rst @@ -88,6 +88,11 @@ The following options are available: :option:`--read-interface` option for more details. The interface file is in a binary format; don't try to read it. +.. option:: --show-interface= + + Dumps a binary interface file to stdout in a human readable fashion. + Uses json as output format. + .. [1] Haddock interface files are not the same as Haskell interface files, I just couldn't think of a better name. diff --git a/haddock-api/haddock-api.cabal b/haddock-api/haddock-api.cabal index ef4bb98c..d38e9149 100644 --- a/haddock-api/haddock-api.cabal +++ b/haddock-api/haddock-api.cabal @@ -73,6 +73,7 @@ library Haddock.Interface.Rename Haddock.Interface.Create Haddock.Interface.AttachInstances + Haddock.Interface.Json Haddock.Interface.LexParseRn Haddock.Interface.ParseModuleHeader Haddock.Interface.Specialize diff --git a/haddock-api/src/Haddock.hs b/haddock-api/src/Haddock.hs index 57ea5fea..554cb416 100644 --- a/haddock-api/src/Haddock.hs +++ b/haddock-api/src/Haddock.hs @@ -32,6 +32,7 @@ import Haddock.Backends.LaTeX import Haddock.Backends.Hoogle import Haddock.Backends.Hyperlinker import Haddock.Interface +import Haddock.Interface.Json import Haddock.Parser import Haddock.Types import Haddock.Version @@ -68,6 +69,7 @@ import System.Directory (doesDirectoryExist) import GHC hiding (verbosity) import Config import DynFlags hiding (projectVersion, verbosity) +import ErrUtils import Packages import Panic (handleGhcException) import Module @@ -164,6 +166,11 @@ haddockWithGhc ghc args = handleTopExceptions $ do dflags <- getDynFlags + forM_ (optShowInterfaceFile flags) $ \path -> liftIO $ do + mIfaceFile <- readInterfaceFiles freshNameCache [(("", Nothing), path)] + forM_ mIfaceFile $ \(_, ifaceFile) -> do + putMsg dflags (renderJson (jsonInterfaceFile ifaceFile)) + if not (null files) then do (packages, ifaces, homeLinks) <- readPackagesAndProcessModules flags files diff --git a/haddock-api/src/Haddock/Interface/Json.hs b/haddock-api/src/Haddock/Interface/Json.hs new file mode 100644 index 00000000..9a569204 --- /dev/null +++ b/haddock-api/src/Haddock/Interface/Json.hs @@ -0,0 +1,109 @@ +{-# LANGUAGE RecordWildCards #-} +module Haddock.Interface.Json ( + jsonInstalledInterface + , jsonInterfaceFile + , renderJson + ) where + +import BasicTypes +import Json +import Module +import Name +import Outputable + +import Control.Arrow +import Data.Map (Map) +import Data.Bifunctor +import qualified Data.Map as Map + +import Haddock.Types +import Haddock.InterfaceFile + +jsonInterfaceFile :: InterfaceFile -> JsonDoc +jsonInterfaceFile InterfaceFile{..} = + jsonObject [ ("link_env" , jsonMap nameStableString (jsonString . moduleNameString . moduleName) ifLinkEnv) + , ("inst_ifaces", jsonArray (map jsonInstalledInterface ifInstalledIfaces)) + ] + +jsonInstalledInterface :: InstalledInterface -> JsonDoc +jsonInstalledInterface InstalledInterface{..} = jsonObject properties + where + properties = + [ ("module" , jsonModule instMod) + , ("is_sig" , jsonBool instIsSig) + , ("info" , jsonHaddockModInfo instInfo) + , ("doc_map" , jsonMap nameStableString jsonMDoc instDocMap) + , ("arg_map" , jsonMap nameStableString (jsonMap show jsonMDoc) instArgMap) + , ("exports" , jsonArray (map jsonName instExports)) + , ("visible_exports" , jsonArray (map jsonName instVisibleExports)) + , ("options" , jsonArray (map (jsonString . show) instOptions)) + , ("sub_map" , jsonMap nameStableString (jsonArray . map jsonName) instSubMap) + , ("bundled_patsyns" , jsonMap nameStableString (jsonArray . map jsonName) instBundledPatSynMap) + , ("fix_map" , jsonMap nameStableString jsonFixity instFixMap) + ] + +jsonHaddockModInfo :: HaddockModInfo Name -> JsonDoc +jsonHaddockModInfo HaddockModInfo{..} = + jsonObject [ ("description" , jsonMaybe jsonDoc hmi_description) + , ("copyright" , jsonMaybe jsonString hmi_copyright) + , ("maintainer" , jsonMaybe jsonString hmi_maintainer) + , ("stability" , jsonMaybe jsonString hmi_stability) + , ("protability" , jsonMaybe jsonString hmi_portability) + , ("safety" , jsonMaybe jsonString hmi_safety) + , ("language" , jsonMaybe (jsonString . show) hmi_language) + , ("extensions" , jsonArray (map (jsonString . show) hmi_extensions)) + ] + +jsonMap :: (a -> String) -> (b -> JsonDoc) -> Map a b -> JsonDoc +jsonMap f g = jsonObject . map (f *** g) . Map.toList + +jsonMDoc :: MDoc Name -> JsonDoc +jsonMDoc MetaDoc{..} = + jsonObject [ ("meta", jsonObject [("version", jsonMaybe (jsonString . show) (_version _meta))]) + , ("doc", jsonDoc _doc) + ] + +jsonDoc :: Doc Name -> JsonDoc +jsonDoc doc = jsonString (show (bimap (moduleNameString . fst) nameStableString doc)) + +jsonModule :: Module -> JsonDoc +jsonModule = JSString . moduleStableString + +jsonName :: Name -> JsonDoc +jsonName = JSString . nameStableString + +jsonFixity :: Fixity -> JsonDoc +jsonFixity (Fixity _ prec dir) = + jsonObject [ ("prec" , jsonInt prec) + , ("direction" , jsonFixityDirection dir) + ] + +jsonFixityDirection :: FixityDirection -> JsonDoc +jsonFixityDirection InfixL = jsonString "infixl" +jsonFixityDirection InfixR = jsonString "infixr" +jsonFixityDirection InfixN = jsonString "infix" + +renderJson :: JsonDoc -> SDoc +renderJson = renderJSON + +jsonMaybe :: (a -> JsonDoc) -> Maybe a -> JsonDoc +jsonMaybe = maybe jsonNull + +jsonString :: String -> JsonDoc +jsonString = JSString + +jsonObject :: [(String, JsonDoc)] -> JsonDoc +jsonObject = JSObject + +jsonArray :: [JsonDoc] -> JsonDoc +jsonArray = JSArray + +jsonNull :: JsonDoc +jsonNull = JSNull + +jsonInt :: Int -> JsonDoc +jsonInt = JSInt + +jsonBool :: Bool -> JsonDoc +jsonBool = JSBool + diff --git a/haddock-api/src/Haddock/Options.hs b/haddock-api/src/Haddock/Options.hs index 0449c829..d73d1a79 100644 --- a/haddock-api/src/Haddock/Options.hs +++ b/haddock-api/src/Haddock/Options.hs @@ -25,6 +25,7 @@ module Haddock.Options ( sourceUrls, wikiUrls, optDumpInterfaceFile, + optShowInterfaceFile, optLaTeXStyle, optMathjax, qualification, @@ -53,6 +54,7 @@ data Flag -- | Flag_DocBook | Flag_ReadInterface String | Flag_DumpInterface String + | Flag_ShowInterface String | Flag_Heading String | Flag_Html | Flag_Hoogle @@ -112,6 +114,8 @@ options backwardsCompat = "read an interface from FILE", Option ['D'] ["dump-interface"] (ReqArg Flag_DumpInterface "FILE") "write the resulting interface to FILE", + Option [] ["show-interface"] (ReqArg Flag_ShowInterface "FILE") + "print the interface in a human readable form", -- Option ['S'] ["docbook"] (NoArg Flag_DocBook) -- "output in DocBook XML", Option ['h'] ["html"] (NoArg Flag_Html) @@ -270,6 +274,8 @@ wikiUrls flags = optDumpInterfaceFile :: [Flag] -> Maybe FilePath optDumpInterfaceFile flags = optLast [ str | Flag_DumpInterface str <- flags ] +optShowInterfaceFile :: [Flag] -> Maybe FilePath +optShowInterfaceFile flags = optLast [ str | Flag_ShowInterface str <- flags ] optLaTeXStyle :: [Flag] -> Maybe String optLaTeXStyle flags = optLast [ str | Flag_LaTeXStyle str <- flags ] diff --git a/haddock-library/CHANGES.md b/haddock-library/CHANGES.md index bebb9982..c52908e1 100644 --- a/haddock-library/CHANGES.md +++ b/haddock-library/CHANGES.md @@ -1,3 +1,9 @@ +## Changes in version 1.4.6 + + * to be released + + * Bifunctor instance for DocH + ## Changes in version 1.4.5 * Move markup related data types to haddock-library diff --git a/haddock-library/src/Documentation/Haddock/Types.hs b/haddock-library/src/Documentation/Haddock/Types.hs index 0ab6bb4c..22cab425 100644 --- a/haddock-library/src/Documentation/Haddock/Types.hs +++ b/haddock-library/src/Documentation/Haddock/Types.hs @@ -19,6 +19,11 @@ import Data.Foldable import Data.Traversable #endif +#if MIN_VERSION_base(4,8,0) +import Control.Arrow ((***)) +import Data.Bifunctor +#endif + -- | With the advent of 'Version', we may want to start attaching more -- meta-data to comments. We make a structure for this ahead of time -- so we don't have to gut half the core each time we want to add such @@ -81,6 +86,33 @@ data DocH mod id | DocHeader (Header (DocH mod id)) deriving (Eq, Show, Functor, Foldable, Traversable) +#if MIN_VERSION_base(4,8,0) +instance Bifunctor DocH where + bimap _ _ DocEmpty = DocEmpty + bimap f g (DocAppend docA docB) = DocAppend (bimap f g docA) (bimap f g docB) + bimap _ _ (DocString s) = DocString s + bimap f g (DocParagraph doc) = DocParagraph (bimap f g doc) + bimap _ g (DocIdentifier i) = DocIdentifier (g i) + bimap f _ (DocIdentifierUnchecked m) = DocIdentifierUnchecked (f m) + bimap _ _ (DocModule s) = DocModule s + bimap f g (DocWarning doc) = DocWarning (bimap f g doc) + bimap f g (DocEmphasis doc) = DocEmphasis (bimap f g doc) + bimap f g (DocMonospaced doc) = DocMonospaced (bimap f g doc) + bimap f g (DocBold doc) = DocBold (bimap f g doc) + bimap f g (DocUnorderedList docs) = DocUnorderedList (map (bimap f g) docs) + bimap f g (DocOrderedList docs) = DocOrderedList (map (bimap f g) docs) + bimap f g (DocDefList docs) = DocDefList (map (bimap f g *** bimap f g) docs) + bimap f g (DocCodeBlock doc) = DocCodeBlock (bimap f g doc) + bimap _ _ (DocHyperlink hyperlink) = DocHyperlink hyperlink + bimap _ _ (DocPic picture) = DocPic picture + bimap _ _ (DocMathInline s) = DocMathInline s + bimap _ _ (DocMathDisplay s) = DocMathDisplay s + bimap _ _ (DocAName s) = DocAName s + bimap _ _ (DocProperty s) = DocProperty s + bimap _ _ (DocExamples examples) = DocExamples examples + bimap f g (DocHeader (Header level title)) = DocHeader (Header level (bimap f g title)) +#endif + -- | 'DocMarkupH' is a set of instructions for marking up documentation. -- In fact, it's really just a mapping from 'Doc' to some other -- type [a], where [a] is usually the type of the output (HTML, say). @@ -114,4 +146,3 @@ data DocMarkupH mod id a = Markup , markupExample :: [Example] -> a , markupHeader :: Header a -> a } - diff --git a/haddock.cabal b/haddock.cabal index 36c80f33..5ae3443c 100644 --- a/haddock.cabal +++ b/haddock.cabal @@ -106,6 +106,7 @@ executable haddock Documentation.Haddock Haddock Haddock.Interface + Haddock.Interface.Json Haddock.Interface.Rename Haddock.Interface.Create Haddock.Interface.AttachInstances -- cgit v1.2.3