Mercurial > hg > tema
changeset 33:b637a4491862
Function data separator could be omitted if the data is empty.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Sat, 17 Oct 2009 03:39:07 +0400 |
parents | bdd1c8d6b560 |
children | 7129dfb130e1 |
files | src/kryshen/tema/FunctionDataParser.java src/kryshen/tema/TemplateParser.java |
diffstat | 2 files changed, 22 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/kryshen/tema/FunctionDataParser.java Fri Sep 25 02:37:16 2009 +0400 +++ b/src/kryshen/tema/FunctionDataParser.java Sat Oct 17 03:39:07 2009 +0400 @@ -73,20 +73,17 @@ if (!available) throw new TemplateException ("Unexpected end of instruction data.", in); - + + if (fd == DataFormat.EMPTY) { + available = false; + lastReturnCode = 0; + return 0; + } + DataFormat fd = skip ? this.fd.noInvoke() : this.fd; TemplateParser.Result r; - -// if (fd.subfunction && argument) { -// // Allow subfunction to pass a list of arguments -// StringWriter sw = new StringWriter(); -// tp.parse(in, sw, fd); -// sw.close(); -// in = new TemplateReader(new StringReader(sw.toString()), in); -// this.fd = DataFormat.VERBATIM; -// r = parseData(out, true, false); -// } else + if (fd.subfunction) { r = tp.parse(in, out, fd); } else if (argument) {
--- a/src/kryshen/tema/TemplateParser.java Fri Sep 25 02:37:16 2009 +0400 +++ b/src/kryshen/tema/TemplateParser.java Sat Oct 17 03:39:07 2009 +0400 @@ -54,13 +54,17 @@ * Specifies how to parse function arguments and data. */ static enum DataFormat { + EMPTY(false, false), INVOKE(true, false), VERBATIM(false, false), NOINVOKE(false, false), SUBFUNCTION(true, true), SUBFUNCTION_NOINVOKE(false, true); - + + /** Recursively invoke nested functions. */ public final boolean invoke; + + /** Treat the data as another function call. */ public final boolean subfunction; DataFormat(boolean invoke, boolean subfunction) { @@ -69,7 +73,7 @@ } /** - * Returns no-call equivalent to this format. + * Returns no-recursive-invoke equivalent to this format. */ public DataFormat noInvoke() { if (this == INVOKE) @@ -288,7 +292,7 @@ readLoop: while (true) { int c = in.read(); - + for (int i = 0; i < chars.length; i++) { if (c == chars[i]) continue readLoop; @@ -337,8 +341,13 @@ while (true) { if (termBracket >= 0 && matchInput(in, BRACKET_CLOSE[termBracket])) { - throw new TemplateException( - "Unexpected end of instruction", in); + +// throw new TemplateException( +// "Unexpected end of instruction", in); + + return invoke( + fd.invoke ? sb.toString() : "true", + DataFormat.EMPTY, in, out); } int c = in.read();