diff --git a/build.gradle b/build.gradle index a4cd13d..ba17b0e 100644 --- a/build.gradle +++ b/build.gradle @@ -5,11 +5,11 @@ buildscript { } plugins { - id "org.jetbrains.intellij" version "0.4.2" + id "org.jetbrains.intellij" version "1.1.3" } wrapper { - gradleVersion = '5.2.1' + gradleVersion = '7.1.1' } group 'antlr' @@ -27,9 +27,9 @@ compileJava { intellij { version = ideaVersion - pluginName 'antlr4-intellij-plugin-sample' - downloadSources true - updateSinceUntilBuild false + pluginName = 'antlr4-intellij-plugin-sample' + downloadSources = true + updateSinceUntilBuild = false } repositories { @@ -41,9 +41,5 @@ dependencies { exclude group:'com.ibm.icu', module:'icu4j' } implementation 'org.antlr:antlr4-intellij-adaptor:0.1' - testCompile group: 'junit', name: 'junit', version: '4.11' + testImplementation group: 'junit', name: 'junit', version: '4.11' } - -generateGrammarSource { - arguments += ["-package", "org.antlr.jetbrains.sample.parser", "-Xexact-output-dir"] -} \ No newline at end of file diff --git a/contributors.txt b/contributors.txt index 89241dd..aa659d3 100644 --- a/contributors.txt +++ b/contributors.txt @@ -54,3 +54,4 @@ YYYY/MM/DD, github id, Full name, email 2015/11/09, parrt, Terence Parr, parrt@antlr.org 2019/02/13, Kisioj, Krzysztof Jura, kisioj@gmail.com 2019/02/13, bjansen, Bastien Jansen, bastien.jansen@gmx.com +2021/07/15, matozoid, Danny van Bruggen, hexagonaal@gmail.com diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 44e7c4d..af7be50 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/antlr/org/antlr/jetbrains/sample/parser/SampleLanguage.g4 b/src/main/antlr/org/antlr/jetbrains/sample/parser/SampleLanguage.g4 index 9e6fd27..843fcd2 100644 --- a/src/main/antlr/org/antlr/jetbrains/sample/parser/SampleLanguage.g4 +++ b/src/main/antlr/org/antlr/jetbrains/sample/parser/SampleLanguage.g4 @@ -8,12 +8,13 @@ * Generate the parser via "mvn compile" from root dir of project. */ grammar SampleLanguage; +@header {package org.antlr.jetbrains.sample.parser;} /** The start rule must be whatever you would normally use, such as script * or compilationUnit, etc... */ script - : vardef* function* statement* EOF + : (vardef|function|statement)* EOF ; function diff --git a/src/test/java/org/antlr/jetbrains/adaptor/test/TestXPath.java b/src/test/java/org/antlr/jetbrains/adaptor/test/TestXPath.java index c325954..04303ca 100644 --- a/src/test/java/org/antlr/jetbrains/adaptor/test/TestXPath.java +++ b/src/test/java/org/antlr/jetbrains/adaptor/test/TestXPath.java @@ -1,6 +1,5 @@ -package org.antlr.intellij.adaptor.test; +package org.antlr.jetbrains.adaptor.test; -import com.intellij.lang.Language; import com.intellij.psi.PsiElement; import com.intellij.psi.impl.source.tree.LeafPsiElement; import com.intellij.testFramework.ParsingTestCase; @@ -8,32 +7,35 @@ import org.antlr.jetbrains.sample.SampleLanguage; import org.antlr.jetbrains.sample.SampleParserDefinition; -import java.io.IOException; import java.util.Collection; public class TestXPath extends ParsingTestCase { + + public static final String TEST_SAMPLE = "src/test/java/org/antlr/jetbrains/adaptor/test/test.sample"; + public static final String BUBBLESORT_SAMPLE = "src/test/java/org/antlr/jetbrains/adaptor/test/bubblesort.sample"; + public TestXPath() { super("", "Sample", new SampleParserDefinition()); } - public void testSingleVarDef() throws Exception { + public void testSingleVarDef() { String code = "var x = 1"; String output = code; - String xpath = "/script/statement"; + String xpath = "/script"; checkXPathResults(code, xpath, output); } - public void testMultiVarDef() throws Exception { + public void testMultiVarDef() { String code = "var x = 1\n" + "var y = [1,2,3]\n"; String output = code; - String xpath = "/script/statement"; + String xpath = "/script"; checkXPathResults(code, xpath, output); } public void testFuncNames() throws Exception { - String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample"); + String code = loadFile(TEST_SAMPLE); String output = "f\n"+ "g\n"+ @@ -43,7 +45,7 @@ public void testFuncNames() throws Exception { } public void testAllIDs() throws Exception { - String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample"); + String code = loadFile(TEST_SAMPLE); String output = "f\n"+ "x\n"+ @@ -60,7 +62,7 @@ public void testAllIDs() throws Exception { } public void testAnyVarDef() throws Exception { - String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample"); + String code = loadFile(TEST_SAMPLE); String output = "var y = x\n"+ "var z = 9"; @@ -69,7 +71,7 @@ public void testAnyVarDef() throws Exception { } public void testVarDefIDs() throws Exception { - String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample"); + String code = loadFile(TEST_SAMPLE); String output = "y\n" + "z"; @@ -78,30 +80,29 @@ public void testVarDefIDs() throws Exception { } public void testAllVarDefIDsInScopes() throws Exception { - String code = loadFile("test/org/antlr/jetbrains/adaptor/test/bubblesort.sample"); + String code = loadFile(BUBBLESORT_SAMPLE); String output = "x\n"+ "i\n"+ "j\n"+ "swap\n"+ "x"; - String xpath = "//block/statement/vardef/ID"; + String xpath = "//block/vardef/ID"; checkXPathResults(code, xpath, output); } public void testTopLevelVarDefIDsInScopes() throws Exception { - String code = loadFile("test/org/antlr/jetbrains/adaptor/test/bubblesort.sample"); + String code = loadFile(BUBBLESORT_SAMPLE); String output = "x\n"+ "i"; - String xpath = "//function/block/statement/vardef/ID"; + String xpath = "//function/block/vardef/ID"; checkXPathResults(code, xpath, output); } public void testRuleUnderWildcard() throws Exception { - String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample"); + String code = loadFile(TEST_SAMPLE); String output = - "var y = x\n"+ "x\n"+ "[\n"+ "1\n"+ @@ -109,13 +110,13 @@ public void testRuleUnderWildcard() throws Exception { "=\n"+ "\"sdflkjsdf\"\n"+ "return\n"+ - "false;"; + "false"; String xpath = "//function/*/statement/*"; checkXPathResults(code, xpath, output); } public void testAllNonWhileTokens() throws Exception { - String code = loadFile("test/org/antlr/jetbrains/adaptor/test/bubblesort.sample"); + String code = loadFile(BUBBLESORT_SAMPLE); String output = "(\n"+ ")\n"+ @@ -125,7 +126,7 @@ public void testAllNonWhileTokens() throws Exception { } public void testGetNestedIf() throws Exception { - String code = loadFile("test/org/antlr/jetbrains/adaptor/test/bubblesort.sample"); + String code = loadFile(BUBBLESORT_SAMPLE); String output = "if"; String xpath = "//'if'"; @@ -133,7 +134,7 @@ public void testGetNestedIf() throws Exception { } public void testWildcardUnderFuncThenJustTokens() throws Exception { - String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample"); + String code = loadFile(TEST_SAMPLE); String output = "func\n"+ "f\n"+ @@ -165,15 +166,11 @@ public void testWildcardUnderFuncThenJustTokens() throws Exception { // S U P P O R T - protected void checkXPathResults(String code, String xpath, String allNodesText) throws IOException { - checkXPathResults(SampleLanguage.INSTANCE, code, xpath, allNodesText); - } - - protected void checkXPathResults(Language language, String code, String xpath, String allNodesText) throws IOException { + protected void checkXPathResults(String code, String xpath, String allNodesText) { myFile = createPsiFile("a", code); ensureParsed(myFile); assertEquals(code, myFile.getText()); - Collection nodes = XPath.findAll(language, myFile, xpath); + Collection nodes = XPath.findAll(SampleLanguage.INSTANCE, myFile, xpath); StringBuilder buf = new StringBuilder(); for (PsiElement t : nodes) { buf.append(t.getText()); diff --git a/src/test/java/org/antlr/jetbrains/adaptor/test/test.sample b/src/test/java/org/antlr/jetbrains/adaptor/test/test.sample index 057aebd..5ec7f1f 100644 --- a/src/test/java/org/antlr/jetbrains/adaptor/test/test.sample +++ b/src/test/java/org/antlr/jetbrains/adaptor/test/test.sample @@ -5,6 +5,6 @@ func f(x:[]) { func g(x:int, y:float) { } -func h() : boolean { return false; } +func h() : boolean { return false } var z = 9