Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8399425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:18:08+00:00 2026-06-09T21:18:08+00:00

path[Scope sc] returns [Path p] @init{ List<String> parts = new ArrayList<String>(); } : ^(PATH

  • 0
path[Scope sc] returns [Path p]
@init{
List<String> parts = new ArrayList<String>();
}
    :   ^(PATH (id=IDENT{parts.add($id.text);})+ pathIndex? )
{// ACTION CODE
 // need to check if pathIndex has executed before running this code.
    if ($pathIndex.index >=0 ){
        p = new Path($sc, parts, $pathIndex.index);
    }else if($pathIndex.pathKey != ""){
        p = new Path($sc, parts, $pathIndex.pathKey);
}
;

Is there a way to detect if pathIndex was executed? In my action code, I tried testing $pathIndex == null, but ANTLR doesn’t let you do that. ANTLRWorks gives a syntax error which saying “Missing attribute access on rule scope: pathIndex.”

The reason why I need to do this is because in my action code I do:

$pathIndex.index

which returns 0 if the variable $pathIndex is translated to is null. When you are accessing an attribute, ANTLR generates pathIndex7!=null?pathIndex7.index:0 This causes a problem with an object because it changes a value I have preset to -1 as an error flag to 0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:18:09+00:00Added an answer on June 9, 2026 at 9:18 pm

    There are a couple of options:

    1

    Put your code inside the optional pathIndex:

    rule
     : ^(PATH (id=IDENT{parts.add($id.text);})+ (pathIndex {/*pathIndex cannot be null here!*/} )? )
     ;
    

    2

    Use a boolean flag to denote the presence (or absence) of pathIndex:

    rule
    @init{boolean flag = false;}
     : ^(PATH (id=IDENT{parts.add($id.text);})+ (pathIndex {flag = true;} )? )
       {
         if(flag) {
           // ...
         }
       }
     ;
    

    EDIT

    You could also make pathIndex match nothing so that you don’t need to make it optional inside path:

    path[Scope sc] returns [Path p]
     : ^(PATH (id=IDENT{parts.add($id.text);})+ pathIndex)
       {
         // code
       }
     ;
    
    pathIndex returns [int index, String pathKey]
    @init {
      $index = -1;
      $pathKey = "";
    }
     : ( /* some rules here */ )?
     ;
    

    PS. Realize that the expression $pathIndex.pathKey != "" will most likely evaluate to false. To compare the contents of strings in Java, use their equals(...) method instead:

    !$pathIndex.pathKey.equals("")
    

    or if $pathIndex.pathKey can be null, you can circumvent a NPE by doing:

    !"".equals($pathIndex.pathKey)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 path objects in my android code.I have tried all the way
I've a class as shown below: @Path(/myrequest) @Scope(request) @Component public class MyRESTCode implements IServicedResource<T>
Is there a way to start a new scope (room) in red5 from the
I'm running this in node.js. Why does the following code segment lose scope for
My code is as follows: #include <curl/curl.h> struct callback_data { FILE *output; char *path;
JSFiddler: http://jsfiddle.net/A3vg6/20/ var regex = /(?:window|scope|data|owner)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*/gi; var path = []; var vars = [];
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [path objectAtIndex:0]; NSString *databasePath =
The path to libidl.so.7.1 is in ld.so.conf, and the library is in the cache
I'm trying to path a web address to a bash script run under cgi.
Now on writing path as sys.path.insert(0,'/home/pooja/Desktop/mysite'), it ran fine asked me for the word

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.