Skip to content

Commit

Permalink
Export the buildf grammar func
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Gordon committed Feb 13, 2020
1 parent 75558bd commit d45e0aa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions wbnf/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions wbnf/grammar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions wbnf/node_test_complex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(`<a x="1">hello <b>world!</b></a>`)
orig := *src
Expand Down

0 comments on commit d45e0aa

Please sign in to comment.