Docs: add section on built-in parsers to Parsing-Input

This commit is contained in:
Mark Harrah 2013-09-30 09:03:39 -04:00
parent c8638c405c
commit f8a1d2ca7b
1 changed files with 16 additions and 2 deletions

View File

@ -15,9 +15,9 @@ Parser combinators build up a parser from smaller parsers. A
`String => Option[T]`. It accepts a `String` to parse and produces a
value wrapped in `Some` if parsing succeeds or `None` if it fails.
Error handling and tab completion make this picture more complicated,
but we'll stick with Option for this discussion.
but we'll stick with `Option` for this discussion.
The following examples assume the imports:
The following examples assume the imports: ::
import sbt._
import complete.DefaultParsers._
@ -54,6 +54,20 @@ from a `Char` or `String`. Other basic parser constructors are the
// The argument is the error message.
val alwaysFail: Parser[Nothing] = failure("Invalid input.")
Built-in parsers
----------------
sbt comes with several built-in parsers defined in `sbt.complete.DefaultParsers <../../api/sbt/complete/DefaultParsers$.html>`_.
Some commonly used built-in parsers are:
* `Space`, `NotSpace`, `OptSpace`, and `OptNotSpace` for parsing spaces or non-spaces, required or not.
* `StringBasic` for parsing text that may be quoted.
* `IntBasic` for parsing a signed Int value.
* `Digit` and `HexDigit` for parsing a single decimal or hexadecimal digit.
* `Bool` for parsing a `Boolean` value
See the `DefaultParsers API <../../api/sbt/complete/DefaultParsers$.html>`_ for details.
Combining parsers
-----------------