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
  • Merge requests
  • !296

Custom operators

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Tim Disney requested to merge custom-operators into master Apr 07, 2014
  • Overview 12
  • Commits 22
  • Pipelines 0
  • Changes 18

Custom (honu-style) operator support. Still need to do a little bit of cleaning/testing before I merge. Here's the syntax I'm going with at the moment:

unaryop neg 14 {$op} => #{ -$op }
binaryop plus 12 left { $lhs, $rhs } => #{ $lhs + $rhs }

The definition syntax is actually just a macro that desugars down to a primitive form:

binaryop (plus) 12 left {
    macro {
        rule { ($left:expr) ($right:expr) } => {
            $left + $right
        }
    }
}

One interesting question came up while I was working on this. How should we order precedence? The precedence table on mdn is ordered from highest (0) to lowest (18), which seems a bit backwards since bigger numbers have lower precedence. I've flipped this for sweet.js so 0 binds least tightly and 18 binds most tightly. Is this the right choice or will people be confused because of the mdn page?

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: custom-operators