diff options
Diffstat (limited to 'spec/parser_test.go')
-rw-r--r-- | spec/parser_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/parser_test.go b/spec/parser_test.go index 2060079..bacd2cb 100644 --- a/spec/parser_test.go +++ b/spec/parser_test.go @@ -47,6 +47,12 @@ func TestParse(t *testing.T) { Pattern: p, } } + fragment := func(lhs string, rhs string) *FragmentNode { + return &FragmentNode{ + LHS: lhs, + RHS: rhs, + } + } tests := []struct { caption string @@ -145,6 +151,29 @@ c: ; synErr: synErrNoProductionName, }, { + caption: "a grammar can contain fragments", + src: ` +s + : tagline + ; +tagline: "\f{words} IS OUT THERE."; +fragment words: "[A-Za-z\u{0020}]+"; +`, + ast: &RootNode{ + Productions: []*ProductionNode{ + production("s", + alternative(id("tagline")), + ), + production("tagline", + alternative(pattern(`\f{words} IS OUT THERE.`)), + ), + }, + Fragments: []*FragmentNode{ + fragment("words", `[A-Za-z\u{0020}]+`), + }, + }, + }, + { caption: "a grammar can contain production modifiers and semantic actions", src: ` mode_tran_seq |