From 147fec98b54e0eb47593a9e5bebb8e2f56f6c15f Mon Sep 17 00:00:00 2001 From: xonix Date: Sun, 28 Apr 2024 03:09:28 +0300 Subject: [PATCH 1/3] Improve auto-complete for this case #186 : adjust grammar --- src/main/java/intellij_awk/Awk.bnf | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/intellij_awk/Awk.bnf b/src/main/java/intellij_awk/Awk.bnf index ac2c3d7..a5906a5 100644 --- a/src/main/java/intellij_awk/Awk.bnf +++ b/src/main/java/intellij_awk/Awk.bnf @@ -502,7 +502,7 @@ lvalue ::= gawk_var_name | DOLLAR expr // XXX this covers a[1][2][3] like in Gawk // XXX awk only supports a[1] -private gawk_var_name ::= var_name (LBRACKET expr_lst RBRACKET)* +//private gawk_var_name ::= var_name (LBRACKET expr_lst RBRACKET)* // XXX for some reason the below makes it terribly slow or hanging on profile5.awk /*private gawk_var_name ::= var_name (subscript_start RBRACKET)* @@ -512,6 +512,15 @@ private subscript_start ::= LBRACKET expr_lst { } private recover_on_rbracket ::= !RBRACKET*/ +private gawk_var_name ::= var_name (subscript_start RBRACKET)* +private subscript_start ::= LBRACKET expr_lst_inner { + pin=1 +} +private expr_lst_inner ::= expr_lst { +// recoverWhile=recover_on_rbracket +} +//private recover_on_rbracket ::= !RBRACKET + private var_name ::= builtin_var_name | user_var_name builtin_var_name ::= SPECIAL_VAR_NAME | SPECIAL_VAR_NAME_GAWK From bd86e2c124d299c09c07ac731bcc65cc6c1d0440 Mon Sep 17 00:00:00 2001 From: xonix Date: Sun, 28 Apr 2024 03:13:41 +0300 Subject: [PATCH 2/3] Improve auto-complete for this case #186 : adjust grammar --- src/main/java/intellij_awk/Awk.bnf | 17 ++--------------- .../java/intellij_awk/AwkParserDefinition.java | 2 +- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/main/java/intellij_awk/Awk.bnf b/src/main/java/intellij_awk/Awk.bnf index a5906a5..d8fed51 100644 --- a/src/main/java/intellij_awk/Awk.bnf +++ b/src/main/java/intellij_awk/Awk.bnf @@ -502,24 +502,11 @@ lvalue ::= gawk_var_name | DOLLAR expr // XXX this covers a[1][2][3] like in Gawk // XXX awk only supports a[1] -//private gawk_var_name ::= var_name (LBRACKET expr_lst RBRACKET)* - -// XXX for some reason the below makes it terribly slow or hanging on profile5.awk -/*private gawk_var_name ::= var_name (subscript_start RBRACKET)* -private subscript_start ::= LBRACKET expr_lst { - pin=1 - recoverWhile=recover_on_rbracket -} -private recover_on_rbracket ::= !RBRACKET*/ - private gawk_var_name ::= var_name (subscript_start RBRACKET)* -private subscript_start ::= LBRACKET expr_lst_inner { +private subscript_start ::= LBRACKET expr_lst +{ pin=1 } -private expr_lst_inner ::= expr_lst { -// recoverWhile=recover_on_rbracket -} -//private recover_on_rbracket ::= !RBRACKET private var_name ::= builtin_var_name | user_var_name diff --git a/src/main/java/intellij_awk/AwkParserDefinition.java b/src/main/java/intellij_awk/AwkParserDefinition.java index 7511144..1692ef0 100644 --- a/src/main/java/intellij_awk/AwkParserDefinition.java +++ b/src/main/java/intellij_awk/AwkParserDefinition.java @@ -26,7 +26,7 @@ public class AwkParserDefinition implements ParserDefinition { new IStubFileElementType<>(AwkLanguage.INSTANCE) { @Override public int getStubVersion() { - return 16; + return 17; } @Override From 576f0fde9d6cb165c7f1f704f78d72b8140cb58b Mon Sep 17 00:00:00 2001 From: xonix Date: Mon, 29 Apr 2024 14:38:17 +0300 Subject: [PATCH 3/3] Improve auto-complete for this case #186 : add test --- .../java/intellij_awk/AwkCompletionTests.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/test/java/intellij_awk/AwkCompletionTests.java b/src/test/java/intellij_awk/AwkCompletionTests.java index 727f46b..1746096 100644 --- a/src/test/java/intellij_awk/AwkCompletionTests.java +++ b/src/test/java/intellij_awk/AwkCompletionTests.java @@ -430,21 +430,32 @@ public void testLocalVariableInAction3() { } public void testGlobalVariableInAction1() { - checkCompletionAuto("{ Xxx=1 } function f(){ Xx }", "{ Xxx=1 } function f(){ Xxx }"); + checkCompletionAuto( + "{ Xxx=1 } function f(){ Xx }", "{ Xxx=1 } function f(){ Xxx }"); } + public void testGlobalVariableInAction2() { checkCompletionAuto("{ Xxx=1 }\nXx", "{ Xxx=1 }\nXxx"); } + public void testGlobalVariableInAction3() { checkCompletionAuto("/a/{ xxx=1 } /b/{ xx }", "/a/{ xxx=1 } /b/{ xxx }"); } + public void testGlobalVariableInAction4() { - checkCompletionAuto("function f(){ Xxx=1 } { Xx }", "function f(){ Xxx=1 } { Xxx }"); + checkCompletionAuto( + "function f(){ Xxx=1 } { Xx }", "function f(){ Xxx=1 } { Xxx }"); } + public void testGlobalVariableInAction5_NotLocal() { checkCompletionEmpty("function f(Xxx){ Xxx=1 } { Xx }"); } + public void testMustCompleteInsideEmptySubscript() { + checkCompletion( + Set.of("q1q2q3"), Set.of(), "BEGIN {\n a[]\n}\n\nfunction q1q2q3() {\n}"); + } + private void checkFunctionArgs(String code, String fName, String expectedArgs) { setupCode(code); LookupElement[] variants = myFixture.completeBasic();