ANTLR exit codes

43 views
Skip to first unread message

Mike Lischke

unread,
Sep 20, 2016, 5:23:32 AM9/20/16
to antlr-di...@googlegroups.com
Hi,

I couldn't find any information about the exit status of the ANTLR tool (only a question in the old antlr-interest list). So, what does ANTLR set on successful generation or in an error case?

It seems as if it always returns 0 currently, which means other build tools which depend on this step never know if they should continue or not. But I might be wrong.

Mike
--
www.soft-gems.net

Gerald Rosenberg

unread,
Sep 20, 2016, 7:02:41 PM9/20/16
to antlr-discussion
The relevant code in Tool.java (line 207) is

    if (antlr.errMgr.getNumErrors() > 0) {
         antlr.exit(1);
 
   }
 
   antlr.exit(0);
 }

Mike Lischke

unread,
Sep 21, 2016, 3:38:34 AM9/21/16
to antlr-di...@googlegroups.com

The relevant code in Tool.java (line 207) is

    if (antlr.errMgr.getNumErrors() > 0) {
         antlr.exit(1);
 
   }
 
   antlr.exit(0);
 }

Thanks Gerald, but somehow this isn't really at the core of the problem. In XCode I get a warning that a tool issued error messages but did not set the exit code to != 0 when I run ANTLR4 in a script. That seems to indicate that the exit code was still 0, even when there are errors.

I even tried this code in my script:

if [ $? -eq 0 ]; then
  echo "Success"
else
  echo "Fail"
fi

but it always shows "Success". There must be something between Java and OSX that doesn't work as expected. But then it's not really an ANTLR problem.


Loring Craymer

unread,
Sep 21, 2016, 3:57:56 AM9/21/16
to antlr-discussion
Mike--

I doubt that it is an OSX issue; I believe that it is a sign that not all exceptions invoke the error manager. Try running antlr over a file that has errors in a debugger and catch exceptions as they are thrown. That should help you localize the problem, although the error manager is also used to issue warnings which will not be counted as errors but will use System.err.

--Loring

Gerald Rosenberg

unread,
Sep 21, 2016, 2:26:00 PM9/21/16
to antlr-discussion
The tool has an option ("-Werror") to treat warnings as errors.

Mike Lischke

unread,
Sep 22, 2016, 3:06:07 AM9/22/16
to antlr-di...@googlegroups.com
The tool has an option ("-Werror") to treat warnings as errors.

The messages I got were errors already, so this wouldn't help. I'll play a bit with that in Eclipse to see if ANTLR really returns the correct exit code and/or this code doesn't end up in scripts.


On Wednesday, September 21, 2016 at 12:38:34 AM UTC-7, Mike Lischke wrote:

The relevant code in Tool.java (line 207) is

    if (antlr.errMgr.getNumErrors() > 0) {
         antlr.exit(1);
 
   }
 
   antlr.exit(0);
 }

Thanks Gerald, but somehow this isn't really at the core of the problem. In XCode I get a warning that a tool issued error messages but did not set the exit code to != 0 when I run ANTLR4 in a script. That seems to indicate that the exit code was still 0, even when there are errors.

Jim Idle

unread,
Sep 22, 2016, 3:12:16 AM9/22/16
to antlr-di...@googlegroups.com
Is the script that is running the antlr tool capturing the antlr exit code and passing it on externally? I have not used XCode in a long time, but if the tool is being called via some kind of script harness and does not pass on the exit code, then this can happen. ANTLR exits with exit(1), the script captures that, but the script then just exits with 0. Just a thought.

Jim

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussion+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mike Lischke

unread,
Sep 22, 2016, 3:25:08 AM9/22/16
to antlr-di...@googlegroups.com
Is the script that is running the antlr tool capturing the antlr exit code and passing it on externally? I have not used XCode in a long time, but if the tool is being called via some kind of script harness and does not pass on the exit code, then this can happen. ANTLR exits with exit(1), the script captures that, but the script then just exits with 0. Just a thought.

I just double checked and see now that the script handles the error code as it should. Either that code is not returned to XCode or XCode itself has a problem. In either case it's not an ANTLR problem.


Reply all
Reply to author
Forward
0 new messages