Merge pull request #387 from urbit/sigilante-less

Document +less in parsing tutorial.
This commit is contained in:
Sigilante 2023-06-18 18:16:40 -05:00 committed by GitHub
commit ba63e44a7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -274,6 +274,25 @@ One common scenario where `+cold` sees play is when writing [command line
interface (CLI) apps](/guides/additional/cli-tutorial). We usher the
reader there to find an example where `+cold` is used.
### [`+less`](/reference/hoon/stdlib/4f/#less)
`+less` builds a `rule` to exclude matches to its first argument. It is commonly
used to filter out an undesired match.
```
> (;~(less buc next) [[1 1] " "])
[p=[p=1 q=2] q=[~ [p=' ' q=[p=[p=1 q=2] q=""]]]]
> (;~(less ace next) [[1 1] " "])
[p=[p=1 q=1] q=~]
```
Here we see that the first case refuses to parse `buc` `$` (which is not present), so
the `ace` ` ` succeeds (via `+next` which matches any character).
The second case attempts to parse the excluded character `ace` ` ` and fails on the
first character as it should.
### [`+knee`](/reference/hoon/stdlib/4f/#knee)
Another important function in the parser builder library is `+knee`, used for building