Herb-AI / HerbGrammar.jl

Grammars for Herb.jl
https://herb-ai.github.io/
MIT License
0 stars 2 forks source link

When adding a constraint to a grammar, assert that the arities are correct #61

Open Whebon opened 7 months ago

Whebon commented 7 months ago

Add assertions to prevent users from imposing constraints with invalid program trees:

g = @csgrammar begin
    Real = 1
    Real = :x
    Real = -Real
    Real = Real + Real
    Real = Real * Real
    Real = Real / Real
end

constraint1 = Forbidden(RuleNode(1, [RuleNode(2), RuleNode(2)]))
addconstraint!(grammar, constraint1) #should raise an AssertionException: rule 1 must have 0 children

constraint2 = Forbidden(RuleNode(4, [RuleNode(5), RuleNode(2)]))
addconstraint!(grammar, constraint2) #should raise an AssertionException: rule 5 must have 2 children

Also add assertions for DomainRuleNodes