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

Nested expressions in expanded symbols causes confusing behaviour with unique rules #25

Open
maetl opened this issue Mar 7, 2019 · 0 comments

Comments

@maetl
Copy link
Owner

maetl commented Mar 7, 2019

The test case below explains the issue fairly well.

Unique rules work intuitively when the expansion is one level deep and the possible options are always single atoms of text.

grammar = Calyx::Grammar.new do
  start "{sentence}{br}{sentence}{br}{sentence}"
  br "\n"
  sentence "I won a {$medal_type} medal!"
  medal_type "gold", "silver", "bronze"
end

puts grammar.generate

But when the unique rule contains nested expressions, the evaluation result gets memorised in the lookup table, not the actual unique symbols to be picked from. For example, the grammar below gives counter-intuitive results because the evaluated result isn’t comparably unique—so either gold, silver or bronze rules can end up being repeated multiple times instead of only being selected once.

nested_grammar = Calyx::Grammar.new do
  start "{sentence}{br}{sentence}{br}{sentence}"
  br "\n"
  sentence "I won a {$medal_type} medal!"
  medal_type "{gold}", "{silver}", "{bronze}"
  gold "gold", "golden"
  silver "silver", "silvery"
  bronze "bronze", "bronzed"
end

puts nested_grammar.generate
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