From 8ab850528e1c05f36668f36db6af4cdcb647180e Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Sun, 20 Jun 2021 23:47:29 +0900 Subject: Add syntax of fragment --- spec/parser_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'spec/parser_test.go') 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 @@ -144,6 +150,29 @@ c: ; src: `;`, 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: ` -- cgit v1.2.3