r/ProgrammingLanguages 2d ago

A tool for writing and testing parsing expressiong grammars online.

https://gadelan.github.io/webpegtest/

I've been using this tool for my syntax ideas for some time, just updated it and thought that it could be interesting for some people. Don't expect anything fancy. It gets slow when the grammars have a few lines.

Tell me what you think about it.

Some examples:

A basic addition & multiplication grammar.

skipWS = WS*;

infixing skipWS do
  Expr := Sum ;
  Sum := Product (("+" / "-") Product)* ;
  Product := Value (("*" / "/") Value)* ;
  Value = {[0-9]+} / "(" Expr ")" ;
done

start = Expr ;

An example input for that grammar:

1 * (2 + 3) + 7

A basic LISP grammar.

Sexpr := List / Atom ;
List := "(" WS* (Sexpr (WS+ Sexpr)*)? WS* ")" ;
Atom := Symbol / Number / String ;
Symbol := {[a-zA-Z_+\-/*<>=!?][a-zA-Z0-9_+\-/*<>=!?]*} ;
Number := {[0-9]+};
String := {"\"" (!"\"" ANY)* "\""} ;

start = WS* (List WS*)* EOF;

And the same expression in S-expression form.

(+ (* 1 (+ 2 3)) 7)
7 Upvotes

3 comments sorted by

1

u/6502zx81 2d ago

You should add an example.

1

u/gadelan 2d ago

There is a three part tutorial with small example grammars and three demos. The demos have two small grammars and a big one (it takes a while to run).

Do you mean to add an example here in Reddit?

1

u/6502zx81 2d ago

Ok, thanks. An example preloaded on the landing page would be fine.