From d6915ce74330cf95c5d0852e8ed5f4aa6e0555ca Mon Sep 17 00:00:00 2001 From: Martin Nonnenmacher Date: Sun, 4 Feb 2024 11:21:09 +0100 Subject: [PATCH] feat(spdx-utils): Take the new parser implementation into use Replace the ANTLR based parser with the new implementation in `SpdxExpression.parse()`. Signed-off-by: Martin Nonnenmacher --- utils/spdx/src/main/kotlin/SpdxExpression.kt | 21 +++----------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/utils/spdx/src/main/kotlin/SpdxExpression.kt b/utils/spdx/src/main/kotlin/SpdxExpression.kt index 8ce617adcb6a5..902ff0d72a95e 100644 --- a/utils/spdx/src/main/kotlin/SpdxExpression.kt +++ b/utils/spdx/src/main/kotlin/SpdxExpression.kt @@ -23,11 +23,9 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer -import org.antlr.v4.runtime.CharStreams -import org.antlr.v4.runtime.CommonTokenStream - import org.ossreviewtoolkit.utils.spdx.SpdxConstants.DOCUMENT_REF_PREFIX import org.ossreviewtoolkit.utils.spdx.SpdxConstants.LICENSE_REF_PREFIX +import org.ossreviewtoolkit.utils.spdx.parser.SpdxExpressionParser /** * An SPDX expression as defined by version 2.1 of the [SPDX specification, appendix IV][1]. @@ -86,21 +84,8 @@ sealed class SpdxExpression { * allowed ([ALLOW_DEPRECATED][Strictness.ALLOW_DEPRECATED]) or only current license identifiers are allowed * ([ALLOW_CURRENT][Strictness.ALLOW_CURRENT]). Throws an [SpdxException] if the string cannot be parsed. */ - fun parse(expression: String, strictness: Strictness): SpdxExpression { - val charStream = CharStreams.fromString(expression) - val lexer = SpdxExpressionLexer(charStream).apply { - removeErrorListeners() - addErrorListener(SpdxErrorListener()) - } - - val tokenStream = CommonTokenStream(lexer) - val parser = SpdxExpressionParser(tokenStream).apply { - removeErrorListeners() - addErrorListener(SpdxErrorListener()) - } - - return SpdxExpressionDefaultVisitor(strictness).visit(parser.licenseExpression()) - } + fun parse(expression: String, strictness: Strictness): SpdxExpression = + SpdxExpressionParser(expression, strictness).parse() } /**