From 63ddf2435a9b33ff2ad6c7dca82cd1f7aa76039b Mon Sep 17 00:00:00 2001 From: Shane Poage Date: Fri, 2 Feb 2024 13:51:26 -0600 Subject: [PATCH] * Compatibility: upgrade to 2023.3 / 233.2 version (#166) * Grammar: multidimensional array rule heads considered valid * Grammar: else expressions no longer consider ':=' invalid * tests: bump OPA version to v0.61.0 Signed-off-by: Shane Poage --- .github/workflows/test.yml | 2 +- build.gradle.kts | 4 ++-- gradle.properties | 10 +++++----- src/main/grammar/Rego.bnf | 4 ++-- .../ideaplugin/ide/highlight/RegoHighlighter.kt | 2 +- .../ideaplugin/lang/parser/fixtures/else_keyword.rego | 6 ++++++ .../ideaplugin/lang/parser/fixtures/rule_head.rego | 5 ++++- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b0eeef2..0fea9b4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,7 +52,7 @@ jobs: - name: Download OPA run: | - OPA_VERSION=v0.59.0 + OPA_VERSION=v0.61.0 mkdir -p /tmp/opa_bin curl -L -o /tmp/opa_bin/opa https://github.com/open-policy-agent/opa/releases/download/$OPA_VERSION/opa_linux_amd64 chmod +x /tmp/opa_bin/opa diff --git a/build.gradle.kts b/build.gradle.kts index 3e141f6..72336a0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -44,8 +44,8 @@ idea { plugins { idea kotlin("jvm") version "1.9.21" - id("org.jetbrains.intellij") version "1.16.1" - id("org.jetbrains.grammarkit") version "2022.3.1" + id("org.jetbrains.intellij") version "1.17.0" + id("org.jetbrains.grammarkit") version "2022.3.2" } allprojects { diff --git a/gradle.properties b/gradle.properties index 1f4bc2d..6c0870a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,13 +9,13 @@ kotlin.code.style=official baseIDE=idea # if you change the version of ide, also change psiViewerPluginVersion accordingly (cf https://plugins.jetbrains.com/plugin/227-psiviewer/versions) -ideaVersion=IC-2023.2 -pycharmCommunityVersion=PC-2023.2 -psiViewerPluginVersion=232.2 +ideaVersion=IC-2023.3 +pycharmCommunityVersion=PC-2023.3 +psiViewerPluginVersion=233.2 # see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for more information -sinceBuild=232 -untilBuild=233.* +sinceBuild=233 +untilBuild=241.* # these two variables will be overwritten by the release process (i.e. the GitHub action) thanks to the env variables: # - ORG_GRADLE_PROJECT_publishToken diff --git a/src/main/grammar/Rego.bnf b/src/main/grammar/Rego.bnf index 0b8434d..ceb2113 100644 --- a/src/main/grammar/Rego.bnf +++ b/src/main/grammar/Rego.bnf @@ -67,10 +67,10 @@ module ::= package (import| rule)* package ::= "package" ref import ::= "import" ref ( "as" var )? rule ::= "default"? rule-head rule-body* -rule-head ::= var ( "(" rule-args? ")" )? ("[" term "]" )? ( ( ":=" | "=" ) expr )? +rule-head ::= var ( "(" rule-args? ")" )? ("[" term "]" )* ( ( ":=" | "=" ) expr )? rule-args ::= term ( "," term )* rule-body ::= else-expr | query-block -else-expr ::= else "=" expr query-block? | else "="? query-block +else-expr ::= else (':=' | '=') expr query-block? | else (':=' | '=')? query-block query-block ::= "{" query "}" query ::= ( literal |';' )+ literal ::= ( some-decl | literal-expr | "not" literal-expr ) with-modifier* diff --git a/src/main/kotlin/org/openpolicyagent/ideaplugin/ide/highlight/RegoHighlighter.kt b/src/main/kotlin/org/openpolicyagent/ideaplugin/ide/highlight/RegoHighlighter.kt index b2382f7..1290268 100644 --- a/src/main/kotlin/org/openpolicyagent/ideaplugin/ide/highlight/RegoHighlighter.kt +++ b/src/main/kotlin/org/openpolicyagent/ideaplugin/ide/highlight/RegoHighlighter.kt @@ -26,7 +26,7 @@ class RegoHighlighter : SyntaxHighlighterBase() { override fun getTokenHighlights(tokenType: IElementType): Array = pack(tokenToColorMap[tokenType]) - val tokenToColorMap: Map = HashMap() + val tokenToColorMap: MutableMap = HashMap() init { fillMap(tokenToColorMap, LINE_COMMENT.textAttributesKey, RegoTypes.COMMENT) diff --git a/src/test/resources/org/openpolicyagent/ideaplugin/lang/parser/fixtures/else_keyword.rego b/src/test/resources/org/openpolicyagent/ideaplugin/lang/parser/fixtures/else_keyword.rego index dd866ea..95994d2 100644 --- a/src/test/resources/org/openpolicyagent/ideaplugin/lang/parser/fixtures/else_keyword.rego +++ b/src/test/resources/org/openpolicyagent/ideaplugin/lang/parser/fixtures/else_keyword.rego @@ -56,6 +56,12 @@ check_only_equal_querry_for_else = true { true } +check_else_with_colon_assignment_op { + input.x < input.y +} else := true { + input.y < input.x +} else := false + # issue 84 check_empty_query_else = true { input.x < input.y diff --git a/src/test/resources/org/openpolicyagent/ideaplugin/lang/parser/fixtures/rule_head.rego b/src/test/resources/org/openpolicyagent/ideaplugin/lang/parser/fixtures/rule_head.rego index efb25b3..977b600 100644 --- a/src/test/resources/org/openpolicyagent/ideaplugin/lang/parser/fixtures/rule_head.rego +++ b/src/test/resources/org/openpolicyagent/ideaplugin/lang/parser/fixtures/rule_head.rego @@ -15,4 +15,7 @@ b := a1 | a2 | a3 c := a1 & a2 | a3 - b d := 1+2 - array.concat(array1, array2)[2] -e := array.concat(array1, array2)[0] + array.concat(array1, array2)[1] \ No newline at end of file +e := array.concat(array1, array2)[0] + array.concat(array1, array2)[1] + +# multidimensional array +f["first"]["second"] := "some value" \ No newline at end of file