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
  • #529
Closed
Open
Issue created Apr 11, 2016 by Administrator@rootContributor

Extendable syntaxes

Created by: bopjesvla

Extendable syntaxes would allow for:

  • the usage of independently written macros with the same name, provided that they're used in different contexts
  • the inline extension of an imported macro without forking a module
  • anything that requires backtracking, such as the macro syntax

The most natural implementation I can think of would be to allow syntax functions to return null, after which the reader tracks back and tries the previous macro with the same name:

syntax each = ctx => {
    let variable = ctx.next("expr").value,
        OF = ctx.next().value,
        iterable = ctx.next("expr").value,
        body = ctx.next().value

    if (variable && iterable && OF.isIdentifier("of") && body.isBraces()) {
        return #`for (${variable} ${OF} ${iterable}) ${body}`
    }

}
syntax each = ctx => {
    let iterable = ctx.next("expr").value,
        body = ctx.next().value

    if (iterable && body.isBraces()) {
        return #`for ($_ of ${iterable}) ${body}` // yeah this wouldn't work because of hygiene
    }
}

each x of y {
    x()
}

each y {
    $_()
}

This would cover a lot of the same ground as readtables.

Assignee
Assign to
Time tracking