diff -Nru node-spdx-expression-parse-1.0.4/AUTHORS node-spdx-expression-parse-3.0.0/AUTHORS --- node-spdx-expression-parse-1.0.4/AUTHORS 2016-10-05 20:12:38.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/AUTHORS 2018-02-27 00:09:59.000000000 +0000 @@ -1,3 +1,4 @@ C. Scott Ananian (http://cscott.net) Kyle E. Mitchell (https://kemitchell.com) Shinnosuke Watanabe +Antoine Motet diff -Nru node-spdx-expression-parse-1.0.4/CONTRIBUTING.md node-spdx-expression-parse-3.0.0/CONTRIBUTING.md --- node-spdx-expression-parse-1.0.4/CONTRIBUTING.md 2016-10-05 20:12:38.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/CONTRIBUTING.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,12 +0,0 @@ -Pull requests are most welcome! - -Please: - -1. Use [JavaScript Standard Style](https://www.npmjs.com/packages/standard). - -2. Add tests to the code blocks in `README.md`, using Node.js' built-in - `assert` module. Travis CI runs those examples as a test suite. - -3. Add yourself to `AUTHORS`. - -4. License your contributions under the existing, MIT-style terms. diff -Nru node-spdx-expression-parse-1.0.4/debian/changelog node-spdx-expression-parse-3.0.0/debian/changelog --- node-spdx-expression-parse-1.0.4/debian/changelog 2016-10-26 17:40:57.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/changelog 2020-03-09 15:24:25.000000000 +0000 @@ -1,3 +1,29 @@ +node-spdx-expression-parse (3.0.0-1) unstable; urgency=medium + + * Team upload + + [ Debian Janitor ] + * Use secure copyright file specification URI. + * Bump debhelper from old 9 to 12. + * Set debhelper-compat version in Build-Depends. + * Set upstream metadata fields: Repository, Repository-Browse. + * Update Vcs-* headers from URL redirect. + * Use canonical URL in Vcs-Git. + + [ Xavier Guimard ] + * Declare compliance with policy 4.5.0 + * Use pkg-js-tools auto test & install + * Add "Rules-Requires-Root: no" + * Change section to javascript + * Add debian/gbp.conf + * Update copyright + * Enable upstream test using mocha + * debian/watch: use npm registry + * New upstream version 3.0.0 + * Update dependencies + + -- Xavier Guimard Mon, 09 Mar 2020 16:24:25 +0100 + node-spdx-expression-parse (1.0.4-1) unstable; urgency=low * Initial release (Closes: #842181) diff -Nru node-spdx-expression-parse-1.0.4/debian/clean node-spdx-expression-parse-3.0.0/debian/clean --- node-spdx-expression-parse-1.0.4/debian/clean 1970-01-01 00:00:00.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/clean 2020-03-09 15:08:34.000000000 +0000 @@ -0,0 +1 @@ +parser.js diff -Nru node-spdx-expression-parse-1.0.4/debian/compat node-spdx-expression-parse-3.0.0/debian/compat --- node-spdx-expression-parse-1.0.4/debian/compat 2016-10-26 17:21:50.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/compat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -9 diff -Nru node-spdx-expression-parse-1.0.4/debian/control node-spdx-expression-parse-3.0.0/debian/control --- node-spdx-expression-parse-1.0.4/debian/control 2016-10-26 18:25:05.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/control 2020-03-09 15:22:39.000000000 +0000 @@ -1,25 +1,27 @@ Source: node-spdx-expression-parse -Section: web -Priority: optional Maintainer: Debian Javascript Maintainers Uploaders: Pirate Praveen +Section: javascript +Testsuite: autopkgtest-pkg-nodejs +Priority: optional Build-Depends: - debhelper (>= 9) - , dh-buildinfo - , nodejs - , node-spdx-license-ids - , node-spdx-exceptions - , jison -Standards-Version: 3.9.8 -Homepage: https://github.com/kemitchell/spdx-expression-parse.js#readme -Vcs-Git: https://anonscm.debian.org/git/pkg-javascript/node-spdx-expression-parse.git -Vcs-Browser: https://anonscm.debian.org/cgit/pkg-javascript/node-spdx-expression-parse.git + debhelper-compat (= 12) + , mocha + , node-spdx-exceptions (>= 2.1.0) + , node-spdx-license-ids (>= 3.0.0) + , pkg-js-tools (>= 0.9.20~) +Standards-Version: 4.5.0 +Vcs-Browser: https://salsa.debian.org/js-team/node-spdx-expression-parse +Vcs-Git: https://salsa.debian.org/js-team/node-spdx-expression-parse.git +Homepage: https://github.com/kemitchell/spdx-expression-parse.js +Rules-Requires-Root: no Package: node-spdx-expression-parse Architecture: all Depends: ${misc:Depends} + , node-spdx-exceptions (>= 2.0.1) + , node-spdx-license-ids (>= 3.0.0) , nodejs Description: parse SPDX license expressions - . Node.js is an event-based server-side JavaScript engine. diff -Nru node-spdx-expression-parse-1.0.4/debian/copyright node-spdx-expression-parse-3.0.0/debian/copyright --- node-spdx-expression-parse-1.0.4/debian/copyright 2016-10-26 17:40:18.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/copyright 2020-03-09 15:05:00.000000000 +0000 @@ -1,4 +1,4 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: spdx-expression-parse Upstream-Contact: https://github.com/kemitchell/spdx-expression-parse.js/issues Source: https://github.com/kemitchell/spdx-expression-parse.js#readme @@ -9,6 +9,7 @@ Files: debian/* Copyright: 2016 Pirate Praveen + 2020 Xavier Guimard License: Expat and CC-BY-3.0 License: Expat @@ -33,15 +34,26 @@ SOFTWARE. License: CC-BY-3.0 + Creative Commons Legal Code + . + Attribution 3.0 Unported + . + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR + DAMAGES RESULTING FROM ITS USE. + . + License + . THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED. . - BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE - BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE - CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE - IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS. - . - Complete terms are found at - http://creativecommons.org/licenses/by/3.0/legalcode + BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE + TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY + BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS + CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND + CONDITIONS. diff -Nru node-spdx-expression-parse-1.0.4/debian/gbp.conf node-spdx-expression-parse-3.0.0/debian/gbp.conf --- node-spdx-expression-parse-1.0.4/debian/gbp.conf 1970-01-01 00:00:00.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/gbp.conf 2020-03-09 15:00:23.000000000 +0000 @@ -0,0 +1,5 @@ +[DEFAULT] +pristine-tar = True + +[import-orig] +filter = [ '.gitignore', '.travis.yml', '.git*' ] diff -Nru node-spdx-expression-parse-1.0.4/debian/install node-spdx-expression-parse-3.0.0/debian/install --- node-spdx-expression-parse-1.0.4/debian/install 2016-10-26 18:35:31.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/install 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ -package.json usr/lib/nodejs/spdx-expression-parse/ -index.js usr/lib/nodejs/spdx-expression-parse/ -parser.js usr/lib/nodejs/spdx-expression-parse/ -AUTHORS usr/lib/nodejs/spdx-expression-parse/ diff -Nru node-spdx-expression-parse-1.0.4/debian/patches/import-upstream-test.diff node-spdx-expression-parse-3.0.0/debian/patches/import-upstream-test.diff --- node-spdx-expression-parse-1.0.4/debian/patches/import-upstream-test.diff 1970-01-01 00:00:00.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/patches/import-upstream-test.diff 2020-03-09 15:21:22.000000000 +0000 @@ -0,0 +1,93 @@ +Description: import upstream test +Author: Xavier Guimard +Forwarded: not-needed +Last-Update: 2020-03-09 + +--- /dev/null ++++ b/test/index.js +@@ -0,0 +1,85 @@ ++'use strict' ++ ++/* global it */ ++ ++var assert = require('assert') ++var p = require('..') ++ ++// The spec is unclear about tabs and newlines ++it('forbids tabs and newlines', function () { ++ assert.throws(function () { p('MIT\t') }) ++ assert.throws(function () { p('\nMIT') }) ++}) ++ ++it('allows many spaces', function () { ++ assert.deepEqual( ++ p(' MIT'), ++ {license: 'MIT'} ++ ) ++ ++ assert.deepEqual( ++ p('MIT '), ++ {license: 'MIT'} ++ ) ++ ++ assert.deepEqual( ++ p('MIT AND BSD-3-Clause'), ++ { ++ left: {license: 'MIT'}, ++ conjunction: 'and', ++ right: {license: 'BSD-3-Clause'} ++ } ++ ) ++}) ++ ++it('forbids spaces between a license-id and a following `+`', function () { ++ assert.throws( ++ function () { p('MIT +') }, ++ /Space before `\+`/ ++ ) ++}) ++ ++it('parses DocumentRefs and LicenseRefs', function () { ++ assert.deepEqual( ++ p('LicenseRef-something'), ++ {license: 'LicenseRef-something'} ++ ) ++ ++ assert.deepEqual( ++ p('DocumentRef-spdx-tool-1.2 : LicenseRef-MIT-Style-2'), ++ {license: 'DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2'} ++ ) ++}) ++ ++// See the note in `parser.js`. ++it('parses `AND`, `OR` and `WITH` with the correct precedence', function () { ++ assert.deepEqual( ++ p('MIT AND BSD-3-Clause AND CC-BY-4.0'), ++ { ++ left: {license: 'MIT'}, ++ conjunction: 'and', ++ right: { ++ left: {license: 'BSD-3-Clause'}, ++ conjunction: 'and', ++ right: {license: 'CC-BY-4.0'} ++ } ++ } ++ ) ++ ++ assert.deepEqual( ++ p('MIT AND BSD-3-Clause WITH GCC-exception-3.1 OR CC-BY-4.0 AND Apache-2.0'), ++ { ++ left: { ++ left: {license: 'MIT'}, ++ conjunction: 'and', ++ right: {license: 'BSD-3-Clause', exception: 'GCC-exception-3.1'} ++ }, ++ conjunction: 'or', ++ right: { ++ left: {license: 'CC-BY-4.0'}, ++ conjunction: 'and', ++ right: {license: 'Apache-2.0'} ++ } ++ } ++ ) ++}) diff -Nru node-spdx-expression-parse-1.0.4/debian/patches/series node-spdx-expression-parse-3.0.0/debian/patches/series --- node-spdx-expression-parse-1.0.4/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/patches/series 2020-03-09 15:20:55.000000000 +0000 @@ -0,0 +1 @@ +import-upstream-test.diff diff -Nru node-spdx-expression-parse-1.0.4/debian/rules node-spdx-expression-parse-3.0.0/debian/rules --- node-spdx-expression-parse-1.0.4/debian/rules 2016-10-26 18:36:08.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/rules 2020-03-09 15:08:34.000000000 +0000 @@ -5,10 +5,4 @@ #export DH_VERBOSE=1 %: - dh $@ - -override_dh_auto_build: - nodejs generate-parser.js > parser.js - -override_dh_auto_clean: - rm -f parser.js + dh $@ --with nodejs diff -Nru node-spdx-expression-parse-1.0.4/debian/tests/control node-spdx-expression-parse-3.0.0/debian/tests/control --- node-spdx-expression-parse-1.0.4/debian/tests/control 2016-10-26 17:21:50.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/tests/control 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -Tests: require -Depends: node-spdx-expression-parse diff -Nru node-spdx-expression-parse-1.0.4/debian/tests/pkg-js/test node-spdx-expression-parse-3.0.0/debian/tests/pkg-js/test --- node-spdx-expression-parse-1.0.4/debian/tests/pkg-js/test 1970-01-01 00:00:00.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/tests/pkg-js/test 2020-03-09 15:06:12.000000000 +0000 @@ -0,0 +1 @@ +mocha diff -Nru node-spdx-expression-parse-1.0.4/debian/tests/require node-spdx-expression-parse-3.0.0/debian/tests/require --- node-spdx-expression-parse-1.0.4/debian/tests/require 2016-10-26 17:21:50.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/tests/require 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ -#!/bin/sh -set -e -nodejs -e "require('spdx-expression-parse');" diff -Nru node-spdx-expression-parse-1.0.4/debian/upstream/metadata node-spdx-expression-parse-3.0.0/debian/upstream/metadata --- node-spdx-expression-parse-1.0.4/debian/upstream/metadata 1970-01-01 00:00:00.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/upstream/metadata 2020-02-18 20:58:14.000000000 +0000 @@ -0,0 +1,2 @@ +Repository: https://github.com/kemitchell/spdx-expression-parse.js.git +Repository-Browse: https://github.com/kemitchell/spdx-expression-parse.js diff -Nru node-spdx-expression-parse-1.0.4/debian/watch node-spdx-expression-parse-3.0.0/debian/watch --- node-spdx-expression-parse-1.0.4/debian/watch 2016-10-26 17:21:50.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/debian/watch 2020-03-09 15:23:22.000000000 +0000 @@ -1,5 +1,5 @@ -version=3 +version=4 opts=\ -dversionmangle=s/\+(debian|dfsg|ds|deb)(\.\d+)?$//,\ +dversionmangle=auto,\ filenamemangle=s/.*\/v?([\d\.-]+)\.tar\.gz/node-spdx-expression-parse.js-$1.tar.gz/ \ - https://github.com/kemitchell/spdx-expression-parse.js/tags .*/archive/v?([\d\.]+).tar.gz + https://github.com/jslicense/spdx-expression-parse.js/tags .*/archive/v?([\d\.]+).tar.gz diff -Nru node-spdx-expression-parse-1.0.4/generate-parser.js node-spdx-expression-parse-3.0.0/generate-parser.js --- node-spdx-expression-parse-1.0.4/generate-parser.js 2016-10-05 20:12:38.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/generate-parser.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,99 +0,0 @@ -var Generator = require('jison').Generator -var options = { - type: 'slr', - moduleType: 'commonjs', - moduleName: 'spdxparse' -} - -var words = ['AND', 'OR', 'WITH'] - -var quote = function (argument) { - return '\'' + argument + '\'' -} - -var regexEscape = function (s) { - return s.replace(/[\^\\$*+?.()|{}\[\]\/]/g, '\\$&') -} - -var handleLicensesAndExceptions = function () { - var ids = require('spdx-license-ids') - var exceptions = require('spdx-exceptions') - - // Sort tokens longest-first (both license ids and exception strings) - var tokens = ids.concat(exceptions) - tokens.sort(function (a, b) { return b.length - a.length }) - return tokens.map(function (t) { - var type = (ids.indexOf(t) >= 0) ? 'LICENSE' : 'EXCEPTION' - return [regexEscape(t), 'return ' + quote(type)] - }) -} - -var grammar = { - lex: { - macros: {}, - rules: [ - ['$', 'return ' + quote('EOS')], - ['\\s+', '/* skip whitespace */'], - ['\\+', 'return ' + quote('PLUS')], - ['\\(', 'return ' + quote('OPEN')], - ['\\)', 'return ' + quote('CLOSE')], - [':', 'return ' + quote('COLON')], - [ - 'DocumentRef-([0-9A-Za-z-+.]+)', - 'return ' + quote('DOCUMENTREF') - ], - [ - 'LicenseRef-([0-9A-Za-z-+.]+)', - 'return ' + quote('LICENSEREF') - ] - ] - .concat(words.map(function (word) { - return [word, 'return ' + quote(word)] - })) - .concat(handleLicensesAndExceptions()) - }, - operators: [ - ['left', 'OR'], - ['left', 'AND'], - ['right', 'PLUS', 'WITH'] - ], - tokens: [ - 'CLOSE', - 'COLON', - 'EXCEPTION', - 'LICENSE', - 'LICENSEREF', - 'OPEN', - 'PLUS' - ].concat(words).join(' '), - start: 'start', - bnf: { - start: [['expression EOS', 'return $$ = $1']], - simpleExpression: [ - ['LICENSE', '$$ = {license: yytext}'], - ['LICENSE PLUS', '$$ = {license: $1, plus: true}'], - ['LICENSEREF', '$$ = {license: yytext}'], - ['DOCUMENTREF COLON LICENSEREF', '$$ = {license: yytext}'] - ], - expression: [ - ['simpleExpression', '$$ = $1'], - ['simpleExpression WITH EXCEPTION', [ - '$$ = {exception: $3}', - '$$.license = $1.license', - 'if ($1.hasOwnProperty(\'plus\')) {', - ' $$.plus = $1.plus', - '}'].join('\n')], - [ - 'expression AND expression', - '$$ = {conjunction: \'and\', left: $1, right: $3}' - ], - [ - 'expression OR expression', - '$$ = {conjunction: \'or\', left: $1, right: $3}' - ], - ['OPEN expression CLOSE', '$$ = $2'] - ] - } -} - -console.log(new Generator(grammar, options).generate()) diff -Nru node-spdx-expression-parse-1.0.4/.gitignore node-spdx-expression-parse-3.0.0/.gitignore --- node-spdx-expression-parse-1.0.4/.gitignore 2016-10-05 20:12:38.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/.gitignore 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -parser.js diff -Nru node-spdx-expression-parse-1.0.4/index.js node-spdx-expression-parse-3.0.0/index.js --- node-spdx-expression-parse-1.0.4/index.js 2016-10-05 20:12:38.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/index.js 2018-02-27 00:09:59.000000000 +0000 @@ -1,5 +1,8 @@ -var parser = require('./parser').parser +'use strict' -module.exports = function (argument) { - return parser.parse(argument) +var scan = require('./scan') +var parse = require('./parse') + +module.exports = function (source) { + return parse(scan(source)) } diff -Nru node-spdx-expression-parse-1.0.4/package.json node-spdx-expression-parse-3.0.0/package.json --- node-spdx-expression-parse-1.0.4/package.json 2016-10-05 20:12:38.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/package.json 2018-02-27 00:14:09.000000000 +0000 @@ -1,20 +1,23 @@ { "name": "spdx-expression-parse", "description": "parse SPDX license expressions", - "version": "1.0.4", + "version": "3.0.0", "author": "Kyle E. Mitchell (http://kemitchell.com)", "files": [ "AUTHORS", "index.js", - "parser.js" + "parse.js", + "scan.js" ], + "dependencies": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + }, "devDependencies": { - "defence-cli": "^1.0.1", - "jison": "^0.4.15", + "defence-cli": "^2.0.1", + "mocha": "^3.4.2", "replace-require-self": "^1.0.0", - "spdx-exceptions": "^1.0.4", - "spdx-license-ids": "^1.0.0", - "standard": "^8.0.0" + "standard": "^10.0.2" }, "keywords": [ "SPDX", @@ -26,12 +29,12 @@ "package.json", "standards" ], - "license": "(MIT AND CC-BY-3.0)", - "repository": "kemitchell/spdx-expression-parse.js", + "license": "MIT", + "repository": "jslicense/spdx-expression-parse.js", "scripts": { "lint": "standard", - "prepublish": "node generate-parser.js > parser.js", - "pretest": "npm run prepublish", - "test": "defence -i javascript README.md | replace-require-self | node" + "test:readme": "defence -i javascript README.md | replace-require-self | node", + "test:mocha": "mocha test/index.js", + "test": "npm run test:mocha && npm run test:readme" } } diff -Nru node-spdx-expression-parse-1.0.4/parse.js node-spdx-expression-parse-3.0.0/parse.js --- node-spdx-expression-parse-1.0.4/parse.js 1970-01-01 00:00:00.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/parse.js 2018-02-27 00:09:59.000000000 +0000 @@ -0,0 +1,138 @@ +'use strict' + +// The ABNF grammar in the spec is totally ambiguous. +// +// This parser follows the operator precedence defined in the +// `Order of Precedence and Parentheses` section. + +module.exports = function (tokens) { + var index = 0 + + function hasMore () { + return index < tokens.length + } + + function token () { + return hasMore() ? tokens[index] : null + } + + function next () { + if (!hasMore()) { + throw new Error() + } + index++ + } + + function parseOperator (operator) { + var t = token() + if (t && t.type === 'OPERATOR' && operator === t.string) { + next() + return t.string + } + } + + function parseWith () { + if (parseOperator('WITH')) { + var t = token() + if (t && t.type === 'EXCEPTION') { + next() + return t.string + } + throw new Error('Expected exception after `WITH`') + } + } + + function parseLicenseRef () { + // TODO: Actually, everything is concatenated into one string + // for backward-compatibility but it could be better to return + // a nice structure. + var begin = index + var string = '' + var t = token() + if (t.type === 'DOCUMENTREF') { + next() + string += 'DocumentRef-' + t.string + ':' + if (!parseOperator(':')) { + throw new Error('Expected `:` after `DocumentRef-...`') + } + } + t = token() + if (t.type === 'LICENSEREF') { + next() + string += 'LicenseRef-' + t.string + return {license: string} + } + index = begin + } + + function parseLicense () { + var t = token() + if (t && t.type === 'LICENSE') { + next() + var node = {license: t.string} + if (parseOperator('+')) { + node.plus = true + } + var exception = parseWith() + if (exception) { + node.exception = exception + } + return node + } + } + + function parseParenthesizedExpression () { + var left = parseOperator('(') + if (!left) { + return + } + + var expr = parseExpression() + + if (!parseOperator(')')) { + throw new Error('Expected `)`') + } + + return expr + } + + function parseAtom () { + return ( + parseParenthesizedExpression() || + parseLicenseRef() || + parseLicense() + ) + } + + function makeBinaryOpParser (operator, nextParser) { + return function parseBinaryOp () { + var left = nextParser() + if (!left) { + return + } + + if (!parseOperator(operator)) { + return left + } + + var right = parseBinaryOp() + if (!right) { + throw new Error('Expected expression') + } + return { + left: left, + conjunction: operator.toLowerCase(), + right: right + } + } + } + + var parseAnd = makeBinaryOpParser('AND', parseAtom) + var parseExpression = makeBinaryOpParser('OR', parseAnd) + + var node = parseExpression() + if (!node || hasMore()) { + throw new Error('Syntax error') + } + return node +} diff -Nru node-spdx-expression-parse-1.0.4/README.md node-spdx-expression-parse-3.0.0/README.md --- node-spdx-expression-parse-1.0.4/README.md 2016-10-05 20:12:38.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/README.md 2018-02-27 00:12:56.000000000 +0000 @@ -1,4 +1,4 @@ -This package parses SPDX license expression strings describing license terms, like [package.json license strings](https://docs.npmjs.com/files/package.json#license), into consistently structured ECMAScript objects. The npm command-line interface depends on this package, as do many automatic license-audit tools. +This package parses [SPDX license expression](https://spdx.org/spdx-specification-21-web-version#h.jxpfx0ykyb60) strings describing license terms, like [package.json license strings](https://docs.npmjs.com/files/package.json#license), into consistently structured ECMAScript objects. The npm command-line interface depends on this package, as do many automatic license-audit tools. In a nutshell: @@ -19,8 +19,9 @@ }) assert.deepEqual( - // Dual licensed under LGPL 2.1 or a combination of the Three-Clause - // BSD License and the MIT License. + // Dual licensed under either: + // - LGPL 2.1 + // - a combination of Three-Clause BSD and MIT parse('(LGPL-2.1 OR BSD-3-Clause AND MIT)'), { left: {license: 'LGPL-2.1'}, @@ -38,12 +39,16 @@ The bulk of the SPDX standard describes syntax and semantics of XML metadata files. This package implements two lightweight, plain-text components of that larger standard: -1. The [license list](https://spdx.org/licenses), a mapping from specific string identifiers, like `Apache-2.0`, to standard form license texts and bolt-on license exceptions. The [spdx-license-ids](https://www.npmjs.com/package/spdx-exceptions) and [spdx-exceptions](https://www.npmjs.com/package/spdx-license-ids) packages implement the license list. They are development dependencies of this package. +1. The [license list](https://spdx.org/licenses), a mapping from specific string identifiers, like `Apache-2.0`, to standard form license texts and bolt-on license exceptions. The [spdx-license-ids](https://www.npmjs.com/package/spdx-exceptions) and [spdx-exceptions](https://www.npmjs.com/package/spdx-license-ids) packages implement the license list. `spdx-expression-parse` depends on and `require()`s them. Any license identifier from the license list is a valid license expression: ```javascript - require('spdx-license-ids').forEach(function (id) { + var identifiers = [] + .concat(require('spdx-license-ids')) + .concat(require('spdx-license-ids/deprecated')) + + identifiers.forEach(function (id) { assert.deepEqual(parse(id), {license: id}) }) ``` @@ -51,7 +56,7 @@ So is any license identifier `WITH` a standardized license exception: ```javascript - require('spdx-license-ids').forEach(function (id) { + identifiers.forEach(function (id) { require('spdx-exceptions').forEach(function (e) { assert.deepEqual( parse(id + ' WITH ' + e), @@ -61,12 +66,15 @@ }) ``` -2. The license expression language, for describing simple and complex license terms, like `MIT` for MIT-licensed and `(GPL-2.0 OR Apache-2.0)` for dual-licensing under GPL 2.0 and Apache 2.0. This package implements the license expression language. +2. The license expression language, for describing simple and complex license terms, like `MIT` for MIT-licensed and `(GPL-2.0 OR Apache-2.0)` for dual-licensing under GPL 2.0 and Apache 2.0. `spdx-expression-parse` itself implements license expression language, exporting a parser. ```javascript assert.deepEqual( - // Licensed under a combination of the MIT License and a combination - // of LGPL 2.1 (or a later version) and the Three-Clause BSD License. + // Licensed under a combination of: + // - the MIT License AND + // - a combination of: + // - LGPL 2.1 (or a later version) AND + // - Three-Clause BSD parse('(MIT AND (LGPL-2.1+ AND BSD-3-Clause))'), { left: {license: 'MIT'}, diff -Nru node-spdx-expression-parse-1.0.4/scan.js node-spdx-expression-parse-3.0.0/scan.js --- node-spdx-expression-parse-1.0.4/scan.js 1970-01-01 00:00:00.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/scan.js 2018-02-27 00:12:56.000000000 +0000 @@ -0,0 +1,131 @@ +'use strict' + +var licenses = [] + .concat(require('spdx-license-ids')) + .concat(require('spdx-license-ids/deprecated')) +var exceptions = require('spdx-exceptions') + +module.exports = function (source) { + var index = 0 + + function hasMore () { + return index < source.length + } + + // `value` can be a regexp or a string. + // If it is recognized, the matching source string is returned and + // the index is incremented. Otherwise `undefined` is returned. + function read (value) { + if (value instanceof RegExp) { + var chars = source.slice(index) + var match = chars.match(value) + if (match) { + index += match[0].length + return match[0] + } + } else { + if (source.indexOf(value, index) === index) { + index += value.length + return value + } + } + } + + function skipWhitespace () { + read(/[ ]*/) + } + + function operator () { + var string + var possibilities = ['WITH', 'AND', 'OR', '(', ')', ':', '+'] + for (var i = 0; i < possibilities.length; i++) { + string = read(possibilities[i]) + if (string) { + break + } + } + + if (string === '+' && index > 1 && source[index - 2] === ' ') { + throw new Error('Space before `+`') + } + + return string && { + type: 'OPERATOR', + string: string + } + } + + function idstring () { + return read(/[A-Za-z0-9-.]+/) + } + + function expectIdstring () { + var string = idstring() + if (!string) { + throw new Error('Expected idstring at offset ' + index) + } + return string + } + + function documentRef () { + if (read('DocumentRef-')) { + var string = expectIdstring() + return {type: 'DOCUMENTREF', string: string} + } + } + + function licenseRef () { + if (read('LicenseRef-')) { + var string = expectIdstring() + return {type: 'LICENSEREF', string: string} + } + } + + function identifier () { + var begin = index + var string = idstring() + + if (licenses.indexOf(string) !== -1) { + return { + type: 'LICENSE', + string: string + } + } else if (exceptions.indexOf(string) !== -1) { + return { + type: 'EXCEPTION', + string: string + } + } + + index = begin + } + + // Tries to read the next token. Returns `undefined` if no token is + // recognized. + function parseToken () { + // Ordering matters + return ( + operator() || + documentRef() || + licenseRef() || + identifier() + ) + } + + var tokens = [] + while (hasMore()) { + skipWhitespace() + if (!hasMore()) { + break + } + + var token = parseToken() + if (!token) { + throw new Error('Unexpected `' + source[index] + + '` at offset ' + index) + } + + tokens.push(token) + } + return tokens +} diff -Nru node-spdx-expression-parse-1.0.4/.travis.yml node-spdx-expression-parse-3.0.0/.travis.yml --- node-spdx-expression-parse-1.0.4/.travis.yml 2016-10-05 20:12:38.000000000 +0000 +++ node-spdx-expression-parse-3.0.0/.travis.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,14 +0,0 @@ ---- -language: "node_js" -node_js: -- "0.10" -- "0.11" -- "0.12" -- "4" -- "5" -- "6" -- "node" -script: -- "npm test" -- "npm run lint" -sudo: false