Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Whebon opened this issue Mar 22, 2024 · 0 comments
Open

Comments

@Whebon
Copy link
Contributor

Whebon commented Mar 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant