You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rather than having to switch between grammar.generate and grammar.evaluate to return a string or raw evaluation tree, this behaviour could be unified by returning a result value object from #generate.
As part of this change, grammar.evaluate would probably be removed from the public API and be considered internal-only.
Rough sketch of the API:
# @return [Calyx::Result]result=grammar.generate# Generated text stringresult.text# Generated text converted to a symbolresult.symbol# Expression treeresult.tree# Alternative interfaceresult.to_symresult.to_sresult.to_exp
This allows both the expanded string and the underlying tree of selected syntax nodes to be easily accessible for all grammar runs, rather than having to pick an output format and call the appropriate method.
It’s also an extension point for overlaying metadata/tagging with chosen productions in future.
If the result object implements #to_s and #inspect it will be straightforward to update a lot of existing usages. However it is a breaking API change so does have potential to cause disruption,
which is why I’d like to get it in before 1.0, so that the API can stabilise then.
The text was updated successfully, but these errors were encountered:
maetl
changed the title
Breaking API change proposed for 1.0
Result value object: Breaking API change proposed for 1.0
Sep 21, 2017
As described in #23, this introduces a result object which wraps the
expression tree returned from evaluating a grammar and provides access
to the result as a raw tree, flattened string or symbol.
The generated result object is returned from a new
`Calyx::Grammar#generate_result` method. `Calyx::Grammar#generate` still
returns a string and `Calyx::Grammar#evaluate` now fires a deprecation
warning and will be removed soon.
Rather than having to switch between
grammar.generate
andgrammar.evaluate
to return a string or raw evaluation tree, this behaviour could be unified by returning a result value object from#generate
.As part of this change,
grammar.evaluate
would probably be removed from the public API and be considered internal-only.Rough sketch of the API:
This allows both the expanded string and the underlying tree of selected syntax nodes to be easily accessible for all grammar runs, rather than having to pick an output format and call the appropriate method.
It’s also an extension point for overlaying metadata/tagging with chosen productions in future.
If the result object implements
#to_s
and#inspect
it will be straightforward to update a lot of existing usages. However it is a breaking API change so does have potential to cause disruption,which is why I’d like to get it in before 1.0, so that the API can stabilise then.
The text was updated successfully, but these errors were encountered: