{"_id":"snapdragon-parser","_rev":"101778","name":"snapdragon-parser","description":"Easily parse a string to create an AST.","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"}],"time":{"modified":"2021-06-03T10:35:35.000Z","created":"2018-11-24T09:28:08.431Z","1.0.0":"2018-11-24T09:28:08.431Z"},"users":{},"author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git+https://github.com/here-be/snapdragon-parser.git"},"versions":{"1.0.0":{"name":"snapdragon-parser","description":"Easily parse a string to create an AST.","version":"1.0.0","homepage":"https://github.com/here-be/snapdragon-parser","author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git+https://github.com/here-be/snapdragon-parser.git"},"bugs":{"url":"https://github.com/here-be/snapdragon-parser/issues"},"license":"MIT","main":"index.js","engines":{"node":">=8"},"scripts":{"test":"nyc mocha"},"dependencies":{"snapdragon-lexer":"^4.0.0","snapdragon-node":"^3.0.0"},"devDependencies":{"gulp-format-md":"^2.0.0","mocha":"^5.2.0","nyc":"^13.1.0"},"keywords":["compile","compiler","convert","parse","parser","render","snapdragon","transform"],"nyc":{"reporter":["lcov","text-summary"]},"verb":{"toc":"collapsible","layout":"default","tasks":["readme"],"related":{"list":["snapdragon-lexer","snapdragon-node","snapdragon-position","snapdragon-token"]},"plugins":["gulp-format-md"],"lint":{"reflinks":true}},"gitHead":"d8f7fd97efaf6537746e9a9ce66d959dab619a7d","_id":"snapdragon-parser@1.0.0","_npmVersion":"6.4.1","_nodeVersion":"11.1.0","_npmUser":{"name":"jonschlinkert","email":"github@sellside.com"},"dist":{"shasum":"d411378c2e0c474f7d9049ae056b2660cdd55ba3","size":7303,"noattachment":false,"key":"/snapdragon-parser/-/snapdragon-parser-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/snapdragon-parser/download/snapdragon-parser-1.0.0.tgz"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/snapdragon-parser_1.0.0_1543051688290_0.6548089176120646"},"_hasShrinkwrap":false,"publish_time":1543051688431,"_cnpm_publish_time":1543051688431}},"readme":"# snapdragon-parser [![NPM version](https://img.shields.io/npm/v/snapdragon-parser.svg?style=flat)](https://www.npmjs.com/package/snapdragon-parser) [![NPM monthly downloads](https://img.shields.io/npm/dm/snapdragon-parser.svg?style=flat)](https://npmjs.org/package/snapdragon-parser) [![NPM total downloads](https://img.shields.io/npm/dt/snapdragon-parser.svg?style=flat)](https://npmjs.org/package/snapdragon-parser) [![Linux Build Status](https://img.shields.io/travis/here-be/snapdragon-parser.svg?style=flat&label=Travis)](https://travis-ci.org/here-be/snapdragon-parser)\n\n> Easily parse a string to create an AST.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Table of Contents\n\n<details>\n<summary><strong>Details</strong></summary>\n\n- [Install](#install)\n- [Usage](#usage)\n- [About](#about)\n\n</details>\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save snapdragon-parser\n```\n\n## Usage\n\n### [Parser](index.js#L21)\n\nCreate a new `Parser` with the given `input` and `options`.\n\n**Params**\n\n* `input` **{String}**\n* `options` **{Object}**\n\n**Example**\n\n```js\nconst Parser = require('snapdragon-parser');\nconst parser = new Parser();\n```\n\n### [.node](index.js#L72)\n\nCreate a new [Node](#node) with the given `value` and `type`.\n\n**Params**\n\n* `node` **{Object}**: The object to use to create a node\n* `returns` **{Object}**: returns the created [Node](#node) instance.\n\n**Example**\n\n```js\nconst node = parser.node({type: 'slash', value: '/'});\n// sugar for\nconst Node = require('snapdragon-node');\nconst node = Node({type: 'slash', value: '/'});\n```\n\n### [.isNode](index.js#L100)\n\nReturns true if the given value is an instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node).\n\n**Params**\n\n* `node` **{Object}**\n* `returns` **{Boolean}**\n\n### [.set](index.js#L119)\n\nRegister handler of the given `type`.\n\n**Params**\n\n* `type` **{String}**\n* `handler` **{Function}**\n\n**Example**\n\n```js\nparser.set('all', function(tok) {\n  // do stuff to tok\n  return tok;\n});\n```\n\n### [.get](index.js#L157)\n\nGet a registered handler function.\n\n**Params**\n\n* `type` **{String}**\n* `fn` **{Function}**: The handler function to register.\n\n**Example**\n\n```js\nhandlers.set('star', function() {\n  // do parser, lexer, or compiler stuff\n});\nconst star = handlers.get('star');\n```\n\n### [.has](index.js#L176)\n\nReturns true if the parser has a registered handler of the given `type`.\n\n**Params**\n\n* **{String}**: type\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nparser.set('star', function() {});\nconsole.log(parser.has('star')); // true\n```\n\n### [.capture](index.js#L228)\n\nCapture a node of the given `type`.\n\n**Params**\n\n* `type` **{String}**: (required)\n* `regex` **{RegExp}**: (optional)\n* `lexerFn` **{Function}**: (optional)\n* `parserFn` **{Function}**: (optional)\n* `returns` **{Object}**: Returns the Parser instance for chaining.\n\n### [.isInside](index.js#L251)\n\nReturns true if the parser is currently \"inside\" a node of the given `type`.\n\n**Params**\n\n* `type` **{String}**\n* `returns` **{Boolean}**\n\n### [.isBlock](index.js#L276)\n\nReturns true if `node` is a \"block\" node. Block nodes have a `nodes` array for keeping child nodes.\n\n**Params**\n\n* `node` **{Object}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nparser.isBlock(new Node()); //=> false\nparser.isBlock(new Node({ nodes: [] })); //=> true\n```\n\n### [.isBlock](index.js#L294)\n\nReturns true if `node` is a new \"block\" node, with either no child nodes, or only an open node.\n\n**Params**\n\n* `node` **{Object}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nparser.isBlock(new Node()); //=> false\nparser.isBlock(new Node({ nodes: [] })); //=> true\n```\n\n### [.isOpen](index.js#L307)\n\nReturns true if the given `node` is an \"open\" node.\n\n**Params**\n\n* `node` **{Object}**\n* `returns` **{Object}** `parentNode`\n\n### [.isClose](index.js#L330)\n\nReturns true if the given `node` is a \"close\" node.\n\n**Params**\n\n* `node` **{Object}**\n* `returns` **{Object}** `parentNode`\n\n### [.push](index.js#L360)\n\nPush a child node onto the `node.nodes` array of the current node on the `stack`.\n\n**Params**\n\n* `node` **{Object}**: (required)\n* `returns` **{Object}** `node`\n\n**Events**\n\n* `emits`: push\n\n**Example**\n\n```js\nparser.set('default', function(tok) {\n  return this.push(this.node(tok));\n});\n```\n\n### [.pop](index.js#L404)\n\nPop the last node from the `stack`. If a\n\n**Params**\n\n* `node` **{Object}**: (optional)\n* `returns` **{Object}** `node`\n\n**Events**\n\n* `emits`: pop\n\n**Example**\n\n```js\nparser.set('default', function(tok) {\n  return this.push(this.node(tok));\n});\n```\n\n### [.next](index.js#L428)\n\nGet the next token from the lexer, then calls the registered\nparser handler for `token.type` on the token.\n\n* `returns` **{Any}**: Returns whatever value the handler returns.\n\nExpect the given `type`, or throw an exception.\n\n**Params**\n\n* `type` **{String}**\n\nAccept the given `type`.\n\n**Params**\n\n* **{String}**: type\n\n### [.parse](index.js#L483)\n\nParses the given `input` string and returns an AST object.\n\n**Params**\n\n* `input` **{String}**\n* `returns` **{Object}**: Returns an AST (abstract syntax tree).\n\n**Example**\n\n```js\nconst ast = parser.parse('foo/bar');\n```\n\nCreates a new Parser instance with the given options, and copy\nthe handlers from the current instance to the new instance.\n\n**Params**\n\n* `options` **{Object}**\n* `parent` **{Object}**: Optionally pass a different parser instance to copy handlers from.\n* `returns` **{Object}**: Returns a new Parser instance\n\nConcat nodes from another AST to `node.nodes`.\n\n**Params**\n\n* `node` **{Object}**\n* `ast` **{Object}**\n* `returns` **{Object}**\n\n### [.hasListeners](index.js#L545)\n\nReturns true if listeners are registered for even `name`.\n\n**Params**\n\n* `name` **{String}**\n* `returns` **{Boolean}**\n\n**Params**\n\n* `fn` **{Function}**\n* `returns` **{Parser}**: Returns the Parser instance.\n\n**Example**\n\n```js\nconst myParser = new Parser();\nconst plugin = parser => {\n  // do stuff to parser instance\n};\nmyParser.use(plugin);\n```\n\n### [.error](index.js#L589)\n\nThrow a formatted error message with details including the cursor position.\n\n**Params**\n\n* `msg` **{String}**: Message to use in the Error.\n* `node` **{Object}**\n* `returns` **{Undefined}**\n\n**Example**\n\n```js\nparser.set('foo', function(tok) {\n  if (tok.value !== 'foo') {\n    throw this.error('expected token.value to be \"foo\"', tok);\n  }\n});\n```\n\nGet the part of the input string has has already been parsed.\n\n* `returns` **{String}**\n\n**Params**\n\n* `parser` **{Object}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nconst Parser = require('parser');\nconst parser = new Parser();\nconsole.log(Parser.isParser(parser)); //=> true\nconsole.log(Parser.isParser({})); //=> false\n```\n\n## About\n\n<details>\n<summary><strong>Contributing</strong></summary>\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\nPlease read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.\n\n</details>\n\n<details>\n<summary><strong>Running Tests</strong></summary>\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install && npm test\n```\n\n</details>\n\n<details>\n<summary><strong>Building docs</strong></summary>\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme && verb\n```\n\n</details>\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [snapdragon-lexer](https://www.npmjs.com/package/snapdragon-lexer): Converts a string into an array of tokens, with useful methods for looking ahead and… [more](https://github.com/here-be/snapdragon-lexer) | [homepage](https://github.com/here-be/snapdragon-lexer \"Converts a string into an array of tokens, with useful methods for looking ahead and behind, capturing, matching, et cetera.\")\n* [snapdragon-node](https://www.npmjs.com/package/snapdragon-node): Snapdragon utility for creating a new AST node in custom code, such as plugins. | [homepage](https://github.com/jonschlinkert/snapdragon-node \"Snapdragon utility for creating a new AST node in custom code, such as plugins.\")\n* [snapdragon-position](https://www.npmjs.com/package/snapdragon-position): Snapdragon util and plugin for patching the position on an AST node. | [homepage](https://github.com/here-be/snapdragon-position \"Snapdragon util and plugin for patching the position on an AST node.\")\n* [snapdragon-token](https://www.npmjs.com/package/snapdragon-token): Create a snapdragon token. Used by the snapdragon lexer, but can also be used by… [more](https://github.com/here-be/snapdragon-token) | [homepage](https://github.com/here-be/snapdragon-token \"Create a snapdragon token. Used by the snapdragon lexer, but can also be used by plugins.\")\n\n### Author\n\n**Jon Schlinkert**\n\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\n### License\n\nCopyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 24, 2018._","_attachments":{},"homepage":"https://github.com/here-be/snapdragon-parser","bugs":{"url":"https://github.com/here-be/snapdragon-parser/issues"},"license":"MIT"}