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

Began Work on Fixing Nested Syntax

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Philip Blair requested to merge github/fork/peblair/nested-syntax into master Jun 02, 2016
  • Overview 16
  • Commits 3
  • Pipelines 0
  • Changes 11

NOTE: This PR is not ready to merge!

I have begun working on fixing #519, but I have reached a bit of a stumbling block. I have gotten shift-reader.js to accept files with nested syntax, but something is getting garbled in between (details below), leading me to believe that I'm missing some step in the expander pipeline.

To explain where I'm at, here's what I know:

  • The reading of syntax templates (and, well, everything else) is done in src/shift-reader.js.
  • Syntax objects begin when src/shift-reader.js's advance function (master) returns a token of type LSYNTAX.
  • The contents of syntax objects are read like normal syntax; the only thing that makes them special is that the handler for LSYNTAX bundles all of the read pieces together into an immutable list.
  • The reason for the error that is mentioned in the bug report is because advance in src/shift-reader.js does not handle the ""` character (or it's escaped variant), so it delegates to the superclass (which also does not handle it).

Thus, I figured that fixing the error would just be a matter of adding the proper escapes to advance, allowing nested syntax objects to be read correctly. As far as reading the syntax goes, this all seems to work correctly. Note: This change is what the first commit of this PR reflects.

So, what happened? I tried to run this modified version on the following code:

syntax makeSayer = function(ctx) {
  let x = ctx.next().value;
  return #`syntax ${x} = function(ctx) { return \`console.log('hello world')\`; }`;
}

makeSayer hi

The result was the following error messsage:

/home/belph/git-belph/sweet.js/dist/syntax.js:174
        return s_701.addScope(scope_696, bindings_697, options_698);
                    ^

TypeError: Cannot read property 'addScope' of null
    at /home/belph/git-belph/sweet.js/dist/syntax.js:174:21
    at /home/belph/git-belph/sweet.js/node_modules/immutable/dist/immutable.js:3018:46
    at List.__iterate (/home/belph/git-belph/sweet.js/node_modules/immutable/dist/immutable.js:2208:13)
    at IndexedIterable.mappedSequence.__iterateUncached (/home/belph/git-belph/sweet.js/node_modules/immutable/dist/immutable.js:3017:23)
    at seqIterate (/home/belph/git-belph/sweet.js/node_modules/immutable/dist/immutable.js:606:16)
    at IndexedIterable.IndexedSeq.__iterate (/home/belph/git-belph/sweet.js/node_modules/immutable/dist/immutable.js:322:14)
    at IndexedIterable.mixin.toArray (/home/belph/git-belph/sweet.js/node_modules/immutable/dist/immutable.js:4260:23)
    at new List (/home/belph/git-belph/sweet.js/node_modules/immutable/dist/immutable.js:2067:62)
    at reify (/home/belph/git-belph/sweet.js/node_modules/immutable/dist/immutable.js:3572:37)
    at List.mixin.map (/home/belph/git-belph/sweet.js/node_modules/immutable/dist/immutable.js:4403:14)

Let's first dissect the syntax object in question as follows:

<ret> = #`syntax ${x} = function(ctx) { \`console.log('hello, world')\`; }`
                                        |------- <ret_nested> --------| 

Now, here's what I can tell happens:

  • read (my fork's copy) will tokenize <ret> and <ret_nested> just fine; <ret> is an immutable list with an entry at index-whatever that is another immutable list corresponding to <ret_nested>
  • Sometime between then and the return value of the call to deserializer.read(str) in loadForCompileTime (my fork's copy), the location of <ret_nested> in <ret> is set to null. Why? Not a clue.

And that is where I'm at. Am I missing some step here? I feel like this is, if nothing else a step in the right direction; nested syntax is a powerful feature to have, so I'd love to get this fixed!

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/peblair/nested-syntax