4 .concat(require('spdx-license-ids'))
5 .concat(require('spdx-license-ids/deprecated'))
6 var exceptions = require('spdx-exceptions')
8 module.exports = function (source) {
12 return index < source.length
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)
23 index += match[0].length
27 if (source.indexOf(value, index) === index) {
34 function skipWhitespace () {
38 function operator () {
40 var possibilities = ['WITH', 'AND', 'OR', '(', ')', ':', '+']
41 for (var i = 0; i < possibilities.length; i++) {
42 string = read(possibilities[i])
48 if (string === '+' && index > 1 && source[index - 2] === ' ') {
49 throw new Error('Space before `+`')
58 function idstring () {
59 return read(/[A-Za-z0-9-.]+/)
62 function expectIdstring () {
63 var string = idstring()
65 throw new Error('Expected idstring at offset ' + index)
70 function documentRef () {
71 if (read('DocumentRef-')) {
72 var string = expectIdstring()
73 return { type: 'DOCUMENTREF', string: string }
77 function licenseRef () {
78 if (read('LicenseRef-')) {
79 var string = expectIdstring()
80 return { type: 'LICENSEREF', string: string }
84 function identifier () {
86 var string = idstring()
88 if (licenses.indexOf(string) !== -1) {
93 } else if (exceptions.indexOf(string) !== -1) {
103 // Tries to read the next token. Returns `undefined` if no token is
105 function parseToken () {
122 var token = parseToken()
124 throw new Error('Unexpected `' + source[index] +
125 '` at offset ' + index)