[Laszlo-checkins] r13188 - in openlaszlo/trunk/WEB-INF/lps/server: sc/src/org/openlaszlo/sc sc/src/org/openlaszlo/sc/parser src/org/openlaszlo/compiler src/org/openlaszlo/sc
dda@openlaszlo.org
dda at openlaszlo.org
Thu Mar 5 12:04:48 PST 2009
Author: dda
Date: 2009-03-05 12:04:44 -0800 (Thu, 05 Mar 2009)
New Revision: 13188
Added:
openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/Token.java
Modified:
openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt
openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/ParseException.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationError.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Main.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
Log:
Change 20090303-dda-0 by dda at lester-2.local on 2009-03-03 09:29:19 PST
in /Users/dda/laszlo/src/svn/openlaszlo/trunk-b
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: Capture filename information in parser errors (with addendum 1)
New Features:
Bugs Fixed: LPP-7839: Compiler does not show file name containing the parsing error
Technical Reviewer: ptw (pending)
QA Reviewer: (pending)
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
Addendum 1 - changed NodeModel.java and CompilationError.java:
the original changeset caused most errors to no longer show the line numbers.
That was because a workaround the insert the line number was removed because it was no longer needed,
at least for the original test case. This addendum leaves the workaround removed, but file/line information
is now correctly copied from a ParseException to a CompilationError. In NodeModel, we catch
compilation errors for dependencies so they can be displayed normally instead of receiving a stack trace.
WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/Token.java
WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt
WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/ParseException.java
WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
This introduce of a better way to track filenames in the parser.
Javacc does not have a direct way to track filename information for use in error messages, etc.
Since it already keeps line/column information in tokens, it seems sensible to keep that information there, too.
These changes overrides the standard Javacc Token.java with our own version that contains the filename,
and a way to set it from the Parser. It removes the knowledge of the current filename from the
TokenManager.
A ParseException, which only has access to the token, not the tokenmanager, is now equipped to tag
an error message to include the file name.
WEB-INF/lps/server/src/org/openlaszlo/sc/CompilationError.java
When wrapping a ParseException in a CompilationError, correctly copy line number/file name from
one to another.
WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
When parsing a dependency expression, add the current filename location information.
For compilation errors that happen during creation of dependencies, add the error to the environment,
rather than let a stack trace appear.
WEB-INF/lps/server/src/org/openlaszlo/compiler/Main.java
WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
Added a 'dumpSourceInput' which is turned on when using -SS that dumps that exact input source
that the script compiler sees into <name>-src-<count>.txt
Tests:
Test case from JIRA now produces a message (not with a stack trace) that includes the filename, and
correct line and column numbers. Works with lzc and in server.
<canvas>
<class name="test" width="1 0"/>
</canvas>
LPP-7839.lzx:2:36: Syntax error: the token "0" was not expected at this position.
Test case with a compilation error not in a dependency also (still) gives a correct error message.
canvas>
<class name="test" width="1"/>
<script>
var z = 422 9;
</script>
</canvas>
LPP-7839b.lzx:4:19: Syntax error: the token "9" was not expected at this position.
Usual regression tests: (smokecheck,weather,lzpix on all platforms).
Modified: openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt 2009-03-05 19:12:49 UTC (rev 13187)
+++ openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/Parser.jjt 2009-03-05 20:04:44 UTC (rev 13188)
@@ -41,7 +41,7 @@
Token t = getToken(1);
if (t!= null) {
SimpleNode sn = (SimpleNode) n;
- sn.setBeginLocation(token_source.pathname,
+ sn.setBeginLocation(t.pathname,
t.beginLine, t.beginColumn);
// See tokenmanager.html in the javacc documentation.
if (t.specialToken != null) {
@@ -97,7 +97,6 @@
TOKEN_MGR_DECLS :
{
- public String pathname;
int beginLine;
}
@@ -111,7 +110,7 @@
<FILENAME> SKIP: {
< (~["\n","\r"])* >
- {pathname = image.toString();} : DEFAULT
+ {Token.setCurrentPathname(image.toString());} : DEFAULT
}
<LINE_NUMBER> SKIP: {
Modified: openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/ParseException.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/ParseException.java 2009-03-05 19:12:49 UTC (rev 13187)
+++ openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/ParseException.java 2009-03-05 20:04:44 UTC (rev 13188)
@@ -8,7 +8,7 @@
* ****************************************************************************/
/* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2007 Laszlo Systems, Inc. All Rights Reserved. *
+* Copyright 2001-2009 Laszlo Systems, Inc. All Rights Reserved. *
* Use is subject to license terms. *
* J_LZ_COPYRIGHT_END *********************************************************/
@@ -120,16 +120,14 @@
}
}
- String pathname = null;
-
public String getPathname() {
- return pathname;
+ if (currentToken.next != null) {
+ return currentToken.next.pathname;
+ } else {
+ return null;
+ }
}
- public void initPathname(String pathname) {
- this.pathname = pathname;
- }
-
/**
* This method has the standard behavior when this object has been
* created using the standard constructors. Otherwise, it uses
@@ -143,12 +141,24 @@
public String getMessage() {
return getMessage(true);
}
-
+
+ /**
+ * returns message fragment ' at file XXX, line YYY, column ZZZ'
+ */
+ private String fileLineMessage(Token token) {
+ String retval = " at ";
+ if (token.pathname != null) {
+ retval += "file " + token.pathname + ", ";
+ }
+ retval += "line " + token.beginLine + ", column " + token.beginColumn;
+ return retval;
+ }
+
public String getMessage(boolean includeSourceLocation) {
if (!specialConstructor) {
String retval = super.getMessage();
if (currentToken != null && includeSourceLocation) {
- retval += " at line " + currentToken.beginLine + ", column " + currentToken.beginColumn;
+ retval += fileLineMessage(currentToken);
}
return retval;
}
@@ -202,7 +212,7 @@
}
String retval = "Syntax error: " + msg;
if (currentToken.next != null && includeSourceLocation) {
- retval += " at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
+ retval += fileLineMessage(currentToken.next);
}
retval += ".";
if (expectedCount == 1) {
Added: openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/Token.java
Property changes on: openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/Token.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationError.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationError.java 2009-03-05 19:12:49 UTC (rev 13187)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationError.java 2009-03-05 20:04:44 UTC (rev 13188)
@@ -67,13 +67,13 @@
* @param cause the chained cause of the error
*/
public CompilationError(Element element, Throwable cause) {
- this(getCauseMessage(cause));
+ this(cause);
initElement(element, cause);
}
public CompilationError(Element element, String attribute,
Throwable cause) {
- this(getCauseMessage(cause));
+ this(cause);
initElement(element, attribute, cause);
}
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Main.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Main.java 2009-03-05 19:12:49 UTC (rev 13187)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Main.java 2009-03-05 20:04:44 UTC (rev 13188)
@@ -321,6 +321,7 @@
}
compiler.setProperty(org.openlaszlo.sc.Compiler.DUMP_AST_INPUT, sourceNameNoExt + "-astin-*.txt");
compiler.setProperty(org.openlaszlo.sc.Compiler.DUMP_AST_OUTPUT, sourceNameNoExt + "-astout-*.txt");
+ compiler.setProperty(org.openlaszlo.sc.Compiler.DUMP_SRC_INPUT, sourceNameNoExt + "-src-*.txt");
compiler.setProperty(org.openlaszlo.sc.Compiler.DUMP_LINE_ANNOTATIONS, sourceNameNoExt + "-lineann-*.txt");
}
status += compile(compiler, logger, sourceName, intermediateName, outFileName, outDir);
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java 2009-03-05 19:12:49 UTC (rev 13187)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java 2009-03-05 20:04:44 UTC (rev 13188)
@@ -21,6 +21,7 @@
import org.openlaszlo.sc.Function;
import org.openlaszlo.sc.Method;
import org.openlaszlo.sc.ScriptCompiler;
+import org.openlaszlo.sc.CompilerException;
import org.openlaszlo.sc.CompilerImplementationError;
import org.openlaszlo.server.*;
import org.openlaszlo.utils.ChainedException;
@@ -354,7 +355,12 @@
return null;
}
String pragmas = "";
- String body = "return (" + getCompiler().dependenciesForExpression(value) + ")";
+ String body = "";
+ try {
+ body = "return (" + getCompiler().dependenciesForExpression(srcloc + value) + ")";
+ } catch (CompilerException e) {
+ env.warn(e, source);
+ }
Function dependencies;
if (canHaveMethods) {
// TODO: [2008-07-21 ptw] (LPP-5813) This should really be
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java 2009-03-05 19:12:49 UTC (rev 13187)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java 2009-03-05 20:04:44 UTC (rev 13188)
@@ -344,6 +344,11 @@
}
cg.setOptions(options);
cg.setOriginalSource(source);
+ String srcDumpFile = (String)options.get(DUMP_SRC_INPUT);
+ if (srcDumpFile != null) {
+ String newname = emitFile(srcDumpFile, source);
+ System.err.println("Created " + newname);
+ }
profiler.enter("parse");
source = cg.preProcess(source);
@@ -471,6 +476,7 @@
public static String DUMP_AST_INPUT = "dumpASTInput";
public static String DUMP_AST_OUTPUT = "dumpASTOutput";
public static String DUMP_LINE_ANNOTATIONS = "dumpLineAnnotations";
+ public static String DUMP_SRC_INPUT = "dumpSourceInput";
public static String DISABLE_CONSTANT_POOL = "disableConstantPool";
public static String DISABLE_TRACK_LINES = "disableTrackLines";
public static String DISABLE_PUBLIC_FOR_DEBUG = "disablePublicForDebug";
@@ -544,16 +550,7 @@
org.openlaszlo.sc.parser.Parser p =
new org.openlaszlo.sc.parser.Parser(new StringReader(str));
assert "Program".equals(type);
- try {
- return p.Program();
- } catch (ParseException pe) {
- // NOTE: [2007-03-27 ptw]
- // The parser tracks #file declarations, but does not pass the
- // file to the exception constructor, so we fix that up here.
- // (This is really a limitation of javacc.)
- pe.initPathname(p.token_source.pathname);
- throw pe;
- }
+ return p.Program();
}
public SimpleNode parse0(String str) {
More information about the Laszlo-checkins
mailing list