I have to share it with you guys, because I did not find anything like a feedback forum for the antlr works 2, and I guess I have a lot of strong emotions my non geeky friends are not going to be interested in.
I've been keeping track of the antlr project for years now and I have to say it is still unusable by simple folks like me.
ok, here is my story. raw emotions. just don't read it if you are not ready.
I opened the antlr works 2 on windows. Copied a simple grammar from the book to the editor. Doesn't work! "Grammar has no rules". I've been programming since 2nd grade. It's been freaking 22 years! I didn't figure out what was wrong. I moved back and forth for 10 minutes and I didn't understand. Know what it was? Apparently the "IDE" doesn't feel it is necessary to save the file I'm editing first, prior to giving it to the tools!
OK. I need a very, VERY simple parser. I want to parse a chess FEN string. The parser is rather trivial to write by hand. Apparently I need lexer modes for that. Apparently that's an advanced feature, cause now the IDE says that I have to have a separate file for the lexer.
Do you think that steep learning curve they've been talking about when they mention ANTLR is about fancy LL(k) concepts? Actually I watched one video and got it. Steep learning curve is to figure out how the freak you make ANTLR understand that there are two related files: lexer and parser and that they should go together!
Apparently it's not simple. The so called IDE doesn't clean the error messages from the output, so whatever you do, you always have it red :( It took me 15 minutes, to figure out that lexer has to be precompiled first and only then does parser see it! That's the curve, not the "lexing" and "parsing" concepts.
Actually they teach you about "lexing" and "parsing" in any decent university. It's tools that make entering this universe so annoying.
Now came the moment when I just gave up. Finally I have lexer and parser, and there's no warnings nor errors, and I saved them, and I generated the java code from them (because by now there's no hope that the IDE does it itself when I press Run or give meaningful error), and I press "Run in TestRig...", and I have no hope that it will work. I'm internally ready that there will be an error, and it will not be descriptive, and I will go and google again.
Guess what?
> Compiling grammar files...
> Arguments: [-o, C:\Users\Ilya\AppData\Local\Temp\TestRigTask-1435265231249, -lib, C:\Users\Ilya\Documents\Antlr, -no-listener, -no-visitor, C:\Users\Ilya\Documents\Antlr\FenLexer.g4]
That's it. That is all the "IDE" gave me. It does not work. There is no error. There is no "Done" message box. There is no "You are freaking idiot" message box. Nothing. How do I ask google why there is nothing going on?
I give up. I guess I will return a few years later again.
If someone read all the crap I just wrote and has a minute, I would love to read an explanation of why it is logical for the IDE to not follow up on the command I gave it.
Just in case it is needed here is the code:
lexer grammar FenLexer;
Piece : [pnbrqkPNBRQK];
Gap : [12345678];
Sep : '/';
TooManySpaces : ' ';
Ws : ' ' -> skip, pushMode(TURN);
mode TURN;
Black : 'b';
White : 'w';
TurnEnd : ' ' -> skip, popMode, pushMode(CASTLINGS);
mode CASTLINGS;
NoCastling : '-';
CastlingOption : [KQkq];
CastlingsEnd : ' ' -> skip, popMode, pushMode(ENPASSANT);
mode ENPASSANT;
NoEnPassant : '-';
File : [abcdefgh];
EnBlack : '3';
EnWhite : '6';
EnPassantEnd : ' ' -> skip, popMode, pushMode(TAIL);
mode TAIL;
Int : [0-9]+;
TailWs : ' ' -> skip;
parser grammar FenParser;
//import FenLexer;
options {
tokenVocab=FenLexer;
}
fen : core Int Int;
core : placement turn castlings enPassant;
placement
: rank Sep rank Sep rank Sep rank Sep
rank Sep rank Sep rank Sep rank;
rank : (Piece | Gap)+;
turn : Black | White;
castlings
: NoCastling
| CastlingOption (CastlingOption (CastlingOption CastlingOption?)?)?
;
enPassant
: NoEnPassant
| (EnBlack | EnWhite) File;