package init
This commit is contained in:
parent
69b5100406
commit
77e3850c81
87
generate-parser.js
Normal file
87
generate-parser.js
Normal file
@ -0,0 +1,87 @@
|
||||
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())
|
||||
@ -1,4 +1,51 @@
|
||||
%{?nodejs_find_provides_and_requires}
|
||||
%global packagename spdx-expression-parse
|
||||
%global enable_tests 1
|
||||
Name: nodejs-spdx-expression-parse
|
||||
Version: 1.0.2
|
||||
Release: 1
|
||||
Summary: Parse SPDX license expressions
|
||||
License: MIT and CC-BY
|
||||
URL: https://github.com/kemitchell/spdx-expression-parse.js.git
|
||||
Source0: https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-%{version}.tgz
|
||||
Source1: https://raw.githubusercontent.com/kemitchell/spdx-expression-parse.js/v%{version}/generate-parser.js
|
||||
ExclusiveArch: %{nodejs_arches} noarch
|
||||
BuildArch: noarch
|
||||
BuildRequires: nodejs-packaging uglify-js npm(jison) npm(spdx-license-ids)
|
||||
BuildRequires: npm(spdx-exceptions)
|
||||
%if 0%{?enable_tests}
|
||||
%endif
|
||||
Requires: nodejs
|
||||
%description
|
||||
Parse SPDX license expressions
|
||||
|
||||
%prep
|
||||
%setup -q -n package
|
||||
cp -p %{SOURCE1} .
|
||||
rm parser.generated.js
|
||||
|
||||
%build
|
||||
%nodejs_symlink_deps --check
|
||||
%__nodejs generate-parser.js | %{_bindir}/uglifyjs > parser.generated.js
|
||||
|
||||
%install
|
||||
mkdir -p %{buildroot}%{nodejs_sitelib}/%{packagename}
|
||||
cp -pr package.json *.js \
|
||||
%{buildroot}%{nodejs_sitelib}/%{packagename}
|
||||
%nodejs_symlink_deps
|
||||
|
||||
%check
|
||||
%{__nodejs} -e 'require("./")'
|
||||
%if 0%{?enable_tests}
|
||||
echo "There are no tests..."
|
||||
%endif
|
||||
|
||||
%files
|
||||
%{!?_licensedir:%global license %doc}
|
||||
%doc *.md
|
||||
%license LICENSE
|
||||
%{nodejs_sitelib}/%{packagename}
|
||||
|
||||
%changelog
|
||||
* Fri Aug 21 2020 wangchong <wangchong56@huawei.com> - -1
|
||||
* Fri Aug 21 2020 wangchong <wangchong56@huawei.com> - 1.0.2-1
|
||||
- package init
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
version-control: github
|
||||
src_repo: sctp/lksctp-tools
|
||||
src_repo: kemitchell/spdx-expression-parse.js
|
||||
tag_prefix: ^v
|
||||
seperator: .
|
||||
|
||||
BIN
spdx-expression-parse-1.0.2.tgz
Normal file
BIN
spdx-expression-parse-1.0.2.tgz
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user