|
| 1 | +var licenses = require('spdx-license-ids') |
| 2 | +var exceptions = require('spdx-exceptions') |
1 | 3 | var util = require('./util') |
2 | 4 |
|
3 | 5 | // The ABNF grammar in the spec is totally ambiguous. |
4 | 6 | // |
5 | 7 | // This parser follows the operator precedence defined in the |
6 | 8 | // `Order of Precedence and Parentheses` section. |
7 | | - |
8 | | -module.exports = function (tokens) { |
| 9 | +// |
| 10 | +// options: |
| 11 | +// - Set `relaxed` to `true` to accept invalid license or exception IDs. |
| 12 | +module.exports = function (tokens, options) { |
| 13 | + options = options || {} |
9 | 14 | var index = 0 |
10 | 15 |
|
11 | 16 | function hasMore () { |
@@ -34,7 +39,10 @@ module.exports = function (tokens) { |
34 | 39 | function parseWith () { |
35 | 40 | if (parseOperator('WITH')) { |
36 | 41 | var t = token() |
37 | | - if (t && t.type === 'EXCEPTION') { |
| 42 | + if (t && t.type === 'IDENTIFIER') { |
| 43 | + if (!options.relaxed && exceptions.indexOf(t.string) === -1) { |
| 44 | + throw new Error('`' + t.string + '` is not a valid exception name') |
| 45 | + } |
38 | 46 | next() |
39 | 47 | return t.string |
40 | 48 | } |
@@ -67,7 +75,10 @@ module.exports = function (tokens) { |
67 | 75 |
|
68 | 76 | function parseLicense () { |
69 | 77 | var t = token() |
70 | | - if (t && t.type === 'LICENSE') { |
| 78 | + if (t && t.type === 'IDENTIFIER') { |
| 79 | + if (!options.relaxed && licenses.indexOf(t.string) === -1) { |
| 80 | + throw new Error('`' + t.string + '` is not a valid license name') |
| 81 | + } |
71 | 82 | next() |
72 | 83 | var node = {license: t.string} |
73 | 84 | if (parseOperator('+')) { |
|
0 commit comments