{"action":"opened","issue":{"url":"https://api.github.com/repos/wavebeem/squiggle/issues/75","labels_url":"https://api.github.com/repos/wavebeem/squiggle/issues/75/labels{/name}","comments_url":"https://api.github.com/repos/wavebeem/squiggle/issues/75/comments","events_url":"https://api.github.com/repos/wavebeem/squiggle/issues/75/events","html_url":"https://github.com/wavebeem/squiggle/issues/75","id":110079030,"number":75,"title":"Modularize parser","user":{"login":"wavebeem","id":176815,"avatar_url":"https://avatars.githubusercontent.com/u/176815?v=3","gravatar_id":"","url":"https://api.github.com/users/wavebeem","html_url":"https://github.com/wavebeem","followers_url":"https://api.github.com/users/wavebeem/followers","following_url":"https://api.github.com/users/wavebeem/following{/other_user}","gists_url":"https://api.github.com/users/wavebeem/gists{/gist_id}","starred_url":"https://api.github.com/users/wavebeem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wavebeem/subscriptions","organizations_url":"https://api.github.com/users/wavebeem/orgs","repos_url":"https://api.github.com/users/wavebeem/repos","events_url":"https://api.github.com/users/wavebeem/events{/privacy}","received_events_url":"https://api.github.com/users/wavebeem/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-06T19:09:42Z","updated_at":"2015-10-06T19:09:42Z","closed_at":null,"body":"`parser.js` is pretty large, and probably a little overcomplicated at this point.\r\n\r\nIt's hard to reason about this file because it's hard to pay attention to what's used just as a helper for one grammar rule, vs what's used in other rules.\r\n\r\nIf each \"public\" rule was exported from a module like `parsers/function.js`, then for example we could hide the `var Arguments = ...` rule from the rest of the parser, making its intended scope reality.\r\n\r\nObviously there's the problem of mutually recursive rules: but in my example parser it seems sufficient to just put all the \"public\" parsers in a large object which is injected as a dependency:\r\n\r\n```javascript\r\n// parsers/function.js\r\nmodule.exports = function(ps) {\r\n    var Arguments = ...;\r\n    var Function_ = ... ps.SomeOtherParser;\r\n    return Function_;\r\n};\r\n```\r\n\r\nThis increases the testability and bypasses the circular `require` problem.\r\n\r\nAll parsers would be put into an object, have that object itself injected as the first param, and the resulting nullary function could be passed to `Parsimmon.lazy`."}}