Skip to content

Commit 17c2f51

Browse files
committed
Inline util.oneOf
1 parent c1b165f commit 17c2f51

File tree

4 files changed

+20
-35
lines changed

4 files changed

+20
-35
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
"AUTHORS",
88
"index.js",
99
"parse.js",
10-
"scan.js",
11-
"util.js"
10+
"scan.js"
1211
],
1312
"dependencies": {
1413
"spdx-exceptions": "^2.0.0",

parse.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
var util = require('./util')
2-
31
// The ABNF grammar in the spec is totally ambiguous.
42
//
53
// This parser follows the operator precedence defined in the
@@ -97,11 +95,11 @@ module.exports = function (tokens) {
9795
}
9896

9997
function parseAtom () {
100-
return util.oneOf([
101-
parseParenthesizedExpression,
102-
parseLicenseRef,
103-
parseLicense
104-
])
98+
return (
99+
parseParenthesizedExpression() ||
100+
parseLicenseRef() ||
101+
parseLicense()
102+
)
105103
}
106104

107105
function makeBinaryOpParser (operator, nextParser) {

scan.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var licenses = require('spdx-license-ids')
22
var exceptions = require('spdx-exceptions')
3-
var util = require('./util')
43

54
module.exports = function (source) {
65
var index = 0
@@ -33,11 +32,14 @@ module.exports = function (source) {
3332
}
3433

3534
function operator () {
36-
var string = util.oneOf(
37-
['WITH', 'AND', 'OR', '(', ')', ':', '+'].map(function (s) {
38-
return function () { return read(s) }
39-
})
40-
)
35+
var string
36+
var possibilities = ['WITH', 'AND', 'OR', '(', ')', ':', '+']
37+
for (var i = 0; i < possibilities.length; i++) {
38+
string = read(possibilities[i])
39+
if (string) {
40+
break
41+
}
42+
}
4143

4244
if (string === '+' && index > 1 && source[index - 2] === ' ') {
4345
throw new Error('Space before `+`')
@@ -98,12 +100,12 @@ module.exports = function (source) {
98100
// recognized.
99101
function parseToken () {
100102
// Ordering matters
101-
return util.oneOf([
102-
operator,
103-
documentRef,
104-
licenseRef,
105-
identifier
106-
])
103+
return (
104+
operator() ||
105+
documentRef() ||
106+
licenseRef() ||
107+
identifier()
108+
)
107109
}
108110

109111
var tokens = []

util.js

-14
This file was deleted.

0 commit comments

Comments
 (0)