# 4g: Parsing (Outside Caller)

## `+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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
