You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/10/17 21:50:18 UTC

[GitHub] [netbeans] lkishalmi opened a new pull request, #4808: More precise code-completion for ANTLRv4 Grammars

lkishalmi opened a new pull request, #4808:
URL: https://github.com/apache/netbeans/pull/4808

   
   Well, just a quick one. Lexer grammars, can only reference fragments inside rules, pure parser grammars cannot reference fragments. Add some heuristic to support lexercommands as well. + icons
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] neilcsmith-net commented on pull request #4808: More precise code-completion for ANTLRv4 Grammars

Posted by GitBox <gi...@apache.org>.
neilcsmith-net commented on PR #4808:
URL: https://github.com/apache/netbeans/pull/4808#issuecomment-1283938845

   Sorry, hadn't a chance to review (and no-one else had) prior to branching.  Please make a call and rebase onto delivery if you think this should go into 16-rc2.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing commented on a diff in pull request #4808: More precise code-completion for ANTLRv4 Grammars

Posted by GitBox <gi...@apache.org>.
matthiasblaesing commented on code in PR #4808:
URL: https://github.com/apache/netbeans/pull/4808#discussion_r1000942703


##########
java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/Antlr4ParserResult.java:
##########
@@ -113,38 +123,52 @@ public void exitTokensSpec(ANTLRv4Parser.TokensSpecContext ctx) {
             public void exitChannelsSpec(ANTLRv4Parser.ChannelsSpecContext ctx) {
                 List<ANTLRv4Parser.IdentifierContext> ids = ctx.idList().identifier();
                 for (ANTLRv4Parser.IdentifierContext id : ids) {
-                    addReference(getIdentifierToken(id));
+                    addReference(ReferenceType.CHANNEL, getIdentifierToken(id));
                 }
             }
 
             @Override
             public void exitModeSpec(ANTLRv4Parser.ModeSpecContext ctx) {
                 if (ctx.identifier() != null) {
-                    addReference(getIdentifierToken(ctx.identifier()));
+                    addReference(ReferenceType.MODE, getIdentifierToken(ctx.identifier()));
                 }
             }
 
-            public void addReference(Token token) {
+            public void addReference(ReferenceType type, Token token) {
                 OffsetRange range = new OffsetRange(token.getStartIndex(), token.getStopIndex() + 1);
                 String name = token.getText();
-                Reference ref = new Reference(name, range);
+                Reference ref = new Reference(type, name, range);
                 references.put(ref.name, ref);
             }
 
         };
     }
 
 
+    private void collectReferences(FileObject fo, Map<String, Reference> refs, Set<String> visited) {
+        if (!visited.contains(fo.getName())) {
+            refs.putAll(references);
+            visited.add(fo.getName());
+            for (String im : imports) {
+                FileObject ifo = getFileObject().getParent().getFileObject(im + ".g4");
+                if (ifo != null) {
+                    Antlr4ParserResult pr = (Antlr4ParserResult) AntlrParser.getParserResult(ifo);

Review Comment:
   This will also create stale errors - if you add a definition to import, there is no reason to invoke the Parser for the including file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing commented on a diff in pull request #4808: More precise code-completion for ANTLRv4 Grammars

Posted by GitBox <gi...@apache.org>.
matthiasblaesing commented on code in PR #4808:
URL: https://github.com/apache/netbeans/pull/4808#discussion_r1000876796


##########
java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/Antlr4ParserResult.java:
##########
@@ -113,38 +123,52 @@ public void exitTokensSpec(ANTLRv4Parser.TokensSpecContext ctx) {
             public void exitChannelsSpec(ANTLRv4Parser.ChannelsSpecContext ctx) {
                 List<ANTLRv4Parser.IdentifierContext> ids = ctx.idList().identifier();
                 for (ANTLRv4Parser.IdentifierContext id : ids) {
-                    addReference(getIdentifierToken(id));
+                    addReference(ReferenceType.CHANNEL, getIdentifierToken(id));
                 }
             }
 
             @Override
             public void exitModeSpec(ANTLRv4Parser.ModeSpecContext ctx) {
                 if (ctx.identifier() != null) {
-                    addReference(getIdentifierToken(ctx.identifier()));
+                    addReference(ReferenceType.MODE, getIdentifierToken(ctx.identifier()));
                 }
             }
 
-            public void addReference(Token token) {
+            public void addReference(ReferenceType type, Token token) {
                 OffsetRange range = new OffsetRange(token.getStartIndex(), token.getStopIndex() + 1);
                 String name = token.getText();
-                Reference ref = new Reference(name, range);
+                Reference ref = new Reference(type, name, range);
                 references.put(ref.name, ref);
             }
 
         };
     }
 
 
+    private void collectReferences(FileObject fo, Map<String, Reference> refs, Set<String> visited) {
+        if (!visited.contains(fo.getName())) {
+            refs.putAll(references);
+            visited.add(fo.getName());
+            for (String im : imports) {
+                FileObject ifo = getFileObject().getParent().getFileObject(im + ".g4");
+                if (ifo != null) {
+                    Antlr4ParserResult pr = (Antlr4ParserResult) AntlrParser.getParserResult(ifo);

Review Comment:
   Won't this blow when grammar files form a cycle? Assuming we have a direct cycle A -> B, B -> A, then:
   
   - user ask for the parser result for file A
   - the parse process will hit this section and ask for the parser result for file B
   - the parser result is not found in the cache, so the parsing for B is invoked
   - parsing for B will hit this section and ask for the parser result of file A
   
   The cycle is closed. I just noticed, that we access other files from the parser. I think this is an error. This kind of error checking needs to be done outside the parser, then you can access the parser results sequentially and build whatever structure you need.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] neilcsmith-net merged pull request #4808: More precise code-completion for ANTLRv4 Grammars

Posted by GitBox <gi...@apache.org>.
neilcsmith-net merged PR #4808:
URL: https://github.com/apache/netbeans/pull/4808


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] lkishalmi commented on a diff in pull request #4808: More precise code-completion for ANTLRv4 Grammars

Posted by GitBox <gi...@apache.org>.
lkishalmi commented on code in PR #4808:
URL: https://github.com/apache/netbeans/pull/4808#discussion_r1002921048


##########
java/languages.antlr/src/org/netbeans/modules/languages/antlr/v4/Antlr4ParserResult.java:
##########
@@ -113,38 +123,52 @@ public void exitTokensSpec(ANTLRv4Parser.TokensSpecContext ctx) {
             public void exitChannelsSpec(ANTLRv4Parser.ChannelsSpecContext ctx) {
                 List<ANTLRv4Parser.IdentifierContext> ids = ctx.idList().identifier();
                 for (ANTLRv4Parser.IdentifierContext id : ids) {
-                    addReference(getIdentifierToken(id));
+                    addReference(ReferenceType.CHANNEL, getIdentifierToken(id));
                 }
             }
 
             @Override
             public void exitModeSpec(ANTLRv4Parser.ModeSpecContext ctx) {
                 if (ctx.identifier() != null) {
-                    addReference(getIdentifierToken(ctx.identifier()));
+                    addReference(ReferenceType.MODE, getIdentifierToken(ctx.identifier()));
                 }
             }
 
-            public void addReference(Token token) {
+            public void addReference(ReferenceType type, Token token) {
                 OffsetRange range = new OffsetRange(token.getStartIndex(), token.getStopIndex() + 1);
                 String name = token.getText();
-                Reference ref = new Reference(name, range);
+                Reference ref = new Reference(type, name, range);
                 references.put(ref.name, ref);
             }
 
         };
     }
 
 
+    private void collectReferences(FileObject fo, Map<String, Reference> refs, Set<String> visited) {
+        if (!visited.contains(fo.getName())) {
+            refs.putAll(references);
+            visited.add(fo.getName());
+            for (String im : imports) {
+                FileObject ifo = getFileObject().getParent().getFileObject(im + ".g4");
+                if (ifo != null) {
+                    Antlr4ParserResult pr = (Antlr4ParserResult) AntlrParser.getParserResult(ifo);

Review Comment:
   You're right. I hope the new implementation is looking better.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] lkishalmi commented on pull request #4808: More precise code-completion for ANTLRv4 Grammars

Posted by GitBox <gi...@apache.org>.
lkishalmi commented on PR #4808:
URL: https://github.com/apache/netbeans/pull/4808#issuecomment-1289531462

   Yes for the time the imports are processed we keep a hard reference on the results.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists