aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md12
-rw-r--r--spec/test/parser.go3
-rw-r--r--spec/test/parser_test.go52
3 files changed, 8 insertions, 59 deletions
diff --git a/README.md b/README.md
index 9c8d649..af7d693 100644
--- a/README.md
+++ b/README.md
@@ -132,11 +132,11 @@ a / b * 100
---
(expr
(expr
- (expr (id))
- (div)
- (expr (id)))
- (mul)
- (expr (int)))
+ (expr (id 'a'))
+ (div '/')
+ (expr (id 'b')))
+ (mul '*')
+ (expr (int '100')))
```
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).
@@ -150,8 +150,6 @@ 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.
-The underscore `_` allows you to match any symbols. Thus `(expr (expr (id)) (_) (expr (id)))` matches `a + b`, `a - b`, and so on.
-
### 5. Generate a parser
Using `vartan-go` command, you can generate a source code of a parser to recognize your grammar.
diff --git a/spec/test/parser.go b/spec/test/parser.go
index e9c557d..aa5d022 100644
--- a/spec/test/parser.go
+++ b/spec/test/parser.go
@@ -99,8 +99,7 @@ func DiffTree(expected, actual *Tree) []*TreeDiff {
if expected == nil && actual == nil {
return nil
}
- // _ matches any symbols.
- if expected.Kind != "_" && actual.Kind != expected.Kind {
+ if actual.Kind != expected.Kind {
msg := fmt.Sprintf("unexpected kind: expected '%v' but got '%v'", expected.Kind, actual.Kind)
return []*TreeDiff{
newTreeDiff(expected, actual, msg),
diff --git a/spec/test/parser_test.go b/spec/test/parser_test.go
index cbf96c0..a12c858 100644
--- a/spec/test/parser_test.go
+++ b/spec/test/parser_test.go
@@ -75,26 +75,6 @@ func TestDiffTree(t *testing.T) {
),
},
{
- t1: NewNonTerminalTree("_"),
- t2: NewNonTerminalTree("a"),
- },
- {
- t1: NewNonTerminalTree("a",
- NewNonTerminalTree("_"),
- ),
- t2: NewNonTerminalTree("a",
- NewNonTerminalTree("b"),
- ),
- },
- {
- t1: NewNonTerminalTree("_",
- NewNonTerminalTree("b"),
- ),
- t2: NewNonTerminalTree("a",
- NewNonTerminalTree("b"),
- ),
- },
- {
t1: NewNonTerminalTree("a"),
t2: NewNonTerminalTree("b"),
different: true,
@@ -159,35 +139,6 @@ func TestDiffTree(t *testing.T) {
),
different: true,
},
- {
- t1: NewNonTerminalTree("a",
- NewNonTerminalTree("_"),
- NewNonTerminalTree("c"),
- ),
- t2: NewNonTerminalTree("a",
- NewNonTerminalTree("b"),
- NewNonTerminalTree("x"),
- ),
- different: true,
- },
- {
- t1: NewNonTerminalTree("_"),
- t2: NewNonTerminalTree("a",
- NewNonTerminalTree("b"),
- ),
- different: true,
- },
- {
- t1: NewNonTerminalTree("a",
- NewNonTerminalTree("_"),
- ),
- t2: NewNonTerminalTree("a",
- NewNonTerminalTree("b",
- NewNonTerminalTree("c"),
- ),
- ),
- different: true,
- },
}
for i, tt := range tests {
t.Run(fmt.Sprintf("#%v", i), func(t *testing.T) {
@@ -398,12 +349,13 @@ foo x
`,
parseErr: true,
},
+ // The error node cannot have another node.
{
src: `test
----
foo x
----
-(foo (error (_ (x 'x'))))
+(foo (error (a)))
`,
parseErr: true,
},