Skip to content

Commit

Permalink
acceptNull -> acceptUnbound
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelstaldal committed Nov 7, 2006
1 parent 030477e commit f8c6860
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 40 deletions.
2 changes: 2 additions & 0 deletions HISTORY
Expand Up @@ -143,3 +143,5 @@
-----
* isUserInRole function in Servlet extlib.
* nvl() function.
* rename acceptNull to acceptUnbound since LSP now makes difference between
null and unbound.
12 changes: 6 additions & 6 deletions docs/lspuser.html
Expand Up @@ -529,7 +529,7 @@ <h3>Types</h3>
use a Java Number).</p>

<p>It's a runtime error to attempt to reference a non-existing tuple element.
Unless the <code>acceptNull</code> parameter is passed to the compiler,
Unless the <code>acceptUnbound</code> parameter is passed to the compiler,
then an non-existing tuple element will result in a special value convertible to
the empty string, the number 0.0, the boolean value false, the empty list
or the empty tuple. The <code>haselement()</code> function can be used to test if a
Expand Down Expand Up @@ -661,7 +661,7 @@ <h3>Variables</h3>
in the outermost scope.</p>

<p>It's a runtime error to attempt to reference an unbound variable.
Unless the <code>acceptNull</code> parameter is passed to the compiler,
Unless the <code>acceptUnbound</code> parameter is passed to the compiler,
then an unbound variable will result in a special value convertible to
the empty string, the number 0.0, the boolean value false, the empty list
or the empty tuple. The <code>isset()</code> function can be used to test if a
Expand All @@ -686,7 +686,7 @@ <h3>Running LSP compiler from command line</h3>
<p>The LSP compiler is invoked by the application class
<code>nu.staldal.lsp.compiler.LSPCompilerCLI</code>. The syntax is:</p>
<pre>
lspc [-verbose] [-force] [-html] [-acceptNull] [-sourcepath <em>sourcepath</em>] [-d <em>destdir</em>] [-enclose <em>encloseFile</em>] <em>inputFile</em> ...
lspc [-verbose] [-force] [-html] [-acceptUnbound] [-sourcepath <em>sourcepath</em>] [-d <em>destdir</em>] [-enclose <em>encloseFile</em>] <em>inputFile</em> ...
</pre>

<p><em>sourcepath</em> specifies where to look for imported files with
Expand All @@ -702,7 +702,7 @@ <h3>Running LSP compiler from command line</h3>
the default output method for HTML pages will be <code>html</code>,
otherwise it will be <code>xhtml</code>.</p>

<p>If <code>-acceptNull</code> is specified, the LSP page will accept
<p>If <code>-acceptUnbound</code> is specified, the LSP page will accept
non-existing variables and tuple entries without runtime error. This
may make it easier to develop the application, but may make it harder
to debug.</p>
Expand Down Expand Up @@ -737,7 +737,7 @@ <h3>Using LSP compiler from within Apache Ant</h3>
enclose="<em>enclose file</em>"
force="<em>force recompiling of all files</em>"
html="<em>use html as default output method</em>"
acceptNull="<em>allow non-existing variables and tuple entries</em>"&gt;
acceptUnbound="<em>allow non-existing variables and tuple entries</em>"&gt;
&lt;fileset dir="lsp"&gt;
&lt;include name="*.lsp" /&gt;
&lt;/fileset&gt;
Expand All @@ -755,7 +755,7 @@ <h3>Using LSP compiler from within Apache Ant</h3>
the default output method for HTML pages will be <code>html</code>,
otherwise it will be <code>xhtml</code>.</p>

<p>If <code>acceptNull</code> is set, the LSP page will accept
<p>If <code>acceptUnbound</code> is set, the LSP page will accept
non-existing variables and tuple entries without runtime error. This
may make it easier to develop the application, but may make it harder
to debug.</p>
Expand Down
2 changes: 1 addition & 1 deletion sample/friendbook-lsp/build.xml
Expand Up @@ -54,7 +54,7 @@
<target name="lsp">
<lspc sourcepath="templates"
destdir="${output.dir}/WEB-INF/classes"
acceptNull="true">
acceptUnbound="true">
<fileset dir="templates">
<include name="*.lsp" />
</fileset>
Expand Down
27 changes: 19 additions & 8 deletions src/nu/staldal/lsp/compiler/LSPCompiler.java
Expand Up @@ -93,7 +93,7 @@ public class LSPCompiler
private Properties outputProperties;

private boolean html;
private boolean acceptNull;
private boolean acceptUnbound;
private String encloseURL;


Expand All @@ -110,7 +110,7 @@ public LSPCompiler()
resolver = null;
jvmCompiler = new LSPJVMCompiler();
html = false;
acceptNull = false;
acceptUnbound = false;
encloseURL = null;
}

Expand Down Expand Up @@ -141,18 +141,29 @@ public void setHtml(boolean html)


/**
* Set to <code>true</code> to make the compiled page accept
* <code>null</code> values without runtime error.
* @param acceptNull
*
* @param acceptNull
* @deprecated use {@link #setAcceptUnbound(boolean)} instead
*/
public void setAcceptNull(boolean acceptNull)
{
this.acceptNull = acceptNull;
setAcceptUnbound(acceptNull);
}


/**
/**
* Set to <code>true</code> to make the compiled page accept
* unbound values without runtime error.
*
* @param acceptUnbound
*/
public void setAcceptUnbound(boolean acceptUnbound)
{
this.acceptUnbound = acceptUnbound;
}


/**
* Set enclose to use. Set to <code>null</code> to not use any enclose.
*
* @param encloseURL URL to the enclose to use
Expand Down Expand Up @@ -289,7 +300,7 @@ else if (tree.getLocalName().equals("html")
jvmCompiler.compileToByteCode(pageName, compiledTree,
importedFiles, compileDynamic,
extLibsInPage, outputProperties,
out, acceptNull,
out, acceptUnbound,
(encloseURL != null));

outputProperties = null;
Expand Down
27 changes: 19 additions & 8 deletions src/nu/staldal/lsp/compiler/LSPCompilerAntTask.java
Expand Up @@ -64,7 +64,7 @@ public class LSPCompilerAntTask extends Task
private File encloseFile;
private boolean force;
private boolean html;
private boolean acceptNull;
private boolean acceptUnbound;


/**
Expand All @@ -86,7 +86,7 @@ public void init()
encloseFile = null;
force = false;
html = false;
acceptNull= false;
acceptUnbound= false;
}


Expand Down Expand Up @@ -124,14 +124,25 @@ public void setHtml(boolean html)
this.html = html;
}

/**
* Accept <code>null</code> as variable value without runtime exception.
/**
* @param acceptNull
*
* @deprecated use {@link #setAcceptUnbound(boolean)} instead
*/
public void setAcceptNull(boolean acceptNull)
{
setAcceptUnbound(acceptNull);
}

/**
* Accept unbound variables and tuple values value without
* runtime exception.
*
* @param acceptNull
* @param acceptUnbound
*/
public void setAcceptNull(boolean acceptNull)
public void setAcceptUnbound(boolean acceptUnbound)
{
this.acceptNull = acceptNull;
this.acceptUnbound = acceptUnbound;
}

/**
Expand Down Expand Up @@ -187,7 +198,7 @@ public void execute() throws BuildException
throw new BuildException("Must have a destdir attribute");

compiler.setHtml(html);
compiler.setAcceptNull(acceptNull);
compiler.setAcceptUnbound(acceptUnbound);

compiler.setTargetDir(destdir);

Expand Down
14 changes: 9 additions & 5 deletions src/nu/staldal/lsp/compiler/LSPCompilerCLI.java
Expand Up @@ -66,7 +66,7 @@ public static void main(String[] args)
boolean verbose = false;
boolean force = false;
boolean html = false;
boolean acceptNull = false;
boolean acceptUnbound = false;

String sourcePathSpec = null;
File targetDir = null;
Expand All @@ -92,10 +92,14 @@ else if (args[i].equals("-html"))
{
html = true;
}
else if (args[i].equals("-acceptNull"))
else if (args[i].equals("-acceptUnbound"))
{
acceptNull = true;
acceptUnbound = true;
}
else if (args[i].equals("-acceptNull")) // deprecated
{
acceptUnbound = true;
}
else if (args[i].equals("-sourcepath"))
{
i++;
Expand Down Expand Up @@ -131,7 +135,7 @@ else if (args[i].equals("-enclose"))

LSPCompilerHelper compiler = new LSPCompilerHelper();
compiler.setHtml(html);
compiler.setAcceptNull(acceptNull);
compiler.setAcceptUnbound(acceptUnbound);

if (sourcePathSpec != null)
{
Expand Down Expand Up @@ -168,7 +172,7 @@ else if (args[i].equals("-enclose"))
private static void syntaxError()
{
System.err.println("LSP compiler version " + LSPPage.LSP_VERSION_NAME);
System.err.println("Syntax: lspc [-verbose] [-force] [-html] [-acceptNull] [-sourcepath sourcepath] [-d destpath] [-enclose encloseFile] inputFile ...");
System.err.println("Syntax: lspc [-verbose] [-force] [-html] [-acceptUnbound] [-sourcepath sourcepath] [-d destpath] [-enclose encloseFile] inputFile ...");
}

}
19 changes: 15 additions & 4 deletions src/nu/staldal/lsp/compiler/LSPCompilerHelper.java
Expand Up @@ -475,13 +475,24 @@ public void setHtml(boolean html)
}

/**
* Set to <code>true</code> to make the compiled page accept
* <code>null</code> values without runtime error.
*
* @param acceptNull
*
* @deprecated use {@link #setAcceptUnbound(boolean)} instead
*/
public void setAcceptNull(boolean acceptNull)
{
compiler.setAcceptNull(acceptNull);
setAcceptUnbound(acceptNull);
}


/**
* Set to <code>true</code> to make the compiled page accept
* unbound values without runtime error.
*
* @param acceptUnbound
*/
public void setAcceptUnbound(boolean acceptUnbound)
{
compiler.setAcceptUnbound(acceptUnbound);
}
}
16 changes: 8 additions & 8 deletions src/nu/staldal/lsp/compiler/LSPJVMCompiler.java
Expand Up @@ -77,7 +77,7 @@ class LSPJVMCompiler implements Constants
private static final int PARAM_sax = 4;
private static final int PARAM_attrs = 5;

private boolean acceptNull;
private boolean acceptUnbound;

private String className = null;
private ClassGen classGen = null;
Expand Down Expand Up @@ -111,10 +111,10 @@ private String getFileName(String path)
void compileToByteCode(String pageName, LSPNode theTree,
HashMap<String,String> importedFiles, boolean compileDynamic,
HashMap<String,String> extLibsInPage, Properties outputProperties,
OutputStream out, boolean acceptNull, boolean hasEnclose)
OutputStream out, boolean acceptUnbound, boolean hasEnclose)
throws IOException, SAXException
{
this.acceptNull = acceptNull;
this.acceptUnbound = acceptUnbound;

splitNumber = 0;

Expand Down Expand Up @@ -1305,7 +1305,7 @@ private void compileExprAsBooleanValue(LSPExpr expr,
{
instrList.append(instrFactory.createInvoke(
LSPPageBase.class.getName(),
acceptNull ? "convertToBooleanAcceptNull" : "convertToBoolean",
acceptUnbound ? "convertToBooleanAcceptNull" : "convertToBoolean",
Type.BOOLEAN,
new Type[] { Type.OBJECT },
INVOKESTATIC));
Expand Down Expand Up @@ -1439,7 +1439,7 @@ private Class compileSubExpr(VariableReference expr,
// Object o = env.lookup(varName);
instrList.append(instrFactory.createInvoke(
LSPPageBase.class.getName(),
acceptNull ? "getVariableValueAcceptNull" : "getVariableValue",
acceptUnbound ? "getVariableValueAcceptNull" : "getVariableValue",
Type.OBJECT,
new Type[] { Type.getType(Environment.class), Type.STRING },
INVOKESTATIC));
Expand Down Expand Up @@ -2000,7 +2000,7 @@ else if (expr.getName().equals("boolean"))
{
instrList.append(instrFactory.createInvoke(
LSPPageBase.class.getName(),
acceptNull ? "convertToBooleanAcceptNull" : "convertToBoolean",
acceptUnbound ? "convertToBooleanAcceptNull" : "convertToBoolean",
Type.BOOLEAN,
new Type[] { Type.OBJECT },
INVOKESTATIC));
Expand Down Expand Up @@ -2349,7 +2349,7 @@ private Class compileSubExpr(TupleExpr expr,

instrList.append(instrFactory.createInvoke(
LSPPageBase.class.getName(),
acceptNull ? "getElementFromTupleAcceptNull" : "getElementFromTuple",
acceptUnbound ? "getElementFromTupleAcceptNull" : "getElementFromTuple",
Type.OBJECT,
new Type[] { Type.getType(Map.class), Type.STRING },
INVOKESTATIC));
Expand Down Expand Up @@ -2441,7 +2441,7 @@ private void compileSubExprAsBooleanValue(LSPExpr expr,
{
instrList.append(instrFactory.createInvoke(
LSPPageBase.class.getName(),
acceptNull ? "convertToBooleanAcceptNull" : "convertToBoolean",
acceptUnbound ? "convertToBooleanAcceptNull" : "convertToBoolean",
Type.BOOLEAN,
new Type[] { Type.OBJECT },
INVOKESTATIC));
Expand Down

0 comments on commit f8c6860

Please sign in to comment.