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

Idea: "Syntax literal" #206

Open
akx opened this issue Mar 10, 2013 · 1 comment
Open

Idea: "Syntax literal" #206

akx opened this issue Mar 10, 2013 · 1 comment

Comments

@akx
Copy link

akx commented Mar 10, 2013

A possible neat feature idea that occurred to me while out walking: a literal that would compile down to a Coco syntax tree object/JavaScript syntax tree object (if it's generated by Coco on the way to JS?)/worst case JavaScript source fragment as string (that could be parsed back to an AST by client code as required).

Use case (for the sake of discussion let's use the syntax ^( ... )):

dbQuery ^(5 < foo < 10) 

-->

dbQuery({
  "type":"Binary","op":"&&",
  "first":{"type":"Binary","op":"<","first":{"type":"Literal","value":"5"},"second":{"type":"Var","value":"foo"}},
  "second":{"type":"Binary","op":"<","first":{"type":"Var","value":"foo"},"second":{"type":"Literal","value":"10"}}
})

The AST above is adapted from coco -aj for (5 < foo && foo < 10) as the AST for 5 < foo < 10 (obviously) didn't have extended comparison transformed into an and expression.
Point being the resulting AST should be as easy to use as possible by client code, with as much of Coco's expressiveness remaining as is sensible.

@satyr
Copy link
Owner

satyr commented Mar 11, 2013

An obvious problem is that our AST is awful: not well-designed, prone to change, not transformable to JS AST, etc.

Something like this would be a must if we were to implement a macro system, though.

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

2 participants