Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • S sweet-core
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 62
    • Issues 62
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • sweet-js
  • sweet-core
  • Issues
  • #319
Closed
Open
Issue created May 08, 2014 by Administrator@rootContributor

Named pattern groups

Created by: natefaubion

This is something that I've wanted on several occasions. Generally I'd like to be able to match on a literal keyword or syntax, but retain the original token in a pattern var for context (like with throwSyntaxError). Right now we have to match on it with a generic pattern var, then verify it with a case body, which is something I do not enjoy. So I propose a simple extension that allows you to name literal groups and pattern groups.

macro func {
  rule { $keyword:[function] $name:ident ($args:ident (,) ...) { $body ... } } => {
    // ...
  }
}

So a normal literal group is $[...], I think a named literal group could easily be $name:[...]. If the match in the braces is successful, the tokens would be bound to the pattern var. This doesn't clobber any existing syntax since we generally treat $name:foo as reserved.

We can extend this to pattern groups with sub matches:

macro obj {
  rule { $def:($name:ident $eq:[=] $lhs:expr) (,) ... } => {
    {
      $($def$name : $def$lhs) (,) ...
    }
  }
}

This does the same thing as macroclass does with concatenating the names. So in this case, its much like an ad-hoc macroclass.

This should be a very simple implementation. I'd just like to get some feedback on it to make sure its something others want and the syntax is obvious enough.

Assignee
Assign to
Time tracking