-
Notifications
You must be signed in to change notification settings - Fork 78
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
Getting rid of implode #470
Comments
Just realized: GASTs are really the dual of concrete syntax patterns/expressions: Concrete syntax -> statically insert appl-trees through parsing So I think there's a story here. |
I like the gist of your proposal but we have to work out the details. Complete duality between concrete and abstract views on the same tree is appealing. We also have to work out the efficiency implications: ASTs were supposed to be more efficient. As long as we can do all the required transformations at compile time, we are ok I guess. We could even generalize a bit further and allow concrete patterns to match abstract trees, provided that the types of the subtrees are "compatible". |
I don't like "compatible" in scare-quotes. In my proposal GASTs will match old-skool concrete trees, if that's what you mean. Like so:
=> True |
I think it would be a good idea to do this and a challenging one at the
On Mon, Dec 30, 2013 at 11:28 PM, Tijs van der Storm <
Jurgen Vinju
|
BTW, the full grammar for every non-terminal is always available using On Fri, Jan 3, 2014 at 11:36 AM, Jurgen J. Vinju
Jurgen Vinju
|
Here's an idea to get rid of implode, with only minor penalty (I think).
Implode transforms parse trees (PTs) to abstract syntax trees (ASTs). To do this, it requires an ADT describing the AST structure. Implode is often complained about and for good reason. The following problems can be observed:
To solve these problems, I suggest the following idea. Get rid of implode and the separate ADT. The grammar defines a single type, just like now, but values of the type have three literal representations:
backquotes
.Tree
notation withappl
s andprod
sadd(lhs, rhs)
(let's call it "Grammar AST" or GAST notation)The 3rd item is new: it means you can construct "abstract" concrete syntax trees. As a result, the grammar is enough to allow you to program with ASTs. Concrete and GAST representations can be arbitrarily mixed and nested.
This design has one big consequence: whenever a parse tree is serialized, and a GAST sub-tree is encountered, we need to
explode
the tree. IOW we might have to invent layout and/or separators. Currently there is no restriction on either Layout or separators, so it's not always possible to do that. Consequently, either you'll get a runtime error ("can't invent layout/sep"), or we impose the restriction statically when using a GAST where no layout/sep can be inferred. Note: this is not about inferring intended layout/seps, just syntactically valid layout/seps. If you need to tweak layout, either you don't use GASTs, or you have to write a pretty printer like all AST people do.Some observations:
Cons:
add(const(1), const(2))
and you getappl(prod(labeled("add", sort("Exp")), [...]), ...)
Possible issues:
explode
(i.e. productions): where to get them?Maybe
, but this suggestsMaybe
shouldn't be inutil
anymore.Feedback welcome!
P.S. Isn't it ironic that one might get rid of implode by introducing explode?
The text was updated successfully, but these errors were encountered: