From d4b8ec31dd7925346e9441875e116b8985cb704d Mon Sep 17 00:00:00 2001 From: James Roseborough Date: Sat, 27 Oct 2012 15:03:57 +0000 Subject: [PATCH] Improve sample code for LuaParser. --- README.html | 7 ++++--- examples/jse/SampleParser.java | 15 ++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/README.html b/README.html index 3aa6dd2f..6b480d73 100644 --- a/README.html +++ b/README.html @@ -638,9 +638,10 @@ For example, to parse a file and print all variable names, use code like: } } ); } catch ( ParseException e ) { - System.out.println( "parse failed: "+e - +" line "+e.currentToken.beginLine - +" col "+e.currentToken.beginColumn); + System.out.println("parse failed: " + e.getMessage() + "\n" + + "Token Image: '" + e.currentToken.image + "'\n" + + "Location: " + e.currentToken.beginLine + ":" + e.currentToken.beginColumn + + "-" + e.currentToken.endLine + "," + e.currentToken.endColumn); } diff --git a/examples/jse/SampleParser.java b/examples/jse/SampleParser.java index 09a78f04..3afa1be9 100644 --- a/examples/jse/SampleParser.java +++ b/examples/jse/SampleParser.java @@ -22,8 +22,8 @@ public class SampleParser { try { final String file = args[0]; - // Create a custom LuaParser subclass that intercepts parse exceptions and - // extracts the line and column number information from the parse token. + // Create a LuaParser. This will fill in line and column number + // information for most exceptions. LuaParser parser = new LuaParser(new FileInputStream(file)); // Perform the parsing. @@ -55,13 +55,10 @@ public class SampleParser { } ); } catch ( ParseException e ) { - System.out.println( "Parse failed : "+e ); - System.out.println( "Begin Line: "+e.currentToken.beginColumn ); - System.out.println( "Begin Column: "+e.currentToken.endColumn ); - System.out.println( "End Line: "+e.currentToken.beginColumn ); - System.out.println( "End Column: "+e.currentToken.endColumn ); - System.out.println( "Token Image: '"+e.currentToken.image+"'" ); - System.out.println( "Message: "+e.getMessage() ); + System.out.println("parse failed: " + e.getMessage() + "\n" + + "Token Image: '" + e.currentToken.image + "'\n" + + "Location: " + e.currentToken.beginLine + ":" + e.currentToken.beginColumn + + "-" + e.currentToken.endLine + "," + e.currentToken.endColumn); } catch ( IOException e ) { System.out.println( "IOException occurred: "+e );