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

Initial work on refactoring modules and terms

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Tim Disney requested to merge refactor/terms-via-spec into master Sep 21, 2016
  • Overview 17
  • Commits 21
  • Pipelines 0
  • Changes 205

This is very much of work in progress but wanted to share my current status with refactoring our term and module handling.

For context, Term has been our "class" for creating our internal AST. Our AST is basically the shift AST with some extra nodes to handle sweet specific syntax like syntax and syntaxrec.

Our ways for manipulating a Term was an ugly combination of a visitor, reducer, and ad-hoc traversal methods. Also, there was no enforcement of how a Term could be constructed so we had lots of hard to track down bugs due to malformed Terms.

So, the solution is to use more macros! The sweet-spec repo defines all the Terms via the sweet-spec-macro using a syntax that is identical with flow's types:

declare class ClassExpression extends Expression {
  name?: BindingIdentifier;
  super?: Expression;
  elements: ClassElement[];
}

All these declarations are expanded into classes that check their arguments on construction. They also have a reduce method that runs a shift-style reducer to make traversal/manipulation nice and easy.

Because the syntax is identical to flow we also can use the spec as a flow interface .flow file and get the benefits of type checking on our AST constructors.

I'm pretty stoked about it.

Anyway, everything is currently broken since I'm halfway through converting everything to use the new constructors but it should converge soon.

/cc @gabejohnson @jlongster

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: refactor/terms-via-spec