> For the complete documentation index, see [llms.txt](https://docs.urbit.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.urbit.org/hoon/stdlib/4g.md).

# 4g: Parsing (Outside Caller)

Top-level parsing functions for parsing text from external sources.

## `+rash` <a href="#rash" id="rash"></a>

Parse or crash.

Parse a `$cord` with a given `$rule` and crash if the `$cord` isn't entirely parsed.

#### Accepts

`.naf` is an `$atom`.

`.sab` is a `$rule`.

#### Produces

The value of the parse result, or crash.

#### Source

```hoon
++  rash  |*([naf=@ sab=rule] (scan (trip naf) sab))
```

#### Examples

```
> (rash 'I was the world in which I walked, and what I saw' (star (shim 0 200)))
"I was the world in which I walked, and what I saw"
```

```
> (rash 'abc' (just 'a'))
! {1 2}
! 'syntax-error'
! exit
```

```
> (rash 'abc' (jest 'abc'))
'abc'
```

```
> (rash 'abc' (jest 'ab'))
! {1 3}
! 'syntax-error'
! exit
```

***

## `+rose` <a href="#rose" id="rose"></a>

Parse to each.

Parse `$tape` `.los` with `$rule` `sab`, producing an `(each @ud (unit *))`. If `.los` was not fully consumed, the result is `%.n` and `.p` contains the column number before failure occurred. If `.los` was fully consumed, the result is `%.y` and `.p` contains either `sab`'s result in a `+unit`, or a null `+unit` if parsing failed.

#### Accepts

`.los` is a `$tape`.

`.sab` is a `$rule`.

#### Produces

`(each @ud (unit *))`, where the `*` is whatever type the `$rule` produces.

#### Source

```hoon
++  rose  |*  [los=tape sab=rule]
          =+  vex=(sab [[1 1] los])
          =+  len=(lent los)
          ?.  =(+(len) q.p.vex)  [%| p=(dec q.p.vex)]
          ?~  q.vex
            [%& p=~]
          [%& p=[~ u=p.u.q.vex]]
```

#### Examples

```
> (rose "!" zap)
[%.y p=[~ u='!']]
```

```
> (rose "?" zap)
[%.n p=0]
```

```
> (rose "!?" zap)
[%.n p=1]
```

```
> (rose "!" ;~(plug zap fail))
[%.y p=~]
```

***

## `+rush` <a href="#rush" id="rush"></a>

Parse or null.

Parse an `$atom` with a given `$rule` and produce null if the `$cord` isn't entirely parsed.

#### Accepts

`.naf` is an `$atom`.

`.sab` is a `$rule`.

#### Produces

The value of the parse result, or null.

#### Source

```hoon
++  rush  |*([naf=@ sab=rule] (rust (trip naf) sab))
```

#### Examples

```
> (rush 'I was the world in which I walked, and what I saw' (star (shim 0 200)))
[~ "I was the world in which I walked, and what I saw"]
```

```
> (rush 'abc' (just 'a'))
~
```

```
> (rush 'abc' (jest 'abc'))
[~ 'abc']
```

```
> (rush 'abc' (jest 'ac'))
~
```

```
> (rush 'abc' (jest 'ab'))
~
```

***

## `+rust` <a href="#rust" id="rust"></a>

Parse `$tape` or null.

Parse a `$tape` with a given `$rule` and produce null if the `$tape` isn't entirely parsed.

#### Accepts

`.los` is a `$tape`.

`.sab` is a `$rule`.

#### Produces

A `(unit *)`, where `*` is the type produced by `.sab`.

#### Source

```hoon
++  rust  |*  [los=tape sab=rule]
          =+  vex=((full sab) [[1 1] los])
          ?~(q.vex ~ [~ u=p.u.q.vex])
```

#### Examples

```
> (rust "I was the world in which I walked, and what I saw" (star (shim 0 200)))
[~ "I was the world in which I walked, and what I saw"]
```

```
> (rust "Or heard or felt came not but from myself;" (star (shim 0 200)))
[~ "Or heard or felt came not but from myself;"]
```

```
> (rust "And there I found myself more truly and more strange." (jest 'And there I'))
~
```

***

## `+scan` <a href="#scan" id="scan"></a>

Parse `$tape` or crash.

Parse a `$tape` with a given `$rule` and crash if the `$tape` isn't entirely parsed.

#### Accepts

`.los` is a `$tape`.

`.sab` is a `$rule`.

#### Produces

Either the type produced by your parsing rules or a crash.

#### Source

```hoon
++  scan  |*  [los=tape sab=rule]
          =+  vex=((full sab) [[1 1] los])
          ?~  q.vex
            ~_  (show [%m '{%d %d}'] p.p.vex q.p.vex ~)
            ~_(leaf+"syntax error" !!)
          p.u.q.vex
```

#### Examples

```
> (scan "I was the world in which I walked, and what I saw" (star (shim 0 200)))
"I was the world in which I walked, and what I saw"
```

```
> (scan "Or heard or felt came not but from myself;" (star (shim 0 200)))
"Or heard or felt came not but from myself;"
```

```
> (scan "And there I found myself more truly and more strange." (jest 'And there I'))
! {1 12}
! 'syntax-error'
! exit
```

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.urbit.org/hoon/stdlib/4g.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
