From ceb6649d3fb8b85ac8629a65dcfb9533763f4af0 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Thu, 19 May 2022 00:20:05 +0900 Subject: Add vartan-test command --- README.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'README.md') 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. -- cgit v1.2.3