forked from jasder/antlr
Merge pull request #2086 from ewanmellor/message-output
Improve the "gnu" message format
This commit is contained in:
commit
21a38b3cea
|
@ -19,6 +19,16 @@ except you need to specify the language target, for example:
|
|||
```
|
||||
$ antlr4 -Dlanguage=Swift MyGrammar.g4
|
||||
```
|
||||
|
||||
If you integrate this as a build step inside Xcode, then you should use the
|
||||
"gnu" message format to have any error messages parsed by Xcode. You may
|
||||
also want to use the `-o` option to put the autogenerated files in a
|
||||
separate subdirectory.
|
||||
|
||||
```
|
||||
antlr4 -Dlanguage=Swift -message-format gnu -o Autogen MyGrammar.g4
|
||||
```
|
||||
|
||||
For a full list of antlr4 tool options, please visit the
|
||||
[tool documentation page](tool-options.md).
|
||||
|
||||
|
|
|
@ -31,9 +31,9 @@ This file contains the actual layout of the messages emitted by ANTLR.
|
|||
This file contains the format that mimicks GCC output.
|
||||
*/
|
||||
|
||||
location(file, line, column) ::= "<file>:<line>:"
|
||||
location(file, line, column) ::= "<file>:<line>:<column>:"
|
||||
|
||||
message(id, text) ::= "<text> (<id>)"
|
||||
message(id, text) ::= "<text> [error <id>]"
|
||||
|
||||
report(location, message, type) ::= "<location> <type>: <message>"
|
||||
|
||||
|
|
|
@ -60,11 +60,20 @@ public class ErrorManager {
|
|||
locationValid = true;
|
||||
}
|
||||
if (msg.fileName != null) {
|
||||
File f = new File(msg.fileName);
|
||||
// Don't show path to file in messages; too long.
|
||||
String displayFileName = msg.fileName;
|
||||
if ( f.exists() ) {
|
||||
displayFileName = f.getName();
|
||||
if (format.equals("antlr")) {
|
||||
// Don't show path to file in messages in ANTLR format;
|
||||
// they're too long.
|
||||
File f = new File(msg.fileName);
|
||||
if ( f.exists() ) {
|
||||
displayFileName = f.getName();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// For other message formats, use the full filename in the
|
||||
// message. This assumes that these formats are intended to
|
||||
// be parsed by IDEs, and so they need the full path to
|
||||
// resolve correctly.
|
||||
}
|
||||
locationST.add("file", displayFileName);
|
||||
locationValid = true;
|
||||
|
|
Loading…
Reference in New Issue