annotate core/src/luan/modules/parsers/Theme.java @ 687:fc08c3b42010

add theme_to_luan
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 18 Apr 2016 01:08:35 -0600
parents
children f99f51bc5bea
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);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 String rtn = "function M." + name + "(env) " + block + "end; ";
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 stmts.append( "%>" );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 int end = start;
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 while( !matchEndTag(tagName) ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73 if( parser.endOfInput() ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74 parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75 throw exception("unclosed block");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
77 String block = parseBlock();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78 if( block != null ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79 addText(start,end,stmts);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
80 start = parser.currentIndex();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
81 stmts.append(block);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82 continue;
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84 String simpleTag = parseSimpleTag();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85 if( simpleTag != null ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86 addText(start,end,stmts);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87 start = parser.currentIndex();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
88 stmts.append(simpleTag);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
89 continue;
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91 parser.anyChar();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92 end = parser.currentIndex();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94 addText(start,end,stmts);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95 stmts.append( "<% ");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96 return stmts.toString();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97 }
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 private boolean matchEndTag(String tagName) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100 parser.begin();
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 if( tagName.startsWith("define:") )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
103 EndOfLine();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
104 */
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
105 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
106 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108 private void addText(int start,int end,StringBuilder stmts) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109 if( start < end ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
110 stmts.append( parser.text.substring(start,end) );
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 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
113
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114 private String parseBlock() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115 int start = parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116 if( !parser.match("{block:") )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118 String name = parseName();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
119 if( name==null ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
120 parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121 throw exception("invalid block name");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123 if( !parser.match('}') )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
124 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125 String block = parseBody("block:"+name);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126 String rtn = "<% env."+ name + "( env, function(env) " + block + "end) %>";
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127 // 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
128 return parser.success(rtn);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131 private String parseSimpleTag() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132 int start = parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133 if( !parser.match('{') )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135 String name = parseName();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136 if( name==null )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
138 if( !parser.match('}') )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 // rtn = "<% env." + name + (attrs.isEmpty() ? "()" : table(attrs)) + " %>";
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141 String rtn = "<% env." + name + "(env) %>";
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142 return parser.success(rtn);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
145 private void InlineSpaces() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146 while( parser.anyOf(" \t") );
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 }