initial (hacky af)

This commit is contained in:
2017-02-24 18:38:35 +01:00
commit ffeacdcb6c
8 changed files with 267 additions and 0 deletions

0
examples/__init__.py Normal file
View File

18
examples/bf.py Normal file
View File

@@ -0,0 +1,18 @@
import gll
def loop(string):
parser = gll.seq(gll.skip(gll.string("[")),
gll.many(op),
gll.skip(gll.string("]")),
tag="loop")
return parser(string)
op = (gll.string("+", tag="add") |
gll.string("-", tag="sub") |
gll.string(".", tag="out") |
gll.string(",", tag="in") |
gll.string(">", tag="fwd") |
gll.string("<", tag="bck") |
loop)
parser = gll.all(gll.many(op), tag="program")

9
examples/calc.py Normal file
View File

@@ -0,0 +1,9 @@
import gll
ws = gll.skipmany(gll.whitespace(), tag="spaces")
num = gll.many1(gll.digit(), tag="number")
op = gll.string("+", tag="op") | gll.string("-", tag="op")
expr = gll.seq(num, ws, op, ws, num, tag="expr")
parser = gll.many(expr)

13
examples/golike.py Normal file
View File

@@ -0,0 +1,13 @@
import gll
ws = gll.many(gll.whitespace)
function = function
package_name = gll.seq(gll.skip(gll.string("package")), gl.skip(ws),
gll.regex(".*$"), tag="package_name")
package = gll.seq(package_name, gll.many(function, tag="package_body"),
tag="package")
parser = gll.all(package)