{"_id":"snapdragon-lexer","_rev":"15615","name":"snapdragon-lexer","description":"Converts a string into an array of tokens, with useful methods for looking ahead and behind, capturing, matching, et cetera.","dist-tags":{"latest":"4.0.0"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"}],"time":{"modified":"2021-06-03T09:58:52.000Z","created":"2017-12-01T03:11:12.881Z","4.0.0":"2018-11-19T16:28:00.463Z","3.1.0":"2018-02-16T16:09:37.465Z","3.0.0":"2018-01-11T10:11:03.475Z","2.0.0":"2018-01-08T18:08:05.651Z","1.0.0":"2017-12-01T03:11:12.881Z"},"users":{},"author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git+https://github.com/here-be/snapdragon-lexer.git"},"versions":{"4.0.0":{"name":"snapdragon-lexer","description":"Converts a string into an array of tokens, with useful methods for looking ahead and behind, capturing, matching, et cetera.","version":"4.0.0","homepage":"https://github.com/here-be/snapdragon-lexer","author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git+https://github.com/here-be/snapdragon-lexer.git"},"bugs":{"url":"https://github.com/here-be/snapdragon-lexer/issues"},"license":"MIT","main":"index.js","engines":{"node":">=8"},"scripts":{"test":"mocha","cover":"nyc --reporter=text --reporter=html mocha"},"devDependencies":{"define-property":"^2.0.2","gulp-format-md":"^2.0.0","mocha":"^5.2.0","nyc":"^13.1.0"},"keywords":["compile","compiler","convert","lexer","parse","parser","render","scan","scanner","snapdragon","token","tokenize","tokenizer","transform"],"verb":{"toc":"collapsible","layout":"default","tasks":["readme"],"plugins":["gulp-format-md"],"lint":{"reflinks":true},"related":{"list":["snapdragon-parser","snapdragon-scanner"]},"reflinks":["snapdragon-location","snapdragon-parser","snapdragon-position","snapdragon-token"]},"gitHead":"5af40ee82584602624b74c158f2a99f681de8a9a","_id":"snapdragon-lexer@4.0.0","_npmVersion":"6.4.1","_nodeVersion":"11.1.0","_npmUser":{"name":"jonschlinkert","email":"github@sellside.com"},"dist":{"shasum":"86e2fb96931e12060839000995b00d3551658292","size":12512,"noattachment":false,"key":"/snapdragon-lexer/-/snapdragon-lexer-4.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/snapdragon-lexer/download/snapdragon-lexer-4.0.0.tgz"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/snapdragon-lexer_4.0.0_1542644880342_0.2952717941416274"},"_hasShrinkwrap":false,"publish_time":1542644880463,"_cnpm_publish_time":1542644880463},"3.1.0":{"name":"snapdragon-lexer","description":"Converts a string into an array of tokens, with useful methods for looking ahead and behind, capturing, matching, et cetera.","version":"3.1.0","homepage":"https://github.com/here-be/snapdragon-lexer","author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git+https://github.com/here-be/snapdragon-lexer.git"},"bugs":{"url":"https://github.com/here-be/snapdragon-lexer/issues"},"license":"MIT","files":["index.js"],"main":"index.js","engines":{"node":">=6"},"scripts":{"test":"nyc mocha"},"dependencies":{"kind-of":"^6.0.2","snapdragon-handlers":"^1.0.0","snapdragon-stack":"^2.1.0","snapdragon-token":"^3.0.1"},"devDependencies":{"define-property":"^2.0.2","gulp-format-md":"^1.0.0","mocha":"^3.5.3","nyc":"^11.4.1","snapdragon-position":"^2.0.2"},"keywords":["compile","compiler","convert","lexer","parse","parser","render","snapdragon","token","tokenizer","transform"],"nyc":{"reporter":["lcov","text-summary"]},"verb":{"toc":"collapsible","layout":"default","tasks":["readme"],"plugins":["gulp-format-md"],"lint":{"reflinks":true},"related":{"list":["snapdragon-node","snapdragon-position","snapdragon-token"]},"reflinks":["snapdragon-location","snapdragon-parser","snapdragon-position","snapdragon-token"]},"gitHead":"1dda19c55a06f2697d92e806ed3228f2b920a03d","_id":"snapdragon-lexer@3.1.0","_npmVersion":"5.6.0","_nodeVersion":"9.5.0","_npmUser":{"name":"jonschlinkert","email":"github@sellside.com"},"dist":{"shasum":"d5a67fa96c17d339362fe0296c6c3f3383aabfa0","size":11682,"noattachment":false,"key":"/snapdragon-lexer/-/snapdragon-lexer-3.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/snapdragon-lexer/download/snapdragon-lexer-3.1.0.tgz"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/snapdragon-lexer_3.1.0_1518797377414_0.5109915046917395"},"_hasShrinkwrap":false,"publish_time":1518797377465,"_cnpm_publish_time":1518797377465},"3.0.0":{"name":"snapdragon-lexer","description":"Converts a string into an array of tokens, with useful methods for looking ahead and behind, capturing, matching, et cetera.","version":"3.0.0","homepage":"https://github.com/here-be/snapdragon-lexer","author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git+https://github.com/here-be/snapdragon-lexer.git"},"bugs":{"url":"https://github.com/here-be/snapdragon-lexer/issues"},"license":"MIT","files":["index.js"],"main":"index.js","engines":{"node":">=6"},"scripts":{"test":"nyc mocha"},"dependencies":{"kind-of":"^6.0.2","snapdragon-handlers":"^1.0.0","snapdragon-stack":"^2.0.0","snapdragon-token":"^3.0.1"},"devDependencies":{"define-property":"^2.0.0","gulp-format-md":"^1.0.0","mocha":"^3.5.3","nyc":"^11.4.1","snapdragon-position":"^2.0.2"},"keywords":["compile","compiler","convert","lexer","parse","parser","render","snapdragon","token","tokenizer","transform"],"nyc":{"reporter":["lcov","text-summary"]},"verb":{"toc":"collapsible","layout":"default","tasks":["readme"],"plugins":["gulp-format-md"],"lint":{"reflinks":true},"related":{"list":["snapdragon-node","snapdragon-position","snapdragon-token"]},"reflinks":["snapdragon-location","snapdragon-parser","snapdragon-position","snapdragon-token"]},"gitHead":"30ef1eedb8231f26d67f4c69d41a36513e3fd2b8","_id":"snapdragon-lexer@3.0.0","_npmVersion":"5.6.0","_nodeVersion":"9.1.0","_npmUser":{"name":"jonschlinkert","email":"github@sellside.com"},"dist":{"shasum":"ed0138a4ff4f38fa33efee23657998219f4a92db","size":11656,"noattachment":false,"key":"/snapdragon-lexer/-/snapdragon-lexer-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/snapdragon-lexer/download/snapdragon-lexer-3.0.0.tgz"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/snapdragon-lexer-3.0.0.tgz_1515665462280_0.7283402599859983"},"directories":{},"publish_time":1515665463475,"_hasShrinkwrap":false,"_cnpm_publish_time":1515665463475},"2.0.0":{"name":"snapdragon-lexer","description":"Converts a string into an array of tokens, with useful methods for looking ahead and behind, capturing, matching, et cetera.","version":"2.0.0","homepage":"https://github.com/here-be/snapdragon-lexer","author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git+https://github.com/here-be/snapdragon-lexer.git"},"bugs":{"url":"https://github.com/here-be/snapdragon-lexer/issues"},"license":"MIT","files":["index.js"],"main":"index.js","engines":{"node":">=6"},"scripts":{"test":"nyc mocha"},"dependencies":{"kind-of":"^6.0.2","snapdragon-handlers":"^1.0.0","snapdragon-stack":"^1.0.1","snapdragon-token":"^3.0.1"},"devDependencies":{"define-property":"^2.0.0","gulp-format-md":"^1.0.0","mocha":"^3.5.3","nyc":"^11.4.1","snapdragon-position":"^2.0.2"},"keywords":["compile","compiler","convert","lexer","parse","parser","render","snapdragon","token","tokenizer","transform"],"nyc":{"reporter":["lcov","text-summary"]},"verb":{"toc":"collapsible","layout":"default","tasks":["readme"],"plugins":["gulp-format-md"],"lint":{"reflinks":true},"related":{"list":["snapdragon-node","snapdragon-position","snapdragon-token"]},"reflinks":["snapdragon-position","snapdragon-token","snapdragon-location","snapdragon-parser"]},"gitHead":"db19fd42c482076299c2d55e9faaa8217f37d59b","_id":"snapdragon-lexer@2.0.0","_npmVersion":"5.6.0","_nodeVersion":"9.1.0","_npmUser":{"name":"jonschlinkert","email":"github@sellside.com"},"dist":{"shasum":"c6b05182545697e3c967412e3b541b698f060bcb","size":11647,"noattachment":false,"key":"/snapdragon-lexer/-/snapdragon-lexer-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/snapdragon-lexer/download/snapdragon-lexer-2.0.0.tgz"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/snapdragon-lexer-2.0.0.tgz_1515434885549_0.09572881367057562"},"directories":{},"publish_time":1515434885651,"_cnpm_publish_time":1515434885651,"_hasShrinkwrap":false},"1.0.0":{"name":"snapdragon-lexer","description":"Converts a string into an array of tokens, with useful methods for looking ahead and behind, capturing, matching, et cetera.","version":"1.0.0","homepage":"https://github.com/here-be-snapdragons/snapdragon-lexer","author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git+https://github.com/here-be-snapdragons/snapdragon-lexer.git"},"bugs":{"url":"https://github.com/here-be-snapdragons/snapdragon-lexer/issues"},"license":"MIT","files":["index.js"],"main":"index.js","engines":{"node":">=4"},"scripts":{"test":"mocha"},"dependencies":{"@sellside/emitter":"^1.0.5","snapdragon-token":"^2.0.0","union-value":"^1.0.0","use":"^3.0.0"},"devDependencies":{"snapdragon-position":"^1.0.0","mocha":"^4.0.1","define-property":"^2.0.0","gulp-format-md":"^1.0.0"},"keywords":["compile","compiler","convert","lexer","parse","parser","render","snapdragon","transform"],"verb":{"toc":false,"layout":"default","tasks":["readme"],"plugins":["gulp-format-md"],"lint":{"reflinks":true},"related":{"list":["snapdragon-node","snapdragon-position","snapdragon-token"]},"reflinks":["snapdragon-position","snapdragon-token"]},"gitHead":"d8dcaef2390ffe02ede6458c39ceabfad5693768","_id":"snapdragon-lexer@1.0.0","_npmVersion":"5.5.1","_nodeVersion":"9.1.0","_npmUser":{"name":"jonschlinkert","email":"github@sellside.com"},"dist":{"shasum":"4179aa551fadac85f97762e5990948436449133b","size":8312,"noattachment":false,"key":"/snapdragon-lexer/-/snapdragon-lexer-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/snapdragon-lexer/download/snapdragon-lexer-1.0.0.tgz"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/snapdragon-lexer-1.0.0.tgz_1512097871514_0.6180952994618565"},"directories":{},"publish_time":1512097872881,"_cnpm_publish_time":1512097872881,"_hasShrinkwrap":false}},"readme":"# snapdragon-lexer [![NPM version](https://img.shields.io/npm/v/snapdragon-lexer.svg?style=flat)](https://www.npmjs.com/package/snapdragon-lexer) [![NPM monthly downloads](https://img.shields.io/npm/dm/snapdragon-lexer.svg?style=flat)](https://npmjs.org/package/snapdragon-lexer) [![NPM total downloads](https://img.shields.io/npm/dt/snapdragon-lexer.svg?style=flat)](https://npmjs.org/package/snapdragon-lexer) [![Linux Build Status](https://img.shields.io/travis/here-be/snapdragon-lexer.svg?style=flat&label=Travis)](https://travis-ci.org/here-be/snapdragon-lexer)\n\n> Converts a string into an array of tokens, with useful methods for looking ahead and behind, capturing, matching, et cetera.\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- [Breaking changes in v2.0!](#breaking-changes-in-v20)\n- [Usage](#usage)\n- [API](#api)\n  * [.set](#set)\n  * [.get](#get)\n- [Properties](#properties)\n  * [lexer.isLexer](#lexerislexer)\n  * [lexer.input](#lexerinput)\n  * [lexer.string](#lexerstring)\n  * [lexer.consumed](#lexerconsumed)\n  * [lexer.tokens](#lexertokens)\n  * [lexer.stash](#lexerstash)\n  * [lexer.stack](#lexerstack)\n  * [lexer.queue](#lexerqueue)\n  * [lexer.loc](#lexerloc)\n- [Options](#options)\n  * [options.source](#optionssource)\n  * [options.mode](#optionsmode)\n  * [options.value](#optionsvalue)\n- [Tokens](#tokens)\n- [Plugins](#plugins)\n  * [Plugin Conventions](#plugin-conventions)\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-lexer\n```\n\n## Breaking changes in v2.0!\n\nPlease see the [changelog](CHANGELOG.md) for details!\n\n## Usage\n\n```js\nconst Lexer = require('snapdragon-lexer');\nconst lexer = new Lexer();\n\nlexer.capture('slash', /^\\//);\nlexer.capture('text', /^\\w+/);\nlexer.capture('star', /^\\*/);\n\nconsole.log(lexer.tokenize('foo/*'));\n```\n\n## API\n\n### [Lexer](index.js#L23)\n\nCreate a new `Lexer` with the given `options`.\n\n**Params**\n\n* `input` **{string|Object}**: (optional) Input string or options. You can also set input directly on `lexer.input` after initializing.\n* `options` **{object}**\n\n**Example**\n\n```js\nconst Lexer = require('snapdragon-lexer');\nconst lexer = new Lexer('foo/bar');\n```\n\n### [.bos](index.js#L53)\n\nReturns true if we are still at the beginning-of-string, and\nno part of the string has been consumed.\n\n* `returns` **{boolean}**\n\n### [.eos](index.js#L65)\n\nReturns true if `lexer.string` and `lexer.queue` are empty.\n\n* `returns` **{boolean}**\n\n### [.set](index.js#L83)\n\nRegister a handler function.\n\n**Params**\n\n* `type` **{string}**\n* `fn` **{function}**: The handler function to register.\n\n**Example**\n\n```js\nlexer.set('star', function() {\n  // do parser, lexer, or compiler stuff\n});\n```\n\n### [.get](index.js#L119)\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\nlexer.set('star', function() {\n  // do lexer stuff\n});\nconst star = lexer.get('star');\n```\n\n### [.has](index.js#L138)\n\nReturns true if the lexer has a registered handler of the given `type`.\n\n**Params**\n\n* **{string}**: type\n* `returns` **{boolean}**\n\n**Example**\n\n```js\nlexer.set('star', function() {});\nconsole.log(lexer.has('star')); // true\n```\n\n### [.token](index.js#L159)\n\nCreate a new [Token](https://github.com/here-be/snapdragon-token) with the given `type` and `value`.\n\n**Params**\n\n* `type` **{string|Object}**: (required) The type of token to create\n* `value` **{string}**: (optional) The captured string\n* `match` **{array}**: (optional) Match results from `String.match()` or `RegExp.exec()`\n* `returns` **{Object}**: Returns an instance of [snapdragon-token](https://github.com/here-be/snapdragon-token)\n\n**Events**\n\n* `emits`: token\n\n**Example**\n\n```js\nconsole.log(lexer.token({type: 'star', value: '*'}));\nconsole.log(lexer.token('star', '*'));\nconsole.log(lexer.token('star'));\n```\n\n### [.isToken](index.js#L179)\n\nReturns true if the given value is a [snapdragon-token](https://github.com/here-be/snapdragon-token) instance.\n\n**Params**\n\n* `token` **{object}**\n* `returns` **{boolean}**\n\n**Example**\n\n```js\nconst Token = require('snapdragon-token');\nlexer.isToken({}); // false\nlexer.isToken(new Token({type: 'star', value: '*'})); // true\n```\n\n### [.consume](index.js#L198)\n\nConsume the given length from `lexer.string`. The consumed value is used to update `lexer.state.consumed`, as well as the current position.\n\n**Params**\n\n* `len` **{number}**\n* `value` **{string}**: Optionally pass the value being consumed.\n* `returns` **{String}**: Returns the consumed value\n\n**Example**\n\n```js\nlexer.consume(1);\nlexer.consume(1, '*');\n```\n\nReturns a function for updating a token with lexer\nlocation information.\n\n* `returns` **{function}**\n\n### [.match](index.js#L255)\n\nUse the given `regex` to match a substring from `lexer.string`. Also validates the regex to ensure that it starts with `^` since matching should always be against the beginning of the string, and throws if the regex matches an empty string, which can cause catastrophic backtracking.\n\n**Params**\n\n* `regex` **{regExp}**: (required)\n* `returns` **{Array|null}**: Returns the match array from `RegExp.exec` or null.\n\n**Example**\n\n```js\nconst lexer = new Lexer('foo/bar');\nconst match = lexer.match(/^\\w+/);\nconsole.log(match);\n//=> [ 'foo', index: 0, input: 'foo/bar' ]\n```\n\n### [.scan](index.js#L301)\n\nScan for a matching substring by calling [.match()](#match) with the given `regex`. If a match is found, 1) a token of the specified `type` is created, 2) `match[0]` is used as `token.value`, and 3) the length of `match[0]` is sliced from `lexer.string` (by calling [.consume()](#consume)).\n\n**Params**\n\n* `type` **{string}**\n* `regex` **{regExp}**\n* `returns` **{Object}**: Returns a token if a match is found, otherwise undefined.\n\n**Events**\n\n* `emits`: scan\n\n**Example**\n\n```js\nlexer.string = '/foo/';\nconsole.log(lexer.scan(/^\\//, 'slash'));\n//=> Token { type: 'slash', value: '/' }\nconsole.log(lexer.scan(/^\\w+/, 'text'));\n//=> Token { type: 'text', value: 'foo' }\nconsole.log(lexer.scan(/^\\//, 'slash'));\n//=> Token { type: 'slash', value: '/' }\n```\n\n### [.capture](index.js#L338)\n\nCapture a token of the specified `type` using the provide `regex` for scanning and matching substrings. Automatically registers a handler when a function is passed as the last argument.\n\n**Params**\n\n* `type` **{string}**: (required) The type of token being captured.\n* `regex` **{regExp}**: (required) The regex for matching substrings.\n* `fn` **{function}**: (optional) If supplied, the function will be called on the token before pushing it onto `lexer.tokens`.\n* `returns` **{Object}**\n\n**Example**\n\n```js\nlexer.capture('text', /^\\w+/);\nlexer.capture('text', /^\\w+/, token => {\n  if (token.value === 'foo') {\n    // do stuff\n  }\n  return token;\n});\n```\n\n### [.handle](index.js#L370)\n\nCalls handler `type` on `lexer.string`.\n\n**Params**\n\n* `type` **{string}**: The handler type to call on `lexer.string`\n* `returns` **{Object}**: Returns a token of the given `type` or undefined.\n\n**Events**\n\n* `emits`: handle\n\n**Example**\n\n```js\nconst lexer = new Lexer('/a/b');\nlexer.capture('slash', /^\\//);\nlexer.capture('text', /^\\w+/);\nconsole.log(lexer.handle('text'));\n//=> undefined\nconsole.log(lexer.handle('slash'));\n//=> { type: 'slash', value: '/' }\nconsole.log(lexer.handle('text'));\n//=> { type: 'text', value: 'a' }\n```\n\n### [.advance](index.js#L393)\n\nGet the next token by iterating over `lexer.handlers` and calling each handler on `lexer.string` until a handler returns a token. If no handlers return a token, an error is thrown with the substring that couldn't be lexed.\n\n* `returns` **{Object}**: Returns the first token returned by a handler, or the first character in the remaining string if `options.mode` is set to `character`.\n\n**Example**\n\n```js\nconst token = lexer.advance();\n```\n\n### [.lex](index.js#L429)\n\nTokenizes a string and returns an array of tokens.\n\n**Params**\n\n* `input` **{string}**: The string to lex.\n* `returns` **{Array}**: Returns an array of tokens.\n\n**Example**\n\n```js\nlet lexer = new Lexer({ handlers: otherLexer.handlers })\nlexer.capture('slash', /^\\//);\nlexer.capture('text', /^\\w+/);\nconst tokens = lexer.lex('a/b/c');\nconsole.log(tokens);\n// Results in:\n// [ Token { type: 'text', value: 'a' },\n//   Token { type: 'slash', value: '/' },\n//   Token { type: 'text', value: 'b' },\n//   Token { type: 'slash', value: '/' },\n//   Token { type: 'text', value: 'c' } ]\n```\n\n### [.enqueue](index.js#L454)\n\nPush a token onto the `lexer.queue` array.\n\n**Params**\n\n* `token` **{object}**\n* `returns` **{Object}**: Returns the given token with updated `token.index`.\n\n**Example**\n\n```js\nconsole.log(lexer.queue.length); // 0\nlexer.enqueue(new Token('star', '*'));\nconsole.log(lexer.queue.length); // 1\n```\n\n### [.dequeue](index.js#L472)\n\nShift a token from `lexer.queue`.\n\n* `returns` **{Object}**: Returns the given token with updated `token.index`.\n\n**Example**\n\n```js\nconsole.log(lexer.queue.length); // 1\nlexer.dequeue();\nconsole.log(lexer.queue.length); // 0\n```\n\n### [.lookbehind](index.js#L488)\n\nLookbehind `n` tokens.\n\n**Params**\n\n* `n` **{number}**\n* `returns` **{Object}**\n\n**Example**\n\n```js\nconst token = lexer.lookbehind(2);\n```\n\n### [.prev](index.js#L504)\n\nGet the previously lexed token.\n\n* `returns` **{Object|undefined}**: Returns a token or undefined.\n\n**Example**\n\n```js\nconst token = lexer.prev();\n```\n\n### [.lookahead](index.js#L522)\n\nLookahead `n` tokens and return the last token. Pushes any intermediate tokens onto `lexer.tokens.` To lookahead a single token, use [.peek()](#peek).\n\n**Params**\n\n* `n` **{number}**\n* `returns` **{Object}**\n\n**Example**\n\n```js\nconst token = lexer.lookahead(2);\n```\n\n### [.peek](index.js#L540)\n\nLookahead a single token.\n\n* `returns` **{Object}**: Returns a token.\n\n**Example**\n\n```js\nconst token = lexer.peek();\n```\n\n### [.next](index.js#L555)\n\nGet the next token, either from the `queue` or by [advancing](#advance).\n\n* `returns` **{Object|String}**: Returns a token, or (when `options.mode` is set to `character`) either gets the next character from `lexer.queue`, or consumes the next charcter in the string.\n\n**Example**\n\n```js\nconst token = lexer.next();\n```\n\n### [.skip](index.js#L571)\n\nSkip `n` tokens or characters in the string. Skipped values are not enqueued.\n\n**Params**\n\n* `n` **{number}**\n* `returns` **{Object}**: returns an array of skipped tokens.\n\n**Example**\n\n```js\nconst token = lexer.skip(1);\n```\n\n### [.skipWhile](index.js#L588)\n\nSkip tokens while the given `fn` returns true.\n\n**Params**\n\n* `fn` **{function}**: Return true if a token should be skipped.\n* `returns` **{Array}**: Returns an array if skipped tokens.\n\n**Example**\n\n```js\nlexer.skipWhile(tok => tok.type !== 'space');\n```\n\n### [.skipType](index.js#L606)\n\nSkip the given token `types`.\n\n**Params**\n\n* `types` **{string|Array}**: One or more token types to skip.\n* `returns` **{Array}**: Returns an array if skipped tokens.\n\n**Example**\n\n```js\nlexer.skipWhile(tok => tok.type !== 'space');\n```\n\n### [.skipType](index.js#L623)\n\nSkip the given token `types`.\n\n**Params**\n\n* `types` **{string|Array}**: One or more token types to skip.\n* `returns` **{Array}**: Returns an array if skipped tokens\n\n**Example**\n\n```js\nlexer.skipType('space');\nlexer.skipType(['newline', 'space']);\n```\n\n### [.push](index.js#L645)\n\nPushes the given `token` onto `lexer.tokens` and calls [.append()](#append) to push `token.value` onto `lexer.stash`. Disable pushing onto the stash by setting `lexer.options.append` or `token.append` to `false`.\n\n**Params**\n\n* `token` **{object|String}**\n* `returns` **{Object}**: Returns the given `token`.\n\n**Events**\n\n* `emits`: push\n\n**Example**\n\n```js\nconsole.log(lexer.tokens.length); // 0\nlexer.push(new Token('star', '*'));\nconsole.log(lexer.tokens.length); // 1\nconsole.log(lexer.stash) // ['*']\n```\n\n### [.append](index.js#L686)\n\nAppend a string to the last element on `lexer.stash`, or push the string onto the stash if no elements exist.\n\n**Params**\n\n* `value` **{String}**\n* `returns` **{String}**: Returns the last value in the array.\n\n**Example**\n\n```js\nconst stack = new Stack();\nstack.push('a');\nstack.push('b');\nstack.push('c');\nstack.append('_foo');\nstack.append('_bar');\nconsole.log(stack);\n//=> Stack ['a', 'b', 'c_foo_bar']\n```\n\n### [.isInside](index.js#L712)\n\nReturns true if a token with the given `type` is on the stack.\n\n**Params**\n\n* `type` **{string}**: The type to check for.\n* `returns` **{boolean}**\n\n**Example**\n\n```js\nif (lexer.isInside('bracket') || lexer.isInside('brace')) {\n  // do stuff\n}\n```\n\n### [.error](index.js#L733)\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\nlexer.set('foo', function(tok) {\n  if (tok.value !== 'foo') {\n    throw this.state.error('expected token.value to be \"foo\"', tok);\n  }\n});\n```\n\n### [.use](index.js#L774)\n\nCall a plugin function on the lexer instance.\n\n**Params**\n\n* `fn` **{function}**\n* `returns` **{object}**: Returns the lexer instance.\n\n**Example**\n\n```js\nlexer.use(function(lexer) {\n  // do stuff to lexer\n});\n```\n\n### [Lexer#isLexer](index.js#L796)\n\nStatic method that returns true if the given value is an instance of `snapdragon-lexer`.\n\n**Params**\n\n* `lexer` **{object}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nconst Lexer = require('snapdragon-lexer');\nconst lexer = new Lexer();\nconsole.log(Lexer.isLexer(lexer)); //=> true\nconsole.log(Lexer.isLexer({})); //=> false\n```\n\n### [Lexer#isToken](index.js#L817)\n\nStatic method that returns true if the given value is an instance of `snapdragon-token`. This is a proxy to `Token#isToken`.\n\n**Params**\n\n* `lexer` **{object}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nconst Token = require('snapdragon-token');\nconst Lexer = require('snapdragon-lexer');\nconsole.log(Lexer.isToken(new Token({type: 'foo'}))); //=> true\nconsole.log(Lexer.isToken({})); //=> false\n```\n\n### [Lexer#State](index.js#L828)\n\nThe State class, exposed as a static property.\n\n### [Lexer#Token](index.js#L839)\n\nThe Token class, exposed as a static property.\n\n### .set\n\nRegister a handler function.\n\n**Params**\n\n* `type` **{String}**\n* `fn` **{Function}**: The handler function to register.\n\n**Example**\n\n```js\nlexer.set('star', function(token) {\n  // do parser, lexer, or compiler stuff\n});\n```\n\nAs an alternative to `.set`, the [.capture](#capture) method will automatically register a handler when a function is passed as the last argument.\n\n### .get\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\nlexer.set('star', function() {\n  // do parser, lexer, or compiler stuff\n});\nconst star = handlers.get('star');\n```\n\n## Properties\n\n### lexer.isLexer\n\nType: **{boolean}**\n\nDefault: `true` (contant)\n\nThis property is defined as a convenience, to make it easy for plugins to check for an instance of Lexer.\n\n### lexer.input\n\nType: **{string}**\n\nDefault: `''`\n\nThe unmodified source string provided by the user.\n\n### lexer.string\n\nType: **{string}**\n\nDefault: `''`\n\nThe source string minus the part of the string that has already been [consumed](#consume).\n\n### lexer.consumed\n\nType: **{string}**\n\nDefault: `''`\n\nThe part of the source string that has been consumed.\n\n### lexer.tokens\n\nType: **{array}**\n\nDefault: `[]\n\nArray of lexed tokens.\n\n### lexer.stash\n\nType: **{array}**\n\nDefault: `['']` (instance of [snapdragon-stack](https://github.com/here-be/snapdragon-stack))\n\nArray of captured strings. Similar to the [lexer.tokens](#lexertokens) array, but stores strings instead of token objects.\n\n### lexer.stack\n\nType: **{array}**\n\nDefault: `[]\n\nLIFO (last in, first out) array. A token is pushed onto the stack when an \"opening\" character or character sequence needs to be tracked. When the (matching) \"closing\" character or character sequence is encountered, the (opening) token is popped off of the stack.\n\nThe stack is not used by any lexer methods, it's reserved for the user. Stacks are necessary for creating Abstract Syntax Trees (ASTs), but if you require this functionality it would be better to use a parser such as [snapdragon-parser][snapdragon-parser], with methods and other conveniences for creating an AST.\n\n### lexer.queue\n\nType: **{array}**\n\nDefault: `[]\n\nFIFO (first in, first out) array, for temporarily storing tokens that are created when [.lookahead()](#lookahead) is called (or a method that calls `.lookhead()`, such as [.peek()](#peek)).\n\nTokens are [dequeued](#dequeue) when [.next()](#next) is called.\n\n### lexer.loc\n\nType: **{Object}**\n\nDefault: `{ index: 0, column: 0, line: 1 }`\n\nThe updated source string location with the following properties.\n\n* `index` - 0-index\n* `column` - 0-index\n* `line` - 1-index\n\nThe following plugins are available for automatically updating tokens with the location:\n\n* [snapdragon-location](https://github.com/here-be/snapdragon-location)\n* [snapdragon-position](https://github.com/here-be/snapdragon-position)\n\n## Options\n\n### options.source\n\nType: **{string}**\n\nDefault: `undefined`\n\nThe source of the input string. This is typically a filename or file path, but can also be `'string'` if a string or buffer is provided directly.\n\nIf `lexer.input` is undefined, and `options.source` is a string, the lexer will attempt to set `lexer.input` by calling `fs.readFileSync()` on the value provided on `options.source`.\n\n### options.mode\n\nType: **{string}**\n\nDefault: `undefined`\n\nIf `options.mode` is `character`, instead of calling handlers (which match using regex) the [.advance()](advance) method will [consume](#consume) and return one character at a time.\n\n### options.value\n\nType: **{string}**\n\nDefault: `undefined`\n\nSpecify the token property to use when the [.push](#push) method pushes a value onto [lexer.stash](#lexerstash). The logic works something like this:\n\n```js\nlexer.append(token[lexer.options.value || 'value']);\n```\n\n## Tokens\n\nSee the [snapdragon-token](https://github.com/here-be/snapdragon-token) documentation for more details.\n\n## Plugins\n\nPlugins are registered with the `lexer.use()` method and use the following conventions.\n\n### Plugin Conventions\n\nPlugins are functions that take an instance of snapdragon-lexer.\n\nHowever, it's recommended that you always wrap your plugin function in another function that takes an options object. This allow users to pass options when using the plugin. _Even if your plugin doesn't take options, it's a best practice for users to always be able to use the same signature_.\n\n**Example**\n\n```js\nfunction plugin(options) {\n  return function(lexer) {\n    // do stuff \n  };\n}\n\nlexer.use(plugin());\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-scanner](https://www.npmjs.com/package/snapdragon-scanner): Easily scan a string with an object of regex patterns to produce an array of… [more](https://github.com/here-be/snapdragon-scanner) | [homepage](https://github.com/here-be/snapdragon-scanner \"Easily scan a string with an object of regex patterns to produce an array of tokens. ~100 sloc.\")\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 19, 2018._","_attachments":{},"homepage":"https://github.com/here-be/snapdragon-lexer","bugs":{"url":"https://github.com/here-be/snapdragon-lexer/issues"},"license":"MIT"}