on master help sign in
squash! Apply suggestions from code review
14fd434JONATHAN PAPROCKI
tutorials/arvo/parsing.md+16−13
@@ -39,16 +39,16 @@ that are plugged into one another in various ways to perform the desired task.
39
39
40The basic building blocks, or primitives, are parsers that read only a
40The basic building blocks, or primitives, are parsers that read only a
41single character. There are frequently a few types of possible input characters,
41single character. There are frequently a few types of possible input characters,
42−such as letters, numbers, and symbols. For example, `parse("1", integer)` calls
42+such as letters, numbers, and symbols. For example, `(parse "1" integer)` calls
43the parsing routine on the string `"1"` and looks for an integer, and so it
43the parsing routine on the string `"1"` and looks for an integer, and so it
44returns the integer `1`. However, taking into account what was said above about
44returns the integer `1`. However, taking into account what was said above about
45parsers returning the unparsed portion of the string as well, we should
45parsers returning the unparsed portion of the string as well, we should
46represent this return as a tuple. So we should expect something like this:
46represent this return as a tuple. So we should expect something like this:
47```
47```
48−> parse("1", integer)
48+> (parse "1" integer)
49−(1, "")
49+[1 ""]
50−> parse("123", integer)
50+> (parse "123" integer)
51−(1, "23")
51+[1 "23"]
52```
52```
53What if we wish to parse the rest of the string? We would need to apply the
53What if we wish to parse the rest of the string? We would need to apply the
54`parse` function again:
54`parse` function again:
@@ -57,6 +57,10 @@ What if we wish to parse the rest of the string? We would need to apply the
57(12, "3")
57(12, "3")
58> parse(parse(parse("123", integer), integer), integer)
58> parse(parse(parse("123", integer), integer), integer)
59(123, "")
59(123, "")
60+> (parse (parse "123" integer) integer)
61+[12 "3"]
62+> (parse (parse (parse "123" integer) integer) integer)
63+[123 ""]
60```
64```
61So we see that we can parse strings larger than one character by stringing
65So we see that we can parse strings larger than one character by stringing
62together parsing functions for single characters. Thus in addition to parsing
66together parsing functions for single characters. Thus in addition to parsing
@@ -179,9 +183,7 @@ parser has not advanced since parsing failed. `q.edg` is null, indicating that
179parsing has failed.
183parsing has failed.
180
184
181Later we will use [+star](#star) to string together a sequence of `+just`s in
185Later we will use [+star](#star) to string together a sequence of `+just`s in
182−order to parse multiple characters at once. However, it should be noted that
186+order to parse multiple characters at once.
183−`+jest`, which is covered next, ought to be used in favor of `+just`, which is
184−mostly included here for pedagogical reasons.
185
187
186### `+jest`
188### `+jest`
187
189
@@ -531,14 +533,14 @@ your `gen/` folder.
531 (ifix [lit rit] expr)
533 (ifix [lit rit] expr)
532 ==
534 ==
533++ turm
535++ turm
534− %+ knee @ud
536+ %+ knee *@ud
535 |. ~+
537 |. ~+
536 ;~ pose
538 ;~ pose
537 ((slug mul) tar ;~(pose factor turm))
539 ((slug mul) tar ;~(pose factor turm))
538 factor
540 factor
539 ==
541 ==
540++ expr
542++ expr
541− %+ knee @ud
543+ %+ knee *@ud
542 |. ~+
544 |. ~+
543 ;~ pose
545 ;~ pose
544 ((slug add) lus ;~(pose turm expr))
546 ((slug add) lus ;~(pose turm expr))
@@ -556,7 +558,7 @@ for expressions.
556
558
557```hoon
559```hoon
558++ factor
560++ factor
559− %+ knee @ud
561+ %+ knee *@ud
560 |. ~+
562 |. ~+
561 ;~ pose
563 ;~ pose
562 dem
564 dem
@@ -623,8 +625,9 @@ for expressions, we just need to swap `lus` for `tar`, `add` for `mul`, and
623
625
624```hoon
626```hoon
625++ expr
627++ expr
626− %+ knee *int
628+ %+ knee *@ud
629+ |. ~+
627− |. ~+ ;~ pose
630+ ;~ pose
628 ((slug add) lus ;~(pose turm expr))
631 ((slug add) lus ;~(pose turm expr))
629 turm
632 turm
630 ==
633 ==