# How do I make this parser recursive?

**URL:** https://discourse.elm-lang.org/t/how-do-i-make-this-parser-recursive/5017
**Category:** Learn
**Created:** [January 15, 2020, 11:36pm UTC](https://discourse.elm-lang.org/t/how-do-i-make-this-parser-recursive/5017 "2020-01-15T23:36:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Sebastian](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/sebastian/32/98_2.png) [@Sebastian](https://discourse.elm-lang.org/u/Sebastian)
#### Post date: [January 15, 2020, 11:36pm UTC](https://discourse.elm-lang.org/t/how-do-i-make-this-parser-recursive/5017/1 "2020-01-15T23:36:03Z")

</div>

I want to make a parser that can handle a recursive data structure. E.g.

`["a", ["b"]]`

`["a", ["b", ["c", "d"]]]`

Here is my attempt [https://ellie-app.com/7MdkFhPYmTDa1](https://ellie-app.com/7MdkFhPYmTDa1)

The first example above should parse into `AstList [AstVal "a", AstList [AstVal "b"] ]`

In `listParser` I tried setting `item = parser`, but the compiler complains with:

```
The `listParser` value depends on itself through the following chain of
definitions:

    ┌─────┐
    │ listParser
    │ ↓
    │ parser
    └─────┘

```

How can I make this parser recursive? Thanks

---

<div class="post-metadata">

### Author: ![choonkeat](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/choonkeat/32/1555_2.png) [@choonkeat](https://discourse.elm-lang.org/u/choonkeat)
#### Post date: [January 16, 2020, 7:48am UTC](https://discourse.elm-lang.org/t/how-do-i-make-this-parser-recursive/5017/2 "2020-01-16T07:48:45Z")

</div>

You are looking for [Parser.lazy](https://package.elm-lang.org/packages/elm/parser/latest/Parser#lazy) ?

---

<div class="post-metadata">

### Author: ![Sebastian](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/sebastian/32/98_2.png) [@Sebastian](https://discourse.elm-lang.org/u/Sebastian)
#### Post date: [January 16, 2020, 10:11pm UTC](https://discourse.elm-lang.org/t/how-do-i-make-this-parser-recursive/5017/3 "2020-01-16T22:11:04Z")

</div>

That was it, so simple, thanks  
[https://ellie-app.com/7MF2kDtLF83a1](https://ellie-app.com/7MF2kDtLF83a1)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)
#### Post date: [January 26, 2020, 10:11pm UTC](https://discourse.elm-lang.org/t/how-do-i-make-this-parser-recursive/5017/4 "2020-01-26T22:11:06Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
