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
  • !566

Add from* syntax methods to syntax instances

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Tim Disney requested to merge add-from-syntax into master Aug 06, 2016
  • Overview 1
  • Commits 2
  • Pipelines 0
  • Changes 5

For some reason, I had become convinced that the only way to make the Syntax static from* methods available to compiletime code was via modules. But in fact they can, and actually should, be put on Syntax instances. This would let you do cool things like:

syntax to_str = ctx => {
  let argStr = ctx.next().value.val();
  let dummy = #`here`.get(0);

  return #`${dummy.fromString(argStr)}`;
}
let s = to_str foo
// expands to:
// let s = 'foo'

The reason we actually want to make from* instance methods is that most of the time when creating a new syntax object you need to re-use an existing syntax object's lexical context (the third argument to the static Syntax.from method). Having these methods as instance methods means you get the lexical context stealing behavior "for free".

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: add-from-syntax