Skip to content

Commit

Permalink
spdx-utils: Fix parsing license references as exceptions
Browse files Browse the repository at this point in the history
This is a fixup for 91056e1 which did not acutally fix the issue.

The problem was that the first part of the `REFERENCE` rule was
optional, as a result any license reference was always put in a
`REFERENCE` token, but never in a `LICENSEREFERENCE` token by the lexer.

Fix this by making two separate rule for license references and document
references, to prevent overlap in the rules.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@here.com>
  • Loading branch information
mnonnenmacher committed May 22, 2019
1 parent 523d2d9 commit 13fa6ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions spdx-utils/src/main/antlr/com/here/ort/spdx/SpdxExpression.g4
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ package com.here.ort.spdx;

licenseReferenceExpression
:
REFERENCE
DOCUMENTREFERENCE | LICENSEREFERENCE
;

licenseExceptionExpression
Expand Down Expand Up @@ -83,8 +83,8 @@ OPEN : '(' ;
CLOSE : ')' ;
PLUS : '+' ;

REFERENCE : ('DocumentRef-' IDSTRING ':')? LICENSEREFERENCE ;
LICENSEREFERENCE : 'LicenseRef-' IDSTRING ;
IDSTRING : (ALPHA | DIGIT)(ALPHA | DIGIT | '-' | '.')* ;
DOCUMENTREFERENCE : 'DocumentRef-' IDSTRING ':' LICENSEREFERENCE ;
LICENSEREFERENCE : 'LicenseRef-' IDSTRING ;
IDSTRING : (ALPHA | DIGIT)(ALPHA | DIGIT | '-' | '.')* ;

WHITESPACE : ' ' -> skip ;
3 changes: 2 additions & 1 deletion spdx-utils/src/test/kotlin/SpdxExpressionParserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ class SpdxExpressionParserTest : WordSpec() {
SpdxExpression.parse("((")
}

exception.message shouldBe "mismatched input '<EOF>' expecting {'(', REFERENCE, IDSTRING}"
exception.message shouldBe
"mismatched input '<EOF>' expecting {'(', DOCUMENTREFERENCE, LICENSEREFERENCE, IDSTRING}"
}
}
}
Expand Down

0 comments on commit 13fa6ee

Please sign in to comment.