annotate src/luan/modules/parsers/Theme.java @ 775:1a68fc55a80c

simplify dir structure
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 Aug 2016 14:36:40 -0600
parents core/src/luan/modules/parsers/Theme.java@c5f5b655f1f7
children 88b5b81cad4a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package luan.modules.parsers;
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 import luan.LuanException;
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 public final class Theme {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 public static String toLuan(String source) throws LuanException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 try {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 return new Theme(source).parse();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 } catch(ParseException e) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 throw new LuanException(e.getMessage());
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 private final Parser parser;
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 private Theme(String source) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 this.parser = new Parser(source);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 private ParseException exception(String msg) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 // parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 return new ParseException(parser,msg);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 private String parse() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 StringBuilder stmts = new StringBuilder();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 stmts.append( "local M = {}; " );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 while( !parser.endOfInput() ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 String def = parseDef();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 if( def != null ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 stmts.append(def);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 } else {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 // parser.anyChar();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 stmts.append(parsePadding());
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 stmts.append( "\n\nreturn M\n" );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 return stmts.toString();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 private String parsePadding() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 int start = parser.currentIndex();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 if( parser.match("--") ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 while( parser.noneOf("\r\n") );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 } else if( !parser.anyOf(" \t\r\n") ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 throw exception("unexpected text");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 return parser.textFrom(start);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 private String parseDef() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 int start = parser.begin();
769
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
55 if( !parser.match('{') )
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
56 return parser.failure(null);
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
57 spaces();
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
58 if( !parser.match("define:") )
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 String name = parseName();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 if( name==null )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 throw exception("invalid block name");
769
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
63 spaces();
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 if( !parser.match('}') )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 throw exception("unclosed define tag");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 String block = parseBody("define:"+name);
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
67 String rtn = "function M." + name + "(env) " + block + " end; ";
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 return parser.success(rtn);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 private String parseBody(String tagName) throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 StringBuilder stmts = new StringBuilder();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73 int start = parser.currentIndex();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74 int end = start;
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75 while( !matchEndTag(tagName) ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76 if( parser.endOfInput() ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
77 parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78 throw exception("unclosed block");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
80 String block = parseBlock();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
81 if( block != null ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82 addText(start,end,stmts);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83 start = parser.currentIndex();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84 stmts.append(block);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85 continue;
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87 String simpleTag = parseSimpleTag();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
88 if( simpleTag != null ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
89 addText(start,end,stmts);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 start = parser.currentIndex();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91 stmts.append(simpleTag);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92 continue;
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93 }
690
6a489a6b3cbc fix theme security
Franklin Schmidt <fschmidt@gmail.com>
parents: 688
diff changeset
94 if( parser.match("<%") ) {
6a489a6b3cbc fix theme security
Franklin Schmidt <fschmidt@gmail.com>
parents: 688
diff changeset
95 addText(start,end,stmts);
6a489a6b3cbc fix theme security
Franklin Schmidt <fschmidt@gmail.com>
parents: 688
diff changeset
96 start = parser.currentIndex();
6a489a6b3cbc fix theme security
Franklin Schmidt <fschmidt@gmail.com>
parents: 688
diff changeset
97 stmts.append("%><%='<%'%><%");
6a489a6b3cbc fix theme security
Franklin Schmidt <fschmidt@gmail.com>
parents: 688
diff changeset
98 continue;
6a489a6b3cbc fix theme security
Franklin Schmidt <fschmidt@gmail.com>
parents: 688
diff changeset
99 }
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100 parser.anyChar();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101 end = parser.currentIndex();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
102 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
103 addText(start,end,stmts);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
104 return stmts.toString();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
105 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107 private boolean matchEndTag(String tagName) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108 parser.begin();
769
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
109 if( !parser.match('{') )
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
110 return parser.failure();
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
111 spaces();
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
112 if( !(parser.match('/') && parser.match(tagName)) )
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
113 return parser.failure();
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
114 spaces();
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
115 if( !parser.match('}') )
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
116 return parser.failure();
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
117 return parser.success();
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
119
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
120 private void addText(int start,int end,StringBuilder stmts) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121 if( start < end ) {
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
122 stmts.append( "%>" ).append( parser.text.substring(start,end) ).append( "<%" );
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
124 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126 private String parseBlock() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127 int start = parser.begin();
769
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
128 if( !parser.match('{') )
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
129 return parser.failure(null);
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
130 spaces();
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
131 if( !parser.match("block:") )
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133 String name = parseName();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134 if( name==null ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135 parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136 throw exception("invalid block name");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137 }
769
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
138 spaces();
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139 if( !parser.match('}') )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141 String block = parseBody("block:"+name);
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
142 String rtn = " env."+ name + "( env, function(env) " + block + "end); ";
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143 // String rtn = "<% env." + tag.name + "(" + (tag.attrs.isEmpty() ? "nil" : table(tag.attrs)) + ",env,function(env) %>" + block + "<% end) %>";
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144 return parser.success(rtn);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
145 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147 private String parseSimpleTag() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148 int start = parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149 if( !parser.match('{') )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150 return parser.failure(null);
769
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
151 spaces();
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152 String name = parseName();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153 if( name==null )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
154 return parser.failure(null);
769
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
155 spaces();
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
156 if( !parser.match('}') )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158 // rtn = "<% env." + name + (attrs.isEmpty() ? "()" : table(attrs)) + " %>";
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
159 String rtn = " env." + name + "(env); ";
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160 return parser.success(rtn);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
162
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163 private boolean BlankLine() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164 parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
165 while( parser.anyOf(" \t") );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
166 return EndOfLine() ? parser.success() : parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
168
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
169 private boolean EndOfLine() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170 return parser.match( "\r\n" ) || parser.match( '\r' ) || parser.match( '\n' );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
171 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173 private String parseName() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174 int start = parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175 if( parser.match('/') ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176 parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177 throw exception("bad closing tag");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
178 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
179 if( parser.match("define:") ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180 parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181 throw exception("unexpected definition");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
182 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
183 if( !FirstNameChar() )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
185 while( NameChar() );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
186 String match = parser.textFrom(start);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
187 return parser.success(match);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
188 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
189
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
190 private boolean FirstNameChar() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
191 return parser.inCharRange('a', 'z') || parser.inCharRange('A', 'Z') || parser.match('_');
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
192 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
193
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
194 private boolean NameChar() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195 return FirstNameChar() || parser.inCharRange('0', '9');
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
196 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
197
769
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
198 private void spaces() {
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
199 while( parser.anyOf(" \t") );
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
200 }
c5f5b655f1f7 allow spaces in theme tags
Franklin Schmidt <fschmidt@gmail.com>
parents: 720
diff changeset
201
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
202 }