summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-05-06 22:32:34 -0600
committermo khan <mo.khan@gmail.com>2020-05-06 22:32:34 -0600
commit503fd0f6fdea9effed2086e2950e858450d35a88 (patch)
tree679fdd934846e0ae151b2634afa3969dfa0a72cb
parentc96fe784c16cdd5690c5a64c1b0fe7b79ea9434f (diff)
Use parslet to prepare a tree represented in a Hash
-rw-r--r--.github/licensed/bundler/parslet.dep.yml33
-rw-r--r--lib/spandx/core/guess.rb5
-rw-r--r--lib/spandx/spdx/expression.rb10
-rw-r--r--spec/unit/spdx/expression_spec.rb6
4 files changed, 41 insertions, 13 deletions
diff --git a/.github/licensed/bundler/parslet.dep.yml b/.github/licensed/bundler/parslet.dep.yml
new file mode 100644
index 0000000..91ff5e7
--- /dev/null
+++ b/.github/licensed/bundler/parslet.dep.yml
@@ -0,0 +1,33 @@
+---
+name: parslet
+version: 2.0.0
+type: bundler
+summary: Parser construction library with great error reporting in Ruby.
+homepage: http://kschiess.github.io/parslet
+license: mit
+licenses:
+- sources: LICENSE
+ text: |2
+ Copyright (c) 2010-2018 Kaspar Schiess
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+notices: []
diff --git a/lib/spandx/core/guess.rb b/lib/spandx/core/guess.rb
index b63b1ef..2b55e37 100644
--- a/lib/spandx/core/guess.rb
+++ b/lib/spandx/core/guess.rb
@@ -47,10 +47,7 @@ module Spandx
threshold = 85.0
catalogue.find do |license|
- next if license.deprecated_license_id?
-
- other_name = ::Spandx::Core::Content.new(license.name)
- content.similar?(other_name, threshold: threshold)
+ content.similar?(Content.new(license.name), threshold: threshold)
end
end
diff --git a/lib/spandx/spdx/expression.rb b/lib/spandx/spdx/expression.rb
index 32b8ff1..e169a57 100644
--- a/lib/spandx/spdx/expression.rb
+++ b/lib/spandx/spdx/expression.rb
@@ -26,7 +26,7 @@ module Spandx
rule(:dot) { str('.') }
rule(:plus) { str('+') }
rule(:hyphen) { str('-') }
- rule(:with_op) { str('with') }
+ rule(:with_op) { str('with') | str('WITH') }
rule(:and_op) { str('AND') | str('and') }
rule(:or_op) { str('OR') | str('or') }
@@ -57,19 +57,19 @@ module Spandx
# simple-expression "WITH" license-exception-id
rule(:with_expression) do
- simple_expression >> space >> with_op >> space >> license_exception_id
+ simple_expression.as(:left) >> space >> with_op.as(:operator) >> space >> license_exception_id.as(:right)
end
# compound-expression "AND" compound-expression
rule(:and_expression) do
# compound_expression >> space >> and_op >> space >> compound_expression
- simple_expression >> space >> and_op >> space >> simple_expression
+ simple_expression.as(:left) >> space >> and_op.as(:operator) >> space >> simple_expression.as(:right)
end
# compound-expression "OR" compound-expression
rule(:or_expression) do
# compound_expression >> space >> or_op >> space >> compound_expression
- simple_expression >> space >> or_op >> space >> simple_expression
+ simple_expression.as(:left) >> space >> or_op.as(:operator) >> space >> simple_expression.as(:right)
end
# compound-expression = 1*1(
@@ -90,7 +90,7 @@ module Spandx
# license-expression = 1*1(simple-expression / compound-expression)
rule(:license_expression) do
- simple_expression.repeat(1, 1) | compound_expression.repeat(1, 1)
+ simple_expression.repeat(1, 1).as(:left) | compound_expression.repeat(1, 1)
end
root(:license_expression)
diff --git a/spec/unit/spdx/expression_spec.rb b/spec/unit/spdx/expression_spec.rb
index 0dcd98d..7ee2133 100644
--- a/spec/unit/spdx/expression_spec.rb
+++ b/spec/unit/spdx/expression_spec.rb
@@ -5,8 +5,7 @@ RSpec.describe Spandx::Spdx::Expression do
describe '#parse' do
specify { expect(subject).to parse('MIT') }
- specify { expect(subject.parse('MIT').to_s).to eql('MIT') }
-
+ specify { expect(subject.parse('MIT')).to satisfy { |x| x[:left] == 'MIT' } }
specify { expect(subject.parse_with_debug('MIT or GPLv3')).to be_truthy }
specify { expect(subject.parse_with_debug('(0BSD OR MIT)')).to be_truthy }
pending { expect(subject.parse_with_debug('(BSD-2-Clause OR MIT OR Apache-2.0)')).to be_truthy }
@@ -36,8 +35,7 @@ RSpec.describe Spandx::Spdx::Expression do
specify { expect(subject.license_exception_id).to parse('389-exception') }
end
- describe '#with_expression' do
- end
+ describe '#with_expression'
describe '#and_expression' do
subject { described_class.new.and_expression }