pax_global_header00006660000000000000000000000064132703266210014514gustar00rootroot0000000000000052 comment=dbb6a209b8f1afc9117f888b59d05c4d2632d520 snapdragon-token-4.0.0/000077500000000000000000000000001327032662100147675ustar00rootroot00000000000000snapdragon-token-4.0.0/.editorconfig000066400000000000000000000004411327032662100174430ustar00rootroot00000000000000# http://editorconfig.org/ root = true [*] charset = utf-8 end_of_line = lf indent_size = 2 indent_style = space insert_final_newline = true trim_trailing_whitespace = true [{**/{actual,fixtures,expected,templates}/**,*.md}] trim_trailing_whitespace = false insert_final_newline = false snapdragon-token-4.0.0/.eslintrc.json000066400000000000000000000073251327032662100175720ustar00rootroot00000000000000{ "extends": [ "eslint:recommended" ], "env": { "browser": false, "es6": true, "node": true, "mocha": true }, "parserOptions":{ "ecmaVersion": 9, "sourceType": "module", "ecmaFeatures": { "modules": true, "experimentalObjectRestSpread": true } }, "globals": { "document": false, "navigator": false, "window": false }, "rules": { "accessor-pairs": 2, "arrow-spacing": [2, { "before": true, "after": true }], "block-spacing": [2, "always"], "brace-style": [2, "1tbs", { "allowSingleLine": true }], "comma-dangle": [2, "never"], "comma-spacing": [2, { "before": false, "after": true }], "comma-style": [2, "last"], "constructor-super": 2, "curly": [2, "multi-line"], "dot-location": [2, "property"], "eol-last": 2, "eqeqeq": [2, "allow-null"], "generator-star-spacing": [2, { "before": true, "after": true }], "handle-callback-err": [2, "^(err|error)$" ], "indent": [2, 2, { "SwitchCase": 1 }], "key-spacing": [2, { "beforeColon": false, "afterColon": true }], "keyword-spacing": [2, { "before": true, "after": true }], "new-cap": [2, { "newIsCap": true, "capIsNew": false }], "new-parens": 2, "no-array-constructor": 2, "no-caller": 2, "no-class-assign": 2, "no-cond-assign": 2, "no-const-assign": 2, "no-control-regex": 2, "no-debugger": 2, "no-delete-var": 2, "no-dupe-args": 2, "no-dupe-class-members": 2, "no-dupe-keys": 2, "no-duplicate-case": 2, "no-empty-character-class": 2, "no-eval": 2, "no-ex-assign": 2, "no-extend-native": 2, "no-extra-bind": 2, "no-extra-boolean-cast": 2, "no-extra-parens": [2, "functions"], "no-fallthrough": 2, "no-floating-decimal": 2, "no-func-assign": 2, "no-implied-eval": 2, "no-inner-declarations": [2, "functions"], "no-invalid-regexp": 2, "no-irregular-whitespace": 2, "no-iterator": 2, "no-label-var": 2, "no-labels": 2, "no-lone-blocks": 2, "no-mixed-spaces-and-tabs": 2, "no-multi-spaces": 2, "no-multi-str": 2, "no-multiple-empty-lines": [2, { "max": 1 }], "no-native-reassign": 0, "no-negated-in-lhs": 2, "no-new": 2, "no-new-func": 2, "no-new-object": 2, "no-new-require": 2, "no-new-wrappers": 2, "no-obj-calls": 2, "no-octal": 2, "no-octal-escape": 2, "no-proto": 0, "no-redeclare": 2, "no-regex-spaces": 2, "no-return-assign": 2, "no-self-compare": 2, "no-sequences": 2, "no-shadow-restricted-names": 2, "no-spaced-func": 2, "no-sparse-arrays": 2, "no-this-before-super": 2, "no-throw-literal": 2, "no-trailing-spaces": 0, "no-undef": 2, "no-undef-init": 2, "no-unexpected-multiline": 2, "no-unneeded-ternary": [2, { "defaultAssignment": false }], "no-unreachable": 2, "no-unused-vars": [2, { "vars": "all", "args": "none" }], "no-useless-call": 0, "no-with": 2, "one-var": [0, { "initialized": "never" }], "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], "padded-blocks": [0, "never"], "quotes": [2, "single", "avoid-escape"], "radix": 2, "semi": [2, "always"], "semi-spacing": [2, { "before": false, "after": true }], "space-before-blocks": [2, "always"], "space-before-function-paren": [2, "never"], "space-in-parens": [2, "never"], "space-infix-ops": 2, "space-unary-ops": [2, { "words": true, "nonwords": false }], "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], "use-isnan": 2, "valid-typeof": 2, "wrap-iife": [2, "any"], "yoda": [2, "never"] } } snapdragon-token-4.0.0/.gitattributes000066400000000000000000000002001327032662100176520ustar00rootroot00000000000000# Enforce Unix newlines * text eol=lf # binaries *.ai binary *.psd binary *.jpg binary *.gif binary *.png binary *.jpeg binary snapdragon-token-4.0.0/.github/000077500000000000000000000000001327032662100163275ustar00rootroot00000000000000snapdragon-token-4.0.0/.github/contributing.md000066400000000000000000000063431327032662100213660ustar00rootroot00000000000000# Contributing to snapdragon-token First and foremost, thank you! We appreciate that you want to contribute to snapdragon-token, your time is valuable, and your contributions mean a lot to us. **What does "contributing" mean?** Creating an issue is the simplest form of contributing to a project. But there are many ways to contribute, including the following: - Updating or correcting documentation - Feature requests - Bug reports If you'd like to learn more about contributing in general, the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) has a lot of useful information. **Showing support for snapdragon-token** Please keep in mind that open source software is built by people like you, who spend their free time creating things the rest the community can use. Don't have time to contribute? No worries, here are some other ways to show your support for snapdragon-token: - star the [project](https://github.com/here-be/snapdragon-token) - tweet your support for snapdragon-token ## Issues ### Before creating an issue Please try to determine if the issue is caused by an underlying library, and if so, create the issue there. Sometimes this is difficult to know. We only ask that you attempt to give a reasonable attempt to find out. Oftentimes the readme will have advice about where to go to create issues. Try to follow these guidelines - **Investigate the issue**: - **Check the readme** - oftentimes you will find notes about creating issues, and where to go depending on the type of issue. - Create the issue in the appropriate repository. ### Creating an issue Please be as descriptive as possible when creating an issue. Give us the information we need to successfully answer your question or address your issue by answering the following in your issue: - **version**: please note the version of snapdragon-token are you using - **extensions, plugins, helpers, etc** (if applicable): please list any extensions you're using - **error messages**: please paste any error messages into the issue, or a [gist](https://gist.github.com/) ## Above and beyond Here are some tips for creating idiomatic issues. Taking just a little bit extra time will make your issue easier to read, easier to resolve, more likely to be found by others who have the same or similar issue in the future. - read the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) - take some time to learn basic markdown. This [markdown cheatsheet](https://gist.github.com/jonschlinkert/5854601) is super helpful, as is the GitHub guide to [basic markdown](https://help.github.com/articles/markdown-basics/). - Learn about [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown/). And if you want to really go above and beyond, read [mastering markdown](https://guides.github.com/features/mastering-markdown/). - use backticks to wrap code. This ensures that code will retain its format, making it much more readable to others - use syntax highlighting by adding the correct language name after the first "code fence" [node-glob]: https://github.com/isaacs/node-glob [micromatch]: https://github.com/jonschlinkert/micromatch [so]: http://stackoverflow.com/questions/tagged/snapdragon-tokensnapdragon-token-4.0.0/.gitignore000066400000000000000000000004561327032662100167640ustar00rootroot00000000000000# always ignore files *.DS_Store .idea .vscode *.sublime-* # test related, or directories generated by tests test/actual actual coverage .nyc* # npm node_modules npm-debug.log # yarn yarn.lock yarn-error.log # misc _gh_pages _draft _drafts bower_components vendor temp tmp TODO.md package-lock.jsonsnapdragon-token-4.0.0/.npmrc000066400000000000000000000000231327032662100161020ustar00rootroot00000000000000package-lock=false snapdragon-token-4.0.0/.travis.yml000066400000000000000000000001461327032662100171010ustar00rootroot00000000000000sudo: false os: - linux - osx language: node_js node_js: - node - '9' - '8' - '7' - '6' snapdragon-token-4.0.0/.verb.md000066400000000000000000000021011327032662100163170ustar00rootroot00000000000000## Usage ```js const Token = require('{%= name %}'); ``` ## API {%= apidocs("index.js") %} ## Release history See [the changelog](CHANGELOG.md). ## Token objects Lexer tokens are represented as `Token` objects that implement the following interface: ```js interface Token { type: string; value: string; match: array | undefined; } ``` ### Token properties - `type` **{string}** - A string representing the token variant type. This property is necessary for classifying one or more characters so that parsers or compilers can determine what to do with the token. - `value` **{string}** - The substring (or [lexeme]()) that was captured for the token. - `match` **{array|undefined}** - If a regular expression was used to capture a substring, the `RegExp.exec()` or `String.match()` arguments array can be stored on the token. **Source location** Add the source location (start, end, index and range) information to tokens using either of the following plugins (depending on preference for property naming conventions): - [snapdragon-position][] - [snapdragon-location][] snapdragon-token-4.0.0/CHANGELOG.md000066400000000000000000000033621327032662100166040ustar00rootroot00000000000000# Release history All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
Guiding Principles - Changelogs are for humans, not machines. - There should be an entry for every single version. - The same types of changes should be grouped. - Versions and sections should be linkable. - The latest version comes first. - The release date of each versions is displayed. - Mention whether you follow Semantic Versioning.
Types of changes Changelog entries are classified using the following labels _(from [keep-a-changelog](http://keepachangelog.com/)_): - `Added` for new features. - `Changed` for changes in existing functionality. - `Deprecated` for soon-to-be removed features. - `Removed` for now removed features. - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities.
## [3.0.0] - 2017-12-13 **Changed** - renamed `token.val` to `token.value` - expose `.create` method to allow customization of `token.value` property name ## [2.0.0] - 2017-11-10 - refactored to be simplified ## [1.0.2] - 2017-11-10 - make `parent` the last argument ## [1.0.1] - 2017-11-09 - fix readme ## [1.0.0] - 2017-11-09 - initial commit - first commit - update description [2.0.0]: https://github.com/here-be/snapdragon-token/compare/1.0.2...2.0.0 [1.0.2]: https://github.com/here-be/snapdragon-token/compare/1.0.1...1.0.2 [1.0.1]: https://github.com/here-be/snapdragon-token/compare/1.0.0...1.0.1 [keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog snapdragon-token-4.0.0/LICENSE000066400000000000000000000021001327032662100157650ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2017-2018, Jon Schlinkert. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. snapdragon-token-4.0.0/README.md000066400000000000000000000116261327032662100162540ustar00rootroot00000000000000# snapdragon-token [![NPM version](https://img.shields.io/npm/v/snapdragon-token.svg?style=flat)](https://www.npmjs.com/package/snapdragon-token) [![NPM monthly downloads](https://img.shields.io/npm/dm/snapdragon-token.svg?style=flat)](https://npmjs.org/package/snapdragon-token) [![NPM total downloads](https://img.shields.io/npm/dt/snapdragon-token.svg?style=flat)](https://npmjs.org/package/snapdragon-token) [![Linux Build Status](https://img.shields.io/travis/here-be/snapdragon-token.svg?style=flat&label=Travis)](https://travis-ci.org/here-be/snapdragon-token) > Create a snapdragon token. Used by the snapdragon lexer, but can also be used by plugins. Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. ## Install Install with [npm](https://www.npmjs.com/): ```sh $ npm install --save snapdragon-token ``` ## Usage ```js const Token = require('snapdragon-token'); ``` ## API ### [Token](index.js#L18) Create a new `Token` with the given `value` and `type`. **Params** * `type` **{String|Object}**: The token type to use when `value` is a string. * `value` **{String}**: Value to set * `returns` **{Object}**: Token instance **Example** ```js const token = new Token('*', 'Star'); const token = new Token({type: 'star', value: '*'}); console.log(token) //=> Token { type: 'star', value: '*' } ``` ## Release history See [the changelog](CHANGELOG.md). ## Token objects Lexer tokens are represented as `Token` objects that implement the following interface: ```js interface Token { type: string; value: string; match: array | undefined; } ``` ### Token properties * `type` **{string}** - A string representing the token variant type. This property is necessary for classifying one or more characters so that parsers or compilers can determine what to do with the token. * `value` **{string}** - The substring (or [lexeme](#lexeme)) that was captured for the token. * `match` **{array|undefined}** - If a regular expression was used to capture a substring, the `RegExp.exec()` or `String.match()` arguments array can be stored on the token. **Source location** Add the source location (start, end, index and range) information to tokens using either of the following plugins (depending on preference for property naming conventions): * [snapdragon-position](https://github.com/here-be/snapdragon-position) * [snapdragon-location](https://github.com/here-be/snapdragon-location) ## About
Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.
Running Tests Running 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: ```sh $ npm install && npm test ```
Building docs _(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.)_ To generate the readme, run the following command: ```sh $ npm install -g verbose/verb#dev verb-generate-readme && verb ```
### Related projects You might also be interested in these projects: * [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.") * [snapdragon-util](https://www.npmjs.com/package/snapdragon-util): Utilities for the snapdragon parser/compiler. | [homepage](https://github.com/here-be/snapdragon-util "Utilities for the snapdragon parser/compiler.") * [snapdragon](https://www.npmjs.com/package/snapdragon): Easy-to-use plugin system for creating powerful, fast and versatile parsers and compilers, with built-in source-map… [more](https://github.com/here-be/snapdragon) | [homepage](https://github.com/here-be/snapdragon "Easy-to-use plugin system for creating powerful, fast and versatile parsers and compilers, with built-in source-map support.") ### Author **Jon Schlinkert** * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) * [GitHub Profile](https://github.com/jonschlinkert) * [Twitter Profile](https://twitter.com/jonschlinkert) ### License Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). Released under the [MIT License](LICENSE). *** _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on April 26, 2018._snapdragon-token-4.0.0/index.js000066400000000000000000000020431327032662100164330ustar00rootroot00000000000000'use strict'; /** * Create a new `Token` with the given `value` and `type`. * * ```js * const token = new Token('*', 'Star'); * const token = new Token({type: 'star', value: '*'}); * console.log(token) //=> Token { type: 'star', value: '*' } * ``` * @name Token * @param {String|Object} `type` The token type to use when `value` is a string. * @param {String} `value` Value to set * @return {Object} Token instance * @api public */ class Token { constructor(type, value, match) { if (Array.isArray(value)) { match = value; value = type.value || match[0]; } if (isObject(type)) { for (const key in type) { this[key] = type[key]; } } else { this.type = type; this.value = value; } if (match) { this.match = match; } } get isToken() { return true; } static isToken(token) { return isObject(token) && token.isToken === true; } } function isObject(val) { return val && typeof val === 'object' && !Array.isArray(val); } module.exports = Token; snapdragon-token-4.0.0/package.json000066400000000000000000000025001327032662100172520ustar00rootroot00000000000000{ "name": "snapdragon-token", "description": "Create a snapdragon token. Used by the snapdragon lexer, but can also be used by plugins.", "version": "4.0.0", "homepage": "https://github.com/here-be/snapdragon-token", "author": "Jon Schlinkert (https://github.com/jonschlinkert)", "repository": "here-be/snapdragon-token", "bugs": { "url": "https://github.com/here-be/snapdragon-token/issues" }, "license": "MIT", "files": [ "index.js" ], "main": "index.js", "engines": { "node": ">=6" }, "scripts": { "test": "mocha", "cover": "nyc mocha" }, "devDependencies": { "gulp-format-md": "^1.0.0", "mocha": "^3.5.3", "nyc": "^11.7.1" }, "keywords": [ "ast", "capture", "compile", "compiler", "convert", "lex", "lexer", "parse", "parser", "render", "snapdragon", "token", "tokenize", "transform" ], "verb": { "toc": false, "layout": "default", "tasks": [ "readme" ], "plugins": [ "gulp-format-md" ], "related": { "list": [ "snapdragon", "snapdragon-node", "snapdragon-tokenizer", "snapdragon-util" ] }, "lint": { "reflinks": true }, "reflinks": [ "snapdragon-location", "snapdragon-position" ] } } snapdragon-token-4.0.0/test/000077500000000000000000000000001327032662100157465ustar00rootroot00000000000000snapdragon-token-4.0.0/test/test.js000066400000000000000000000057631327032662100172760ustar00rootroot00000000000000'use strict'; require('mocha'); const assert = require('assert'); const Token = require('..'); // mock lexer class Lexer { constructor() { this.isLexer = true; this.tokens = []; } push(tok) { tok.parent = this; this.tokens.push(tok); } unshift(tok) { tok.parent = this; this.tokens.unshift(tok); } } describe('snapdragon-token', function() { describe('main export', function() { it('should export a function', function() { assert.strictEqual(typeof Token, 'function'); }); }); describe('token', function() { it('should create a new Token with the given type', function() { const token = new Token('star'); assert.strictEqual(token.type, 'star'); }); it('should create a new Token with the given type and value', function() { const token = new Token('star', '*'); assert.strictEqual(token.type, 'star'); assert.strictEqual(token.value, '*'); }); it('should create a new Token with the given object', function() { const token = new Token({type: 'star', value: '*'}); assert.strictEqual(token.value, '*'); assert.strictEqual(token.type, 'star'); }); it('should extend type and value onto a token', function() { const token = new Token({type: 'foo', value: 'bar'}); assert.strictEqual(token.type, 'foo'); assert.strictEqual(token.value, 'bar'); }); it('should add match array when first arg is an object', function() { const match = /^\w+/.exec('word'); const token = new Token({type: 'foo', value: 'bar'}, match); assert.strictEqual(token.type, 'foo'); assert.strictEqual(token.value, 'bar'); assert.deepEqual(token.match.slice(), ['word']); }); it('should add match array when type and value are strings', function() { const match = /^\w+/.exec('word'); const token = new Token('foo', 'bar', match); assert.strictEqual(token.type, 'foo'); assert.strictEqual(token.value, 'bar'); assert.deepEqual(token.match.slice(), ['word']); }); it('should add match array when type is a string', function() { const match = /^\w+/.exec('word'); const token = new Token('foo', match); assert.strictEqual(token.type, 'foo'); assert.strictEqual(token.value, 'word'); assert.deepEqual(token.match.slice(), ['word']); }); it('should extend arbitrary properties onto a token', function() { const token = new Token({type: 'foo', value: 'bar', baz: 'qux'}); assert.strictEqual(token.baz, 'qux'); }); }); describe('.isToken', function() { it('should be false if the value is not a Token', function() { assert(!Token.isToken({})); assert(!Token.isToken(null)); assert(!Token.isToken([])); }); it('should be true if the value is an instance of Token', function() { assert(Token.isToken(new Token())); }); it('should be true if the object has isToken = true', function() { assert(Token.isToken({isToken: true})); }); }); });