annotate core/src/luan/modules/parsers/Theme.java @ 720:bdd766df1c17

add json parser
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 30 May 2016 21:27:17 -0600
parents 6a489a6b3cbc
children c5f5b655f1f7
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();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 if( !parser.match("{define:") )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 String name = parseName();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 if( name==null )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 throw exception("invalid block name");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 if( !parser.match('}') )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 throw exception("unclosed define tag");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 String block = parseBody("define:"+name);
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
63 String rtn = "function M." + name + "(env) " + block + " end; ";
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 return parser.success(rtn);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 private String parseBody(String tagName) throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 StringBuilder stmts = new StringBuilder();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69 int start = parser.currentIndex();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 int end = start;
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 while( !matchEndTag(tagName) ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 if( parser.endOfInput() ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73 parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74 throw exception("unclosed block");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76 String block = parseBlock();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
77 if( block != null ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78 addText(start,end,stmts);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79 start = parser.currentIndex();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
80 stmts.append(block);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
81 continue;
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83 String simpleTag = parseSimpleTag();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84 if( simpleTag != null ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85 addText(start,end,stmts);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86 start = parser.currentIndex();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87 stmts.append(simpleTag);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
88 continue;
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
89 }
690
6a489a6b3cbc fix theme security
Franklin Schmidt <fschmidt@gmail.com>
parents: 688
diff changeset
90 if( parser.match("<%") ) {
6a489a6b3cbc fix theme security
Franklin Schmidt <fschmidt@gmail.com>
parents: 688
diff changeset
91 addText(start,end,stmts);
6a489a6b3cbc fix theme security
Franklin Schmidt <fschmidt@gmail.com>
parents: 688
diff changeset
92 start = parser.currentIndex();
6a489a6b3cbc fix theme security
Franklin Schmidt <fschmidt@gmail.com>
parents: 688
diff changeset
93 stmts.append("%><%='<%'%><%");
6a489a6b3cbc fix theme security
Franklin Schmidt <fschmidt@gmail.com>
parents: 688
diff changeset
94 continue;
6a489a6b3cbc fix theme security
Franklin Schmidt <fschmidt@gmail.com>
parents: 688
diff changeset
95 }
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96 parser.anyChar();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97 end = parser.currentIndex();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
98 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99 addText(start,end,stmts);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100 return stmts.toString();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101 }
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 private boolean matchEndTag(String tagName) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
104 parser.begin();
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 if( tagName.startsWith("define:") )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107 EndOfLine();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108 */
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109 return parser.match("{/") && parser.match(tagName) && parser.match('}') ? parser.success() : parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
110 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
111
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
112 private void addText(int start,int end,StringBuilder stmts) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
113 if( start < end ) {
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
114 stmts.append( "%>" ).append( parser.text.substring(start,end) ).append( "<%" );
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118 private String parseBlock() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
119 int start = parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
120 if( !parser.match("{block:") )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122 String name = parseName();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123 if( name==null ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
124 parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125 throw exception("invalid block name");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127 if( !parser.match('}') )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129 String block = parseBody("block:"+name);
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
130 String rtn = " env."+ name + "( env, function(env) " + block + "end); ";
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131 // 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
132 return parser.success(rtn);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135 private String parseSimpleTag() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136 int start = parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137 if( !parser.match('{') )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
138 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139 String name = parseName();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 if( name==null )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142 if( !parser.match('}') )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144 // rtn = "<% env." + name + (attrs.isEmpty() ? "()" : table(attrs)) + " %>";
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
145 String rtn = " env." + name + "(env); ";
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146 return parser.success(rtn);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149 private boolean BlankLine() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150 parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
151 while( parser.anyOf(" \t") );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152 return EndOfLine() ? parser.success() : parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
154
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
155 private boolean EndOfLine() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
156 return parser.match( "\r\n" ) || parser.match( '\r' ) || parser.match( '\n' );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159 private String parseName() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160 int start = parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161 if( parser.match('/') ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
162 parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163 throw exception("bad closing tag");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
165 if( parser.match("define:") ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
166 parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167 throw exception("unexpected definition");
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 if( !FirstNameChar() )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
171 while( NameChar() );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172 String match = parser.textFrom(start);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173 return parser.success(match);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176 private boolean FirstNameChar() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177 return parser.inCharRange('a', 'z') || parser.inCharRange('A', 'Z') || parser.match('_');
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
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180 private boolean NameChar() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181 return FirstNameChar() || parser.inCharRange('0', '9');
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
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184 }