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 diff
1.1 --- a/src/kryshen/tema/FunctionDataParser.java Fri Sep 25 02:37:16 2009 +0400 1.2 +++ b/src/kryshen/tema/FunctionDataParser.java Sat Oct 17 03:39:07 2009 +0400 1.3 @@ -73,20 +73,17 @@ 1.4 if (!available) 1.5 throw new TemplateException 1.6 ("Unexpected end of instruction data.", in); 1.7 - 1.8 + 1.9 + if (fd == DataFormat.EMPTY) { 1.10 + available = false; 1.11 + lastReturnCode = 0; 1.12 + return 0; 1.13 + } 1.14 + 1.15 DataFormat fd = skip ? this.fd.noInvoke() : this.fd; 1.16 1.17 TemplateParser.Result r; 1.18 - 1.19 -// if (fd.subfunction && argument) { 1.20 -// // Allow subfunction to pass a list of arguments 1.21 -// StringWriter sw = new StringWriter(); 1.22 -// tp.parse(in, sw, fd); 1.23 -// sw.close(); 1.24 -// in = new TemplateReader(new StringReader(sw.toString()), in); 1.25 -// this.fd = DataFormat.VERBATIM; 1.26 -// r = parseData(out, true, false); 1.27 -// } else 1.28 + 1.29 if (fd.subfunction) { 1.30 r = tp.parse(in, out, fd); 1.31 } else if (argument) {
2.1 --- a/src/kryshen/tema/TemplateParser.java Fri Sep 25 02:37:16 2009 +0400 2.2 +++ b/src/kryshen/tema/TemplateParser.java Sat Oct 17 03:39:07 2009 +0400 2.3 @@ -54,13 +54,17 @@ 2.4 * Specifies how to parse function arguments and data. 2.5 */ 2.6 static enum DataFormat { 2.7 + EMPTY(false, false), 2.8 INVOKE(true, false), 2.9 VERBATIM(false, false), 2.10 NOINVOKE(false, false), 2.11 SUBFUNCTION(true, true), 2.12 SUBFUNCTION_NOINVOKE(false, true); 2.13 - 2.14 + 2.15 + /** Recursively invoke nested functions. */ 2.16 public final boolean invoke; 2.17 + 2.18 + /** Treat the data as another function call. */ 2.19 public final boolean subfunction; 2.20 2.21 DataFormat(boolean invoke, boolean subfunction) { 2.22 @@ -69,7 +73,7 @@ 2.23 } 2.24 2.25 /** 2.26 - * Returns no-call equivalent to this format. 2.27 + * Returns no-recursive-invoke equivalent to this format. 2.28 */ 2.29 public DataFormat noInvoke() { 2.30 if (this == INVOKE) 2.31 @@ -288,7 +292,7 @@ 2.32 readLoop: 2.33 while (true) { 2.34 int c = in.read(); 2.35 - 2.36 + 2.37 for (int i = 0; i < chars.length; i++) { 2.38 if (c == chars[i]) 2.39 continue readLoop; 2.40 @@ -337,8 +341,13 @@ 2.41 while (true) { 2.42 if (termBracket >= 0 && 2.43 matchInput(in, BRACKET_CLOSE[termBracket])) { 2.44 - throw new TemplateException( 2.45 - "Unexpected end of instruction", in); 2.46 + 2.47 +// throw new TemplateException( 2.48 +// "Unexpected end of instruction", in); 2.49 + 2.50 + return invoke( 2.51 + fd.invoke ? sb.toString() : "true", 2.52 + DataFormat.EMPTY, in, out); 2.53 } 2.54 2.55 int c = in.read();