on master help sign in
Apply suggestions from code review
7f673c4poprox
tutorials/arvo/parsing.md+13−9
@@ -236,7 +236,7 @@ and returns a `rule`.
236### `+cold`
236### `+cold`
237
237
238`+cold` is a `rule` builder that takes in a constant noun we'll call `cus` and a
238`+cold` is a `rule` builder that takes in a constant noun we'll call `cus` and a
239−`rule` we'll call `sef` and returns a `rule` identical to the `sef` except it
239+`rule` we'll call `sef`. It returns a `rule` identical to the `sef` except it
240replaces the parsing result with `cus`.
240replaces the parsing result with `cus`.
241
241
242Here we see that `p.q` of the `edge` returned by the `rule` created with `+cold`
242Here we see that `p.q` of the `edge` returned by the `rule` created with `+cold`
@@ -267,8 +267,8 @@ utilizes parsers. That is to say, you'd like the programmer to only worry about
267passing `tape`s to the parser, and not have to dress up the `tape` as a `nail`
267passing `tape`s to the parser, and not have to dress up the `tape` as a `nail`
268themselves. Thus we have several functions for exactly this purpose.
268themselves. Thus we have several functions for exactly this purpose.
269
269
270−These functions take in either a `tape` or an `@` (typically representing a
270+These functions take in either a `tape` or a `cord`,
271−`cord`) with a `rule` and attempts to parse the input with the `rule`. If the
271+alongside a `rule`, and attempt to parse the input with the `rule`. If the
272parse succeeds, it returns the result. There are crashing and unitized versions
272parse succeeds, it returns the result. There are crashing and unitized versions
273of each caller, corresponding to what happens when a parse fails.
273of each caller, corresponding to what happens when a parse fails.
274
274
@@ -486,8 +486,11 @@ to write the above `rule` is as follows:
486++ pars
486++ pars
487 |-
487 |-
488 ;~ plug prn
488 ;~ plug prn
489+ ;~ pose
489− ;~ pose knee *tape
490+ (knee *tape |.(^$))
490− |. ^$ (easy ~)
491+ (easy ~)
492+ ==
493+ ==
491```
494```
492
495
493You may want to utilize the `~+` rune when writing recursive parsers to cache
496You may want to utilize the `~+` rune when writing recursive parsers to cache
@@ -516,12 +519,12 @@ First lets look at the code we're going to use, and then dive into explaining
516it. If you'd like to follow along, save the following as `expr-parse.hoon` in
519it. If you'd like to follow along, save the following as `expr-parse.hoon` in
517your `gen/` folder.
520your `gen/` folder.
518```hoon
521```hoon
519−:: expr-parse: parse arithmetic expressions
522+:: expr-parse: parse arithmetic expressions
520::
523::
521|= xprs=tape
524|= xprs=tape
522|^ (scan xprs tape)
525|^ (scan xprs tape)
523++ factor
526++ factor
524− %+ knee @ud
527+ %+ knee *@ud
525 |. ~+
528 |. ~+
526 ;~ pose
529 ;~ pose
527 dem
530 dem
@@ -554,7 +557,8 @@ for expressions.
554```hoon
557```hoon
555++ factor
558++ factor
556 %+ knee @ud
559 %+ knee @ud
560+ |. ~+
557− |. ~+ ;~ pose
561+ ;~ pose
558 dem
562 dem
559 (ifix [lit rit] expr)
563 (ifix [lit rit] expr)
560 ==
564 ==
@@ -570,7 +574,7 @@ with `+pose`, which says to try each rule in succession until one of them works.
570
574
571Since expressions ultimately reduce to factors, we are actually building a
575Since expressions ultimately reduce to factors, we are actually building a
572recursive rule. Thus we need to make use of `+knee`. The first argument for
576recursive rule. Thus we need to make use of `+knee`. The first argument for
573−`+knee` is `@ud`, since our final answer should be a `@ud`.
577+`+knee` is `*@ud`, since our final answer should be a `@ud`.
574
578
575Then follows the definition of the gate utilized by `+knee`:
579Then follows the definition of the gate utilized by `+knee`:
576```hoon
580```hoon