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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to