Resources for writing a parser/lexer

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. :wink:

Example input:

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)
}
}

1 Like

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.

1 Like

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.

2 Likes

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

2 Likes

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

You may find Lerche 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 API so it shouldn’t change.

I am successfully using it for a reasonably complicated grammar .

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.

1 Like

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.

2 Likes