Skip to content

Commit d38fd4f

Browse files
committed
deps: spdx-expression-parse@4.0.0
1 parent 913b326 commit d38fd4f

File tree

17 files changed

+748
-8
lines changed

17 files changed

+748
-8
lines changed

node_modules/.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@
208208
!/socks-proxy-agent
209209
!/socks
210210
!/spdx-correct
211+
!/spdx-correct/node_modules/
212+
/spdx-correct/node_modules/*
213+
!/spdx-correct/node_modules/spdx-expression-parse
211214
!/spdx-exceptions
212215
!/spdx-expression-parse
213216
!/spdx-license-ids
@@ -233,6 +236,9 @@
233236
!/unique-slug
234237
!/util-deprecate
235238
!/validate-npm-package-license
239+
!/validate-npm-package-license/node_modules/
240+
/validate-npm-package-license/node_modules/*
241+
!/validate-npm-package-license/node_modules/spdx-expression-parse
236242
!/validate-npm-package-name
237243
!/walk-up-path
238244
!/wcwidth
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
C. Scott Ananian <cscott@cscott.net> (http://cscott.net)
2+
Kyle E. Mitchell <kyle@kemitchell.com> (https://kemitchell.com)
3+
Shinnosuke Watanabe <snnskwtnb@gmail.com>
4+
Antoine Motet <antoine.motet@gmail.com>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License
2+
3+
Copyright (c) 2015 Kyle E. Mitchell & other authors listed in AUTHORS
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included
14+
in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict'
2+
3+
var scan = require('./scan')
4+
var parse = require('./parse')
5+
6+
module.exports = function (source) {
7+
return parse(scan(source))
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "spdx-expression-parse",
3+
"description": "parse SPDX license expressions",
4+
"version": "3.0.1",
5+
"author": "Kyle E. Mitchell <kyle@kemitchell.com> (https://kemitchell.com)",
6+
"files": [
7+
"AUTHORS",
8+
"index.js",
9+
"parse.js",
10+
"scan.js"
11+
],
12+
"dependencies": {
13+
"spdx-exceptions": "^2.1.0",
14+
"spdx-license-ids": "^3.0.0"
15+
},
16+
"devDependencies": {
17+
"defence-cli": "^3.0.1",
18+
"replace-require-self": "^1.0.0",
19+
"standard": "^14.1.0"
20+
},
21+
"keywords": [
22+
"SPDX",
23+
"law",
24+
"legal",
25+
"license",
26+
"metadata",
27+
"package",
28+
"package.json",
29+
"standards"
30+
],
31+
"license": "MIT",
32+
"repository": "jslicense/spdx-expression-parse.js",
33+
"scripts": {
34+
"lint": "standard",
35+
"test:readme": "defence -i javascript README.md | replace-require-self | node",
36+
"test:suite": "node test.js",
37+
"test": "npm run test:suite && npm run test:readme"
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
'use strict'
2+
3+
// The ABNF grammar in the spec is totally ambiguous.
4+
//
5+
// This parser follows the operator precedence defined in the
6+
// `Order of Precedence and Parentheses` section.
7+
8+
module.exports = function (tokens) {
9+
var index = 0
10+
11+
function hasMore () {
12+
return index < tokens.length
13+
}
14+
15+
function token () {
16+
return hasMore() ? tokens[index] : null
17+
}
18+
19+
function next () {
20+
if (!hasMore()) {
21+
throw new Error()
22+
}
23+
index++
24+
}
25+
26+
function parseOperator (operator) {
27+
var t = token()
28+
if (t && t.type === 'OPERATOR' && operator === t.string) {
29+
next()
30+
return t.string
31+
}
32+
}
33+
34+
function parseWith () {
35+
if (parseOperator('WITH')) {
36+
var t = token()
37+
if (t && t.type === 'EXCEPTION') {
38+
next()
39+
return t.string
40+
}
41+
throw new Error('Expected exception after `WITH`')
42+
}
43+
}
44+
45+
function parseLicenseRef () {
46+
// TODO: Actually, everything is concatenated into one string
47+
// for backward-compatibility but it could be better to return
48+
// a nice structure.
49+
var begin = index
50+
var string = ''
51+
var t = token()
52+
if (t.type === 'DOCUMENTREF') {
53+
next()
54+
string += 'DocumentRef-' + t.string + ':'
55+
if (!parseOperator(':')) {
56+
throw new Error('Expected `:` after `DocumentRef-...`')
57+
}
58+
}
59+
t = token()
60+
if (t.type === 'LICENSEREF') {
61+
next()
62+
string += 'LicenseRef-' + t.string
63+
return { license: string }
64+
}
65+
index = begin
66+
}
67+
68+
function parseLicense () {
69+
var t = token()
70+
if (t && t.type === 'LICENSE') {
71+
next()
72+
var node = { license: t.string }
73+
if (parseOperator('+')) {
74+
node.plus = true
75+
}
76+
var exception = parseWith()
77+
if (exception) {
78+
node.exception = exception
79+
}
80+
return node
81+
}
82+
}
83+
84+
function parseParenthesizedExpression () {
85+
var left = parseOperator('(')
86+
if (!left) {
87+
return
88+
}
89+
90+
var expr = parseExpression()
91+
92+
if (!parseOperator(')')) {
93+
throw new Error('Expected `)`')
94+
}
95+
96+
return expr
97+
}
98+
99+
function parseAtom () {
100+
return (
101+
parseParenthesizedExpression() ||
102+
parseLicenseRef() ||
103+
parseLicense()
104+
)
105+
}
106+
107+
function makeBinaryOpParser (operator, nextParser) {
108+
return function parseBinaryOp () {
109+
var left = nextParser()
110+
if (!left) {
111+
return
112+
}
113+
114+
if (!parseOperator(operator)) {
115+
return left
116+
}
117+
118+
var right = parseBinaryOp()
119+
if (!right) {
120+
throw new Error('Expected expression')
121+
}
122+
return {
123+
left: left,
124+
conjunction: operator.toLowerCase(),
125+
right: right
126+
}
127+
}
128+
}
129+
130+
var parseAnd = makeBinaryOpParser('AND', parseAtom)
131+
var parseExpression = makeBinaryOpParser('OR', parseAnd)
132+
133+
var node = parseExpression()
134+
if (!node || hasMore()) {
135+
throw new Error('Syntax error')
136+
}
137+
return node
138+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
'use strict'
2+
3+
var licenses = []
4+
.concat(require('spdx-license-ids'))
5+
.concat(require('spdx-license-ids/deprecated'))
6+
var exceptions = require('spdx-exceptions')
7+
8+
module.exports = function (source) {
9+
var index = 0
10+
11+
function hasMore () {
12+
return index < source.length
13+
}
14+
15+
// `value` can be a regexp or a string.
16+
// If it is recognized, the matching source string is returned and
17+
// the index is incremented. Otherwise `undefined` is returned.
18+
function read (value) {
19+
if (value instanceof RegExp) {
20+
var chars = source.slice(index)
21+
var match = chars.match(value)
22+
if (match) {
23+
index += match[0].length
24+
return match[0]
25+
}
26+
} else {
27+
if (source.indexOf(value, index) === index) {
28+
index += value.length
29+
return value
30+
}
31+
}
32+
}
33+
34+
function skipWhitespace () {
35+
read(/[ ]*/)
36+
}
37+
38+
function operator () {
39+
var string
40+
var possibilities = ['WITH', 'AND', 'OR', '(', ')', ':', '+']
41+
for (var i = 0; i < possibilities.length; i++) {
42+
string = read(possibilities[i])
43+
if (string) {
44+
break
45+
}
46+
}
47+
48+
if (string === '+' && index > 1 && source[index - 2] === ' ') {
49+
throw new Error('Space before `+`')
50+
}
51+
52+
return string && {
53+
type: 'OPERATOR',
54+
string: string
55+
}
56+
}
57+
58+
function idstring () {
59+
return read(/[A-Za-z0-9-.]+/)
60+
}
61+
62+
function expectIdstring () {
63+
var string = idstring()
64+
if (!string) {
65+
throw new Error('Expected idstring at offset ' + index)
66+
}
67+
return string
68+
}
69+
70+
function documentRef () {
71+
if (read('DocumentRef-')) {
72+
var string = expectIdstring()
73+
return { type: 'DOCUMENTREF', string: string }
74+
}
75+
}
76+
77+
function licenseRef () {
78+
if (read('LicenseRef-')) {
79+
var string = expectIdstring()
80+
return { type: 'LICENSEREF', string: string }
81+
}
82+
}
83+
84+
function identifier () {
85+
var begin = index
86+
var string = idstring()
87+
88+
if (licenses.indexOf(string) !== -1) {
89+
return {
90+
type: 'LICENSE',
91+
string: string
92+
}
93+
} else if (exceptions.indexOf(string) !== -1) {
94+
return {
95+
type: 'EXCEPTION',
96+
string: string
97+
}
98+
}
99+
100+
index = begin
101+
}
102+
103+
// Tries to read the next token. Returns `undefined` if no token is
104+
// recognized.
105+
function parseToken () {
106+
// Ordering matters
107+
return (
108+
operator() ||
109+
documentRef() ||
110+
licenseRef() ||
111+
identifier()
112+
)
113+
}
114+
115+
var tokens = []
116+
while (hasMore()) {
117+
skipWhitespace()
118+
if (!hasMore()) {
119+
break
120+
}
121+
122+
var token = parseToken()
123+
if (!token) {
124+
throw new Error('Unexpected `' + source[index] +
125+
'` at offset ' + index)
126+
}
127+
128+
tokens.push(token)
129+
}
130+
return tokens
131+
}

node_modules/spdx-expression-parse/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "spdx-expression-parse",
33
"description": "parse SPDX license expressions",
4-
"version": "3.0.1",
4+
"version": "4.0.0",
55
"author": "Kyle E. Mitchell <kyle@kemitchell.com> (https://kemitchell.com)",
66
"files": [
77
"AUTHORS",

node_modules/spdx-expression-parse/scan.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = function (source) {
3737

3838
function operator () {
3939
var string
40-
var possibilities = ['WITH', 'AND', 'OR', '(', ')', ':', '+']
40+
var possibilities = [/^WITH/i, /^AND/i, /^OR/i, '(', ')', ':', '+']
4141
for (var i = 0; i < possibilities.length; i++) {
4242
string = read(possibilities[i])
4343
if (string) {
@@ -51,7 +51,7 @@ module.exports = function (source) {
5151

5252
return string && {
5353
type: 'OPERATOR',
54-
string: string
54+
string: string.toUpperCase()
5555
}
5656
}
5757

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
C. Scott Ananian <cscott@cscott.net> (http://cscott.net)
2+
Kyle E. Mitchell <kyle@kemitchell.com> (https://kemitchell.com)
3+
Shinnosuke Watanabe <snnskwtnb@gmail.com>
4+
Antoine Motet <antoine.motet@gmail.com>

0 commit comments

Comments
 (0)