Skip to content

Inline Go expr into patterns #10

@quasilyte

Description

@quasilyte

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions