aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2022-05-19 00:20:05 +0900
committerRyo Nihei <nihei.dev@gmail.com>2022-05-29 14:38:41 +0900
commitceb6649d3fb8b85ac8629a65dcfb9533763f4af0 (patch)
treeaa787ce3571dc6cd33a7fdcfb48f81c950082ac1 /README.md
parentRename spec package to spec/grammar package (diff)
downloadcotia-ceb6649d3fb8b85ac8629a65dcfb9533763f4af0.tar.gz
cotia-ceb6649d3fb8b85ac8629a65dcfb9533763f4af0.tar.xz
Add vartan-test command
Diffstat (limited to 'README.md')
-rw-r--r--README.md31
1 files changed, 30 insertions, 1 deletions
diff --git a/README.md b/README.md
index 900fa28..3d9e5f5 100644
--- a/README.md
+++ b/README.md
@@ -121,7 +121,36 @@ When `vartan parse` command successfully parses the input data, it prints a CST
$ vartan show expr-report.json
```
-### 4. Generate a parser
+### 4. Test
+
+`vartan-test` command allows you to test whether your grammar recognizes an input text as a syntax tree with an expected structure. To do so, you need to define a test case as follows.
+
+```
+This is an example.
+---
+a / b * 100
+---
+(expr
+ (expr
+ (expr (id))
+ (div)
+ (expr (id)))
+ (mul)
+ (expr (int)))
+```
+
+The test case consists of a description, an input text, and a syntax tree you expect. Each part is separated by the delimiter `---`. The syntax tree is represented by the syntax like an [S-expression](https://en.wikipedia.org/wiki/S-expression).
+
+Save the above test case to `test.txt` file and run the following command.
+
+```sh
+$ vartan-test expr.vartan test.txt
+Passed test.txt
+```
+
+When you specify a directory as the 2nd argument of `vartan-test` command, it will run all test cases in the directory.
+
+### 5. Generate a parser
Using `vartan-go` command, you can generate a source code of a parser to recognize your grammar.