{"action":"created","comment":{"url":"https://api.github.com/repos/cdglabs/ohm/pulls/comments/72477983","id":72477983,"diff_hunk":"@@ -0,0 +1,229 @@\n+/* eslint-env browser */\n+\n+'use strict';\n+\n+self.importScripts('../dist/ohm.js', 'utils.js');\n+\n+// Web Worker that generates examples.\n+// communicates with 'exampleGenerationUI.js'\n+\n+(function(root, initModule) {\n+  if (typeof exports === 'object') {\n+    module.exports = initModule;\n+  } else {\n+    initModule(root.ohm, root.utils);\n+  }\n+})(this, function(ohm, utils) {\n+  postMessage('WORKER STARTED');\n+  var grammar;\n+\n+  var examplePieces = {};\n+  var generator;\n+\n+  var overrides = {\n+    ident: function(g, ex, syn, args) {\n+      return {needHelp: true};\n+    },\n+    ctor: function(g, ex, syn, args) {\n+      return {needHelp: true};\n+    },\n+    letter: function(g, ex, syn, args) {\n+      if (Math.floor(Math.random() * 2) === 0) {\n+        return {example: String.fromCharCode(Math.floor(26 * Math.random()) + 'a'.charCodeAt(0))};\n+      } else {\n+        return {example: String.fromCharCode(Math.floor(26 * Math.random()) + 'A'.charCodeAt(0))};\n+      }\n+    }\n+  };\n+\n+  self.addEventListener('message', function(e) {\n+    postMessage(e.data.name);\n+    switch (e.data.name) {\n+      case 'initialize':\n+        /* eslint-disable no-eval */\n+        grammar = ohm.makeRecipe(eval(e.data.recipe));\n+        /* eslint-enable no-eval */\n+\n+        start();\n+        break;\n+      case 'request:examples':\n+        var ruleName = e.data.args[0];\n+\n+        var examplesForRule = examplePieces[ruleName] || null;\n+        self.postMessage({name: 'received:examples',\n+                          args: [ruleName, examplesForRule]});\n+        break;\n+      case 'update:neededExamples':\n+        var neededExamples = utils.difference(\n+          Object.keys(grammar.rules),\n+          Object.keys(examplePieces)\n+        );\n+\n+        self.postMessage({name: 'received:neededExamples',\n+                          args: [neededExamples]});\n+        break;\n+      case 'add:userExample':\n+        ruleName = e.data.args[0];\n+        var example = e.data.args[1];\n+        generator.processExampleFromUser(example, ruleName);\n+        break;\n+    }\n+  }, false);\n+\n+  function addPiecesToDict(trace, examples) {\n+    if (trace.expr.constructor.name === 'Terminal') {\n+      return;\n+    } else {\n+      if (trace.expr.constructor.name === 'Apply') {\n+        var ruleName = trace.expr.toString();\n+        if (!examples.hasOwnProperty(ruleName)) {\n+          examples[ruleName] = [];\n+        }\n+\n+        if (!examples[ruleName].includes(trace.source.contents)) {\n+          examples[ruleName].push(trace.source.contents);\n+        }\n+      }\n+      trace.children\n+           .filter(function(child) { return child.succeeded; })\n+           .forEach(function(child) { return addPiecesToDict(child, examples); });\n+    }\n+  }\n+\n+  function ExampleGenerator(examplePieces) {\n+    this.examplePieces = examplePieces;\n+    this.rules = initialRules(grammar);\n+    this.examplesNeeded = utils.difference(\n+      Object.keys(grammar.rules),\n+      Object.keys(examplePieces)\n+    );\n+    this.currentRuleIndex = 0;\n+  }\n+\n+  ExampleGenerator.prototype.processExampleFromUser = function(example, optRuleName) {\n+    if (optRuleName) {\n+      var trace = grammar.trace(example, optRuleName);\n+      if (trace.succeeded) {\n+        addPiecesToDict(trace, examplePieces);\n+      }\n+    }\n+\n+    utils.objectForEach(grammar.rules, function(ruleName) {\n+      var trace = grammar.trace(example, ruleName);\n+      if (trace.succeeded) {\n+        addPiecesToDict(trace, examplePieces);\n+      }\n+    });\n+\n+    var oldSize = this.examplesNeeded.length;\n+    this.examplesNeeded = this.examplesNeeded.filter(function(ruleName) {\n+      return !examplePieces.hasOwnProperty(ruleName);\n+    });\n+    if (this.examplesNeeded.length < oldSize) {\n+      self.postMessage({name: 'received:neededExamples',\n+                        args: [this.examplesNeeded]});\n+    }\n+  };\n+\n+  ExampleGenerator.prototype.next = function() {\n+    var that = this;","path":"src/exampleWorker.js","position":129,"original_position":129,"commit_id":"4e64a8a7131c0f7cbc9025056b0f47db3068f6ff","original_commit_id":"4e64a8a7131c0f7cbc9025056b0f47db3068f6ff","user":{"login":"sakekasi","id":979969,"avatar_url":"https://avatars.githubusercontent.com/u/979969?v=3","gravatar_id":"","url":"https://api.github.com/users/sakekasi","html_url":"https://github.com/sakekasi","followers_url":"https://api.github.com/users/sakekasi/followers","following_url":"https://api.github.com/users/sakekasi/following{/other_user}","gists_url":"https://api.github.com/users/sakekasi/gists{/gist_id}","starred_url":"https://api.github.com/users/sakekasi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sakekasi/subscriptions","organizations_url":"https://api.github.com/users/sakekasi/orgs","repos_url":"https://api.github.com/users/sakekasi/repos","events_url":"https://api.github.com/users/sakekasi/events{/privacy}","received_events_url":"https://api.github.com/users/sakekasi/received_events","type":"User","site_admin":false},"body":"So, after a bit of thought, in this case, I think I would prefer to use repeat instead of for, just because it's more declarative. There's something similar to repeat strings in common.js. Would that be ok?","created_at":"2016-07-27T16:54:54Z","updated_at":"2016-07-27T16:54:54Z","html_url":"https://github.com/cdglabs/ohm/pull/139#discussion_r72477983","pull_request_url":"https://api.github.com/repos/cdglabs/ohm/pulls/139","_links":{"self":{"href":"https://api.github.com/repos/cdglabs/ohm/pulls/comments/72477983"},"html":{"href":"https://github.com/cdglabs/ohm/pull/139#discussion_r72477983"},"pull_request":{"href":"https://api.github.com/repos/cdglabs/ohm/pulls/139"}}},"pull_request":{"url":"https://api.github.com/repos/cdglabs/ohm/pulls/139","id":78949017,"html_url":"https://github.com/cdglabs/ohm/pull/139","diff_url":"https://github.com/cdglabs/ohm/pull/139.diff","patch_url":"https://github.com/cdglabs/ohm/pull/139.patch","issue_url":"https://api.github.com/repos/cdglabs/ohm/issues/139","number":139,"state":"open","locked":false,"title":"Add example generation web worker to ohm editor","user":{"login":"sakekasi","id":979969,"avatar_url":"https://avatars.githubusercontent.com/u/979969?v=3","gravatar_id":"","url":"https://api.github.com/users/sakekasi","html_url":"https://github.com/sakekasi","followers_url":"https://api.github.com/users/sakekasi/followers","following_url":"https://api.github.com/users/sakekasi/following{/other_user}","gists_url":"https://api.github.com/users/sakekasi/gists{/gist_id}","starred_url":"https://api.github.com/users/sakekasi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sakekasi/subscriptions","organizations_url":"https://api.github.com/users/sakekasi/orgs","repos_url":"https://api.github.com/users/sakekasi/repos","events_url":"https://api.github.com/users/sakekasi/events{/privacy}","received_events_url":"https://api.github.com/users/sakekasi/received_events","type":"User","site_admin":false},"body":"Adds web worker and worker manager for integration with\r\neditor event system","created_at":"2016-07-27T00:42:17Z","updated_at":"2016-07-27T16:54:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f9344447796ba0d8dca32a9313fccdfac5fb6ef7","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/cdglabs/ohm/pulls/139/commits","review_comments_url":"https://api.github.com/repos/cdglabs/ohm/pulls/139/comments","review_comment_url":"https://api.github.com/repos/cdglabs/ohm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cdglabs/ohm/issues/139/comments","statuses_url":"https://api.github.com/repos/cdglabs/ohm/statuses/4e64a8a7131c0f7cbc9025056b0f47db3068f6ff","head":{"label":"cdglabs:ohm-madlibs-integration","ref":"ohm-madlibs-integration","sha":"4e64a8a7131c0f7cbc9025056b0f47db3068f6ff","user":{"login":"cdglabs","id":9912100,"avatar_url":"https://avatars.githubusercontent.com/u/9912100?v=3","gravatar_id":"","url":"https://api.github.com/users/cdglabs","html_url":"https://github.com/cdglabs","followers_url":"https://api.github.com/users/cdglabs/followers","following_url":"https://api.github.com/users/cdglabs/following{/other_user}","gists_url":"https://api.github.com/users/cdglabs/gists{/gist_id}","starred_url":"https://api.github.com/users/cdglabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdglabs/subscriptions","organizations_url":"https://api.github.com/users/cdglabs/orgs","repos_url":"https://api.github.com/users/cdglabs/repos","events_url":"https://api.github.com/users/cdglabs/events{/privacy}","received_events_url":"https://api.github.com/users/cdglabs/received_events","type":"Organization","site_admin":false},"repo":{"id":36021747,"name":"ohm","full_name":"cdglabs/ohm","owner":{"login":"cdglabs","id":9912100,"avatar_url":"https://avatars.githubusercontent.com/u/9912100?v=3","gravatar_id":"","url":"https://api.github.com/users/cdglabs","html_url":"https://github.com/cdglabs","followers_url":"https://api.github.com/users/cdglabs/followers","following_url":"https://api.github.com/users/cdglabs/following{/other_user}","gists_url":"https://api.github.com/users/cdglabs/gists{/gist_id}","starred_url":"https://api.github.com/users/cdglabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdglabs/subscriptions","organizations_url":"https://api.github.com/users/cdglabs/orgs","repos_url":"https://api.github.com/users/cdglabs/repos","events_url":"https://api.github.com/users/cdglabs/events{/privacy}","received_events_url":"https://api.github.com/users/cdglabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cdglabs/ohm","description":"A library and language for building parsers, interpreters, compilers, etc.","fork":false,"url":"https://api.github.com/repos/cdglabs/ohm","forks_url":"https://api.github.com/repos/cdglabs/ohm/forks","keys_url":"https://api.github.com/repos/cdglabs/ohm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cdglabs/ohm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cdglabs/ohm/teams","hooks_url":"https://api.github.com/repos/cdglabs/ohm/hooks","issue_events_url":"https://api.github.com/repos/cdglabs/ohm/issues/events{/number}","events_url":"https://api.github.com/repos/cdglabs/ohm/events","assignees_url":"https://api.github.com/repos/cdglabs/ohm/assignees{/user}","branches_url":"https://api.github.com/repos/cdglabs/ohm/branches{/branch}","tags_url":"https://api.github.com/repos/cdglabs/ohm/tags","blobs_url":"https://api.github.com/repos/cdglabs/ohm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cdglabs/ohm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cdglabs/ohm/git/refs{/sha}","trees_url":"https://api.github.com/repos/cdglabs/ohm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cdglabs/ohm/statuses/{sha}","languages_url":"https://api.github.com/repos/cdglabs/ohm/languages","stargazers_url":"https://api.github.com/repos/cdglabs/ohm/stargazers","contributors_url":"https://api.github.com/repos/cdglabs/ohm/contributors","subscribers_url":"https://api.github.com/repos/cdglabs/ohm/subscribers","subscription_url":"https://api.github.com/repos/cdglabs/ohm/subscription","commits_url":"https://api.github.com/repos/cdglabs/ohm/commits{/sha}","git_commits_url":"https://api.github.com/repos/cdglabs/ohm/git/commits{/sha}","comments_url":"https://api.github.com/repos/cdglabs/ohm/comments{/number}","issue_comment_url":"https://api.github.com/repos/cdglabs/ohm/issues/comments{/number}","contents_url":"https://api.github.com/repos/cdglabs/ohm/contents/{+path}","compare_url":"https://api.github.com/repos/cdglabs/ohm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cdglabs/ohm/merges","archive_url":"https://api.github.com/repos/cdglabs/ohm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cdglabs/ohm/downloads","issues_url":"https://api.github.com/repos/cdglabs/ohm/issues{/number}","pulls_url":"https://api.github.com/repos/cdglabs/ohm/pulls{/number}","milestones_url":"https://api.github.com/repos/cdglabs/ohm/milestones{/number}","notifications_url":"https://api.github.com/repos/cdglabs/ohm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cdglabs/ohm/labels{/name}","releases_url":"https://api.github.com/repos/cdglabs/ohm/releases{/id}","deployments_url":"https://api.github.com/repos/cdglabs/ohm/deployments","created_at":"2015-05-21T15:42:14Z","updated_at":"2016-07-22T18:21:28Z","pushed_at":"2016-07-27T00:42:17Z","git_url":"git://github.com/cdglabs/ohm.git","ssh_url":"git@github.com:cdglabs/ohm.git","clone_url":"https://github.com/cdglabs/ohm.git","svn_url":"https://github.com/cdglabs/ohm","homepage":"","size":19990,"stargazers_count":399,"watchers_count":399,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":24,"mirror_url":null,"open_issues_count":30,"forks":24,"open_issues":30,"watchers":399,"default_branch":"master"}},"base":{"label":"cdglabs:master","ref":"master","sha":"d9f0aa7bace7f56e98362256ead8c9421e0d1384","user":{"login":"cdglabs","id":9912100,"avatar_url":"https://avatars.githubusercontent.com/u/9912100?v=3","gravatar_id":"","url":"https://api.github.com/users/cdglabs","html_url":"https://github.com/cdglabs","followers_url":"https://api.github.com/users/cdglabs/followers","following_url":"https://api.github.com/users/cdglabs/following{/other_user}","gists_url":"https://api.github.com/users/cdglabs/gists{/gist_id}","starred_url":"https://api.github.com/users/cdglabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdglabs/subscriptions","organizations_url":"https://api.github.com/users/cdglabs/orgs","repos_url":"https://api.github.com/users/cdglabs/repos","events_url":"https://api.github.com/users/cdglabs/events{/privacy}","received_events_url":"https://api.github.com/users/cdglabs/received_events","type":"Organization","site_admin":false},"repo":{"id":36021747,"name":"ohm","full_name":"cdglabs/ohm","owner":{"login":"cdglabs","id":9912100,"avatar_url":"https://avatars.githubusercontent.com/u/9912100?v=3","gravatar_id":"","url":"https://api.github.com/users/cdglabs","html_url":"https://github.com/cdglabs","followers_url":"https://api.github.com/users/cdglabs/followers","following_url":"https://api.github.com/users/cdglabs/following{/other_user}","gists_url":"https://api.github.com/users/cdglabs/gists{/gist_id}","starred_url":"https://api.github.com/users/cdglabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdglabs/subscriptions","organizations_url":"https://api.github.com/users/cdglabs/orgs","repos_url":"https://api.github.com/users/cdglabs/repos","events_url":"https://api.github.com/users/cdglabs/events{/privacy}","received_events_url":"https://api.github.com/users/cdglabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cdglabs/ohm","description":"A library and language for building parsers, interpreters, compilers, etc.","fork":false,"url":"https://api.github.com/repos/cdglabs/ohm","forks_url":"https://api.github.com/repos/cdglabs/ohm/forks","keys_url":"https://api.github.com/repos/cdglabs/ohm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cdglabs/ohm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cdglabs/ohm/teams","hooks_url":"https://api.github.com/repos/cdglabs/ohm/hooks","issue_events_url":"https://api.github.com/repos/cdglabs/ohm/issues/events{/number}","events_url":"https://api.github.com/repos/cdglabs/ohm/events","assignees_url":"https://api.github.com/repos/cdglabs/ohm/assignees{/user}","branches_url":"https://api.github.com/repos/cdglabs/ohm/branches{/branch}","tags_url":"https://api.github.com/repos/cdglabs/ohm/tags","blobs_url":"https://api.github.com/repos/cdglabs/ohm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cdglabs/ohm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cdglabs/ohm/git/refs{/sha}","trees_url":"https://api.github.com/repos/cdglabs/ohm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cdglabs/ohm/statuses/{sha}","languages_url":"https://api.github.com/repos/cdglabs/ohm/languages","stargazers_url":"https://api.github.com/repos/cdglabs/ohm/stargazers","contributors_url":"https://api.github.com/repos/cdglabs/ohm/contributors","subscribers_url":"https://api.github.com/repos/cdglabs/ohm/subscribers","subscription_url":"https://api.github.com/repos/cdglabs/ohm/subscription","commits_url":"https://api.github.com/repos/cdglabs/ohm/commits{/sha}","git_commits_url":"https://api.github.com/repos/cdglabs/ohm/git/commits{/sha}","comments_url":"https://api.github.com/repos/cdglabs/ohm/comments{/number}","issue_comment_url":"https://api.github.com/repos/cdglabs/ohm/issues/comments{/number}","contents_url":"https://api.github.com/repos/cdglabs/ohm/contents/{+path}","compare_url":"https://api.github.com/repos/cdglabs/ohm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cdglabs/ohm/merges","archive_url":"https://api.github.com/repos/cdglabs/ohm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cdglabs/ohm/downloads","issues_url":"https://api.github.com/repos/cdglabs/ohm/issues{/number}","pulls_url":"https://api.github.com/repos/cdglabs/ohm/pulls{/number}","milestones_url":"https://api.github.com/repos/cdglabs/ohm/milestones{/number}","notifications_url":"https://api.github.com/repos/cdglabs/ohm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cdglabs/ohm/labels{/name}","releases_url":"https://api.github.com/repos/cdglabs/ohm/releases{/id}","deployments_url":"https://api.github.com/repos/cdglabs/ohm/deployments","created_at":"2015-05-21T15:42:14Z","updated_at":"2016-07-22T18:21:28Z","pushed_at":"2016-07-27T00:42:17Z","git_url":"git://github.com/cdglabs/ohm.git","ssh_url":"git@github.com:cdglabs/ohm.git","clone_url":"https://github.com/cdglabs/ohm.git","svn_url":"https://github.com/cdglabs/ohm","homepage":"","size":19990,"stargazers_count":399,"watchers_count":399,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":24,"mirror_url":null,"open_issues_count":30,"forks":24,"open_issues":30,"watchers":399,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cdglabs/ohm/pulls/139"},"html":{"href":"https://github.com/cdglabs/ohm/pull/139"},"issue":{"href":"https://api.github.com/repos/cdglabs/ohm/issues/139"},"comments":{"href":"https://api.github.com/repos/cdglabs/ohm/issues/139/comments"},"review_comments":{"href":"https://api.github.com/repos/cdglabs/ohm/pulls/139/comments"},"review_comment":{"href":"https://api.github.com/repos/cdglabs/ohm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cdglabs/ohm/pulls/139/commits"},"statuses":{"href":"https://api.github.com/repos/cdglabs/ohm/statuses/4e64a8a7131c0f7cbc9025056b0f47db3068f6ff"}}}}
{"actor":{"display_login":"sakekasi"}}