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

Inline Go expr into patterns #10

Open
quasilyte opened this issue Jan 7, 2018 · 0 comments
Open

Inline Go expr into patterns #10

quasilyte opened this issue Jan 7, 2018 · 0 comments

Comments

@quasilyte
Copy link
Collaborator

Make it possible to inline Go syntax into pattern templates.

For example:

(map [\ident] (expr "map[string]interface{}"))
// matches:
// map[A]map[string]interface{}
// map[B]map[string]interface{}
// etc...

(block \... (stmt "x := foo().bar().baz()") \...)
// matches:
// {x := foo().bar().baz()}
// {f(); x := foo().bar().baz()}
// {f(); g(); x := foo().bar().baz(); y--}
// etc...

The idea is to simplify some literal sub-patterns.
This syntax does not deprecate any existing ways to describe patterns as it lacks
many features like captures, \... wildcards, etc.

The change itself requires patterns expr to become overloaded with additional form that expects single literal string argument.
If Go parser fails to resolve AST for that sub-pattern, whole pattern compilation fails.

stmt and decl patterns may have same feature somewhere in future, but not it's unclear if this is as important as for expressions.

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