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
  • #118
Closed
Open
Issue created Oct 16, 2013 by Administrator@rootContributor

Incorrect pattern matches in "macro" macro

Created by: andreypopp

Hello,

First — Sweet.js is super awesome, thanks!

I'm trying to write a simple macro which will produce an object literal from a list of k-v pairs but passes everything else as-is:

attributes(id) // id
attributes({}) // {}
attributes(k: v, a: 1) // {k: v, a: 1}

Currently my macro looks like this:

macro attributes {
  case {_()} => {
    return #{null}
  }
  case {_($($name:ident : $val:expr) (,) ...)} => {
    return [makeDelim('{}', #{$($name: $val) (,) ...})]
  }
  case {_($any:expr)} => {
    return #{$any}
  }
}

But somehow attributes(id) matches the second case which is, I believe, wrong.

P.S. this macro is part of the bigger story, which is why I have a special case producing null for empty arg list.

Assignee
Assign to
Time tracking