hussainahmad / as3corelib

Automatically exported from code.google.com/p/as3corelib
0 stars 0 forks source link

Add line numbers to parse errors #138

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. If you parse a manually create JSON file, it does not give you a line error 
for the error in the error text.

You can get the line number using something like this:

try {
    JSON.decode(rawJSONString);
}
catch (e:JSONParseError) {
    String(rawJSONString).substring(0, e.location).split("\n").length
}

It would be nicer if it was already included in the error text.

I'd be happy to make a patch if you are interested (I assume I'd have to patch 
the tokenizer.parseError() lines in JSONDecoder.as ..)

Original issue reported on code.google.com by Tou...@gmail.com on 17 Feb 2010 at 9:42

GoogleCodeExporter commented 8 years ago
oh, or maybe JSONTokenizer.as

Original comment by Tou...@gmail.com on 17 Feb 2010 at 9:54

GoogleCodeExporter commented 8 years ago
I did this in JSONTokenizer, though I'm sure a property with the line number 
and a way to append it in the 
parseError (where the rest of the message is constructed) call would be more 
appropriate. This worked for my 
needs though.

public function parseError( message:String ):void {
    throw new JSONParseError(
        message + " (line " + jsonString.substring(0, loc).split("\n").length +")",
            loc, jsonString
    );
}

Original comment by Tou...@gmail.com on 3 Mar 2010 at 7:35