Skip to content

Commit

Permalink
Rename, test, fix, and document the LL(1) parser combinator library (#…
Browse files Browse the repository at this point in the history
…1063)

std/text/basic-parsers => std/parser/ll1
  • Loading branch information
fare authored Dec 4, 2023
1 parent b060fb9 commit 32c3054
Show file tree
Hide file tree
Showing 12 changed files with 949 additions and 283 deletions.
8 changes: 8 additions & 0 deletions doc/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ module.exports = {
]
},

{ title: "Text Parser Libraries",
path: "/reference/std/parser/",
children: [
"parser/",
"parser/ll1"
]
},

{ title: "Text Encoding and Decoding Libraries",
path: "/reference/std/text/",
children: [
Expand Down
24 changes: 20 additions & 4 deletions doc/reference/std/misc/decimal.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,30 @@ i.e. a rational number that is not a floating-point number.
exponent-allowed: (exponent-allowed_ #f)) -> decimal
```

`parse-decimal` expects and parses a decimal number on an `input`,
`parse-decimal` parses a decimal number on a `input`
with the options specifed via keyword arguments.

The `input` will be cast to a `BufferedStringReader` using
The `input` can be a string, input port, BufferedStringReader, StringReader, or Reader,
and will be cast to a `BufferedStringReader` using
[`open-buffered-string-reader`](../stdio.md#open-buffered-string-reader).
`parse-decimal` will then side-effect this reader as it parses,
and finally return the decimal number,
or raises a `parse-error` (from `:std/parser/base`).
or raise a `parse-error` (from `:std/parser/base`).

The options are as for `ll1-decimal` below.

## ll1-decimal
```scheme
(ll1-decimal
reader
sign-allowed?: (sign-allowed? #t)
decimal-mark: (decimal-mark #\.)
group-separator: (group-separator_ #f)
exponent-allowed: (exponent-allowed_ #f)) -> decimal
```
`parse-decimal` parses a decimal number from a `reader` object
that satisfies the `PeekableStringReader` interface,
with the options specifed via keyword arguments.

The keyword arguments `decimal-mark` and `group-separator` are each a character or false,
and specify optional allowed decimal mark and group separator characters,
Expand All @@ -87,7 +103,7 @@ before and/or after calling `parse-decimal`.

`: PeekableStringReader sign-allowed?:Bool decimal-mark:Char group-separator:(Or Char Bool) exponent-allowed:(or Bool String) -> Decimal`

You may use utilities from [:std/text/basic-parsers](../text/basic-parsers.md)
You may use utilities from [:std/parser/ll1](../parser/ll1.md)
to parse decimals as part of something bigger, or just use `string->decimal` below.

## string->decimal
Expand Down
7 changes: 7 additions & 0 deletions doc/reference/std/parser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The Parser Library

Gerbil comes with a variety of tools for parsing.
For the main parser interface see [std/parser](../parser).

But for the most simple parsing needs, you may want to use our
LL(1) parser library [std/parser/ll1](ll1).
Loading

0 comments on commit 32c3054

Please sign in to comment.