22
33[ ![ Continuous Integration status] [ status-png ]] [ status ]
44[ ![ Hackage page (downloads and API reference)] [ hackage-png ]] [ hackage ]
5- [ ![ Hackage-Deps] [ hackage-deps-png ]] [ hackage-deps ]
65
76
87optparse-applicative is a haskell library for parsing options on
@@ -1043,20 +1042,20 @@ and the `pure` value should instead be wrapped parenthetically).
10431042 ```
10441043
10451044## How it works
1046- An applicative `Parser ` is essentially a heterogeneous list or tree
1047- of `Option `s, implemented with existential types.
10481045
1049- All options are therefore known statically (i. e. before parsing,
1050- not necessarily before runtime), and can, for example, be traversed
1051- to generate a help text. Indeed , when displaying the usage text for
1052- a parser, we use an intermediate tree structure.
1046+ An applicative `Parser ` is essentially a heterogeneous tree of
1047+ `Option `s, made type safe using a technique called _existential types_.
10531048
1054- When we examine the user's input, each argument is examined to
1055- determine if it's an option or flag, or a positional argument. The
1056- parse tree is then searched for a matching term, and if it finds
1057- one, that leaf of the tree is replaced with the value itself. When
1058- all input has been processed, we see if we can generate the complete
1059- value, and if not issue an error .
1049+ All options are therefore known before we parse any user input, and
1050+ can be traversed to generate a help text and any command line completions
1051+ required.
1052+
1053+ When we examine the user's input, the terms are checked if they're an
1054+ option or flag, as opposed to a positional argument. The `Parser ` tree
1055+ is then searched for a matching term, and if it finds one, that leaf
1056+ of the tree is replaced with the value provided. When all input has been
1057+ processed, we see if we can generate the complete value, and if not ,
1058+ issue an error .
10601059
10611060See [this blog post][blog] for a more detailed explanation based on a
10621061simplified implementation.
@@ -1077,8 +1076,6 @@ These are some tutorials found on the web:
10771076 [blog]: http:// paolocapriotti. com/ blog/ 2012 / 04 / 27 / applicative- option- parser/
10781077 [hackage]: http:// hackage. haskell. org/ package/ optparse- applicative
10791078 [hackage- png]: http:// img. shields. io/ hackage/ v/ optparse- applicative. svg
1080- [hackage- deps]: http:// packdeps. haskellers. com/ reverse / optparse- applicative
1081- [hackage- deps- png]: https:// img. shields. io/ hackage- deps/ v/ optparse- applicative. svg
10821079 [monoid]: http:// hackage. haskell. org/ package/ base/ docs/ Data - Monoid. html
10831080 [semigroup]: http:// hackage. haskell. org/ package/ base/ docs/ Data - Semigroup. html
10841081 [parsec]: http:// hackage. haskell. org/ package/ parsec
0 commit comments