From d45e0aa84a5c25bd1eb85931499e643c9a5a7771 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Thu, 13 Feb 2020 11:05:00 +1100 Subject: [PATCH] Export the buildf grammar func --- wbnf/compile.go | 4 ++-- wbnf/grammar_test.go | 4 ++-- wbnf/node_test_complex.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wbnf/compile.go b/wbnf/compile.go index c14b204..eeabd05 100644 --- a/wbnf/compile.go +++ b/wbnf/compile.go @@ -222,7 +222,7 @@ func buildProd(p ProdNode) parser.Term { return seq } -func buildGrammar(node ast.Node) parser.Grammar { +func NewFromAst(node ast.Node) parser.Grammar { g := parser.Grammar{} tree := NewGrammarNode(node) for _, stmt := range tree.AllStmt() { @@ -241,7 +241,7 @@ func Compile(grammar string) (parser.Parsers, error) { if err := validate(node); err != nil { return parser.Parsers{}, err } - g := buildGrammar(node) + g := NewFromAst(node) return g.Compile(node), nil } diff --git a/wbnf/grammar_test.go b/wbnf/grammar_test.go index 52a7cac..dd6b272 100644 --- a/wbnf/grammar_test.go +++ b/wbnf/grammar_test.go @@ -214,7 +214,7 @@ func TestTinyGrammarGrammarGrammar(t *testing.T) { require.NoError(t, err) e := v.(parser.Node) - grammar2 := buildGrammar(ast.FromParserNode(parsers.Grammar(), e)) + grammar2 := NewFromAst(ast.FromParserNode(parsers.Grammar(), e)) assert.EqualValues(t, tinyGrammar, grammar2) } @@ -227,7 +227,7 @@ func TestExprGrammarGrammarGrammar(t *testing.T) { require.NoError(t, err) e := v.(parser.Node) - grammar2 := buildGrammar(ast.FromParserNode(parsers.Grammar(), e)) + grammar2 := NewFromAst(ast.FromParserNode(parsers.Grammar(), e)) assert.EqualValues(t, exprGrammar, grammar2) } diff --git a/wbnf/node_test_complex.go b/wbnf/node_test_complex.go index abea5bc..2a16eb2 100644 --- a/wbnf/node_test_complex.go +++ b/wbnf/node_test_complex.go @@ -18,7 +18,7 @@ func TestParserNodeToNode(t *testing.T) { u := ast.ToParserNode(g, n).(parser.Node) parser.AssertEqualNodes(t, v, u) - p = buildGrammar(n).Compile(u) + p = NewFromAst(n).Compile(u) v = p.MustParse(parser.Rule("expr"), parser.NewScanner(`1+2*3`)).(parser.Node) g = p.Grammar() n = ast.FromParserNode(g, v) @@ -38,7 +38,7 @@ func TestTinyXMLGrammar(t *testing.T) { assert.NoError(t, err) node := v.(parser.Node) - xmlParser := buildGrammar(ast.FromParserNode(Core().Grammar(), node)).Compile(&node) + xmlParser := NewFromAst(ast.FromParserNode(Core().Grammar(), node)).Compile(&node) src := parser.NewScanner(`hello world!`) orig := *src