# Resources for writing a parser/lexer

**URL:** https://discourse.julialang.org/t/resources-for-writing-a-parser-lexer/47355
**Category:** General Usage
**Created:** [September 27, 2020, 9:53am UTC](https://discourse.julialang.org/t/resources-for-writing-a-parser-lexer/47355 "2020-09-27T09:53:37Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [September 27, 2020, 9:53am UTC](https://discourse.julialang.org/t/resources-for-writing-a-parser-lexer/47355/1 "2020-09-27T09:53:37Z")

</div>

Hi I have to write a parser for a simple Syntax and I was wondering if there are already resources to help me do that.

Any hints are welcome. 😉

Example input:

```julia
group=name {
Section1 {
key1 = value1
key2 = value2, value3
key3(args) = value5
}
Section2
{
key1(args)= table (
value1, value2;
value3, value4;)
entry"d"(args)(x=1, y=2)
}
}

```

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [September 27, 2020, 10:28am UTC](https://discourse.julialang.org/t/resources-for-writing-a-parser-lexer/47355/2 "2020-09-27T10:28:58Z")

</div>

Why don’t you use an existing file format instead of rolling your own? TOML is built into Julia, but there are also other (JSON, YAML, etc). Otherwise those packages could be inspirations for you.

---

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [September 27, 2020, 10:41am UTC](https://discourse.julialang.org/t/resources-for-writing-a-parser-lexer/47355/3 "2020-09-27T10:41:30Z")

</div>

I want to use an external program which takes this kind of format as an input. The parser would help with reusing/modifying the already existing files, which are quite long.

I’ll take a look at the mentioned projects. Let’s see if I can find some common strategy, which I can reuse.

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [September 27, 2020, 8:11pm UTC](https://discourse.julialang.org/t/resources-for-writing-a-parser-lexer/47355/4 "2020-09-27T20:11:30Z")

</div>

I haven’t used it, but I have high hopes for

[https://github.com/gkappler/CombinedParsers.jl](https://github.com/gkappler/CombinedParsers.jl)

---

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [September 27, 2020, 10:50pm UTC](https://discourse.julialang.org/t/resources-for-writing-a-parser-lexer/47355/5 "2020-09-27T22:50:39Z")

</div>

This looks very interesting, although I can’t grab the full concept yet.

---

<div class="post-metadata">

### Author: ![frtps](https://avatars.discourse-cdn.com/v4/letter/f/73ab20/32.png) [@frtps](https://discourse.julialang.org/u/frtps)
#### Post date: [September 30, 2020, 12:41am UTC](https://discourse.julialang.org/t/resources-for-writing-a-parser-lexer/47355/6 "2020-09-30T00:41:16Z")

</div>

You may find [Lerche](https://github.com/jamesrhester/Lerche.jl) useful. It reads an EBNF for your grammar to create a parser. Rules provided by you for traversing and transforming the resultant parse tree are then applied. Lerche is only version 0.1 but the API is designed to match the [Lark](https://github.com/lark-parser/lark) API so it shouldn’t change.

I am successfully using it for [a reasonably complicated grammar](https://github.com/jamesrhester/CIF_dREL.jl/blob/master/src/lark_grammar.ebnf) .

There are certainly opportunities for speed improvement in Lerche. As a workaround, you can see from the linked project that it is possible to simply serialise the generated parser.

---

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [October 1, 2020, 7:55am UTC](https://discourse.julialang.org/t/resources-for-writing-a-parser-lexer/47355/7 "2020-10-01T07:55:27Z")

</div>

I managed to write a small parser using CombinedParsers.  
I have to say it works quite well.

Also I saw that there is an issue for adding a macro, which can import EBNF grammar.
