This project is read-only.

Hime Parser Error Messages

Aug 5, 2012 at 4:55 PM


I was testing your 0.5 release, and actually really like the parser. There's only one area I think could use some improvement. Right now, errors are collected via the Error property on the generated Parser class, and each error is essentially a string that's returned. For my applications, it would be best to have the line information separated out of the error string so more robust debugging tools can be developed around a language. Using the console, for example, to print out a segment of the line where the error occurred to provide the user more information.

Basically, it'd be nice to have an error struct that looked like this:

struct ParserError
    public string ErrorMessage;
    public HimeErrorType ErrorType; //some enum specifying the different types of errors, so we know if there's a Row/Column or not
    public long Row;
    public long Column;
    public string ToString(); //You can output your current string here
Also, any other error information that could be provided would be pretty useful, as different parsing methods probably provide different information.

Thanks for the parser

Aug 5, 2012 at 5:32 PM


Thank you for your input. This is an excellent idea which will hit the next release.

You may want to check out the sources in a few days if you are impatient :)

Aug 5, 2012 at 6:33 PM

No problem. I probably will check that out since I'm seriously considering using your parser to develop my next language.

You also might want to think of a way to output if an input stream was properly accepted and parsed, verses parsed with errors/warnings, or attempted to parse and failed. This way the program could easily output more informative error messages. In my case, I'll be using the parser to generate an AST and then emit the AST to IL, and during this process, the compiler will have to tell the user as detailed info as possible.

As an example, using the sample grammar:

			var l = new MathExp.MathExpLexer("a 1+7");
			var inter = new Interpreter();
			var par = new MathExp.MathExpParser(l,inter);

The interpreter still manages to output 8, but just by looking at the Error property alone, I can't tell if the error was a fatal one or not. It would be nice to query one property and tell the user there were fatal errors, or compilation succeeded with serious warnings. The string "a 1+7 b" also outputs 8 properly, as well, etc. Also, by checking if there are any warnings, the program can decide if it wants to go ahead and do other things.

Thanks again!