aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-08-02 22:03:12 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-08-02 22:06:00 +0900
commitd8a13197900a62b0ff35e57779bf8f54756b559e (patch)
tree6ef32535403685e9aff942a2062510fe53ec102f /README.md
parentPrint expected terminals on a parse error (diff)
downloadurubu-d8a13197900a62b0ff35e57779bf8f54756b559e.tar.gz
urubu-d8a13197900a62b0ff35e57779bf8f54756b559e.tar.xz
Update README
Diffstat (limited to 'README.md')
-rw-r--r--README.md75
1 files changed, 73 insertions, 2 deletions
diff --git a/README.md b/README.md
index 3ba2d50..c3c6fc1 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,80 @@
# vartan
-vartan provides a compiler that generates a parsing table and a driver for golang.
+vartan provides a compiler that generates a SLR parsing table and a driver for golang.
[![Test](https://github.com/nihei9/vartan/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/nihei9/vartan/actions/workflows/test.yml)
## Status
-Now Developing
+🚧 Now Developing
+
+## Installation
+
+```sh
+$ go install github.com/nihei9/vartan/cmd/vartan@latest
+```
+
+## Usage
+
+vartan uses BNF-like DSL to define your grammar. As an example, let's write a grammar that represents a simple expression.
+
+```
+expr
+ : expr add_op term
+ | term
+ ;
+term
+ : term mul_op factor
+ | factor
+ ;
+factor
+ : number
+ | id
+ ;
+
+whitespaces: "[\u{0009}\u{0020}]+" #skip;
+number: "[0-9]+";
+id: "[A-Za-z_]+";
+add_op: '+';
+mul_op: '*';
+```
+
+Save the above grammar to a file in UTF-8. In this explanation, the file name is `expr.vr`.
+
+Next, generate a parsing table using `vartan compile` command.
+
+```sh
+$ vartan compile -g expr.vr -o expr.json
+```
+
+If you want to make sure that the grammar behaves as expected, you can use `vartan parse` command to try parse without implementing a driver.
+
+⚠️ An encoding that `vartan parse` command and the driver can handle is only UTF-8.
+
+```sh
+$ echo -n 'foo + bar * baz * 100 ' | vartan parse expr.json
+Accepted
+expr
+├─ expr
+│ └─ term
+│ └─ factor
+│ └─ id "foo"
+├─ add_op "+"
+└─ term
+ ├─ term
+ │ ├─ term
+ │ │ └─ factor
+ │ │ └─ id "bar"
+ │ ├─ mul_op "*"
+ │ └─ factor
+ │ └─ id "baz"
+ ├─ mul_op "*"
+ └─ factor
+ └─ number "100"
+```
+
+When `vartan parse` command successfully parses the input data, it prints a CST or an AST (if any).
+
+## Debug
+
+`vartan compile` command also generates a description file having `.desc` suffix along with a parsing table. This file describes each state in the parsing table in detail. If your grammar contains conflicts, see `Conflicts` section of this file.