{"action":"created","issue":{"url":"https://api.github.com/repos/jonschlinkert/snapdragon/issues/2","repository_url":"https://api.github.com/repos/jonschlinkert/snapdragon","labels_url":"https://api.github.com/repos/jonschlinkert/snapdragon/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/jonschlinkert/snapdragon/issues/2/comments","events_url":"https://api.github.com/repos/jonschlinkert/snapdragon/issues/2/events","html_url":"https://github.com/jonschlinkert/snapdragon/issues/2","id":171852401,"number":2,"title":"Prev / next, or offset","user":{"login":"tunnckoCore","id":5038030,"avatar_url":"https://avatars.githubusercontent.com/u/5038030?v=3","gravatar_id":"","url":"https://api.github.com/users/tunnckoCore","html_url":"https://github.com/tunnckoCore","followers_url":"https://api.github.com/users/tunnckoCore/followers","following_url":"https://api.github.com/users/tunnckoCore/following{/other_user}","gists_url":"https://api.github.com/users/tunnckoCore/gists{/gist_id}","starred_url":"https://api.github.com/users/tunnckoCore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tunnckoCore/subscriptions","organizations_url":"https://api.github.com/users/tunnckoCore/orgs","repos_url":"https://api.github.com/users/tunnckoCore/repos","events_url":"https://api.github.com/users/tunnckoCore/events{/privacy}","received_events_url":"https://api.github.com/users/tunnckoCore/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-08-18T09:03:52Z","updated_at":"2016-08-22T11:37:21Z","closed_at":null,"body":"```js\r\napp\r\n  .use(function any () {\r\n    var pos = this.position();\r\n    var m = this.match(/^./);\r\n    if (!m) return;\r\n    return pos({\r\n      type: 'any',\r\n      val: m[0]\r\n    });\r\n  })\r\n```\r\nIdea how from one renderer to get prev and next char? I think offset in position would work for me.\r\n\r\n_edit: And btw, should mention in readme, that you should be careful with parser plugins order (will show example in other issue)._"},"comment":{"url":"https://api.github.com/repos/jonschlinkert/snapdragon/issues/comments/241387427","html_url":"https://github.com/jonschlinkert/snapdragon/issues/2#issuecomment-241387427","issue_url":"https://api.github.com/repos/jonschlinkert/snapdragon/issues/2","id":241387427,"user":{"login":"jonschlinkert","id":383994,"avatar_url":"https://avatars.githubusercontent.com/u/383994?v=3","gravatar_id":"","url":"https://api.github.com/users/jonschlinkert","html_url":"https://github.com/jonschlinkert","followers_url":"https://api.github.com/users/jonschlinkert/followers","following_url":"https://api.github.com/users/jonschlinkert/following{/other_user}","gists_url":"https://api.github.com/users/jonschlinkert/gists{/gist_id}","starred_url":"https://api.github.com/users/jonschlinkert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonschlinkert/subscriptions","organizations_url":"https://api.github.com/users/jonschlinkert/orgs","repos_url":"https://api.github.com/users/jonschlinkert/repos","events_url":"https://api.github.com/users/jonschlinkert/events{/privacy}","received_events_url":"https://api.github.com/users/jonschlinkert/received_events","type":"User","site_admin":false},"created_at":"2016-08-22T11:37:21Z","updated_at":"2016-08-22T11:37:21Z","body":"k, maybe this will help: \r\n\r\n```js\r\n\r\nfunction parse(input) {\r\n  var stack = [];\r\n  var ast = [{type: 'root', nodes: []}];\r\n\r\n  var len = input.length;\r\n  var idx = -1;\r\n  while (++idx < len) {\r\n    var ch = input[idx];\r\n    var prev = ast[ast.length - 1];\r\n\r\n    if (ch === '{') {\r\n      var tok = {\r\n        type: 'brace',\r\n        nodes: [{\r\n          type: 'brace.open',\r\n          val: ch\r\n        }]\r\n      };\r\n\r\n      if (stack.length) {\r\n        var last = stack[stack.length - 1];\r\n        last.nodes.push(tok);\r\n      } else {\r\n        prev.nodes.push(tok);\r\n      }\r\n\r\n      stack.push(tok);\r\n      continue;\r\n    }\r\n\r\n    if (ch === '}') {\r\n      var open = stack.pop();\r\n      if (open.type !== 'brace') {\r\n        throw new Error('missing opening \"}\"');\r\n      }\r\n      open.nodes.push({\r\n        type: 'brace.close',\r\n        val: ch\r\n      });\r\n      continue;\r\n    }\r\n\r\n    if (stack.length) {\r\n      var last = stack[stack.length - 1];\r\n      last.nodes.push({\r\n        type: 'text',\r\n        val: ch\r\n      });\r\n      continue;\r\n    }\r\n\r\n    prev.nodes.push({\r\n      type: 'text',\r\n      val: ch\r\n    });\r\n  }\r\n\r\n  return ast[0];\r\n}\r\n\r\nvar ast = parse('foo{bar{baz}qux}fez');\r\nconsole.log(ast.nodes);\r\n```\r\n\r\nThe single most important thing to get out of this is that there are two arrays:  `ast` AND `stack`. The stack should be empty when parsing is finished. It's main job is to determine two things:\r\n\r\n- if we receive a `closing` character, was the previous token on the stack an `opening` character? If not, we know that an opening character is missing.\r\n- if we receive an `opening` character, we check to see if the stack has any tokens on it. if it does, that means we're inside a nested structure. So instead of pushing tokens onto the AST, we want to push tokens onto the `nodes` array of the previous token on the stack. \r\n\r\nIf you log that out it will make sense pretty quick I think. You learn pretty darn fast lol"}}
{"actor":{"display_login":"jonschlinkert"}}