annotate core/src/luan/modules/parsers/Theme.java @ 688:f99f51bc5bea

fix up-values
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 18 Apr 2016 15:46:05 -0600
parents fc08c3b42010
children 6a489a6b3cbc
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 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 parser.anyChar();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91 end = parser.currentIndex();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93 addText(start,end,stmts);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94 return stmts.toString();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97 private boolean matchEndTag(String tagName) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
98 parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99 /*
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100 if( tagName.startsWith("define:") )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101 EndOfLine();
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 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
104 }
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 private void addText(int start,int end,StringBuilder stmts) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107 if( start < end ) {
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
108 stmts.append( "%>" ).append( parser.text.substring(start,end) ).append( "<%" );
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109 }
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 String parseBlock() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
113 int start = parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114 if( !parser.match("{block:") )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116 String name = parseName();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117 if( name==null ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118 parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
119 throw exception("invalid block name");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
120 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121 if( !parser.match('}') )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123 String block = parseBody("block:"+name);
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
124 String rtn = " env."+ name + "( env, function(env) " + block + "end); ";
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125 // 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
126 return parser.success(rtn);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129 private String parseSimpleTag() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130 int start = parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131 if( !parser.match('{') )
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 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136 if( !parser.match('}') )
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 // rtn = "<% env." + name + (attrs.isEmpty() ? "()" : table(attrs)) + " %>";
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
139 String rtn = " env." + name + "(env); ";
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 return parser.success(rtn);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143 private void InlineSpaces() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144 while( parser.anyOf(" \t") );
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 boolean BlankLine() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148 parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149 while( parser.anyOf(" \t") );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150 return EndOfLine() ? parser.success() : parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
151 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153 private boolean EndOfLine() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
154 return parser.match( "\r\n" ) || parser.match( '\r' ) || parser.match( '\n' );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
155 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
156
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157 private String parseName() throws ParseException {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158 int start = parser.begin();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159 if( parser.match('/') ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160 parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161 throw exception("bad closing tag");
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 if( parser.match("define:") ) {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164 parser.failure();
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
165 throw exception("unexpected definition");
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
166 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167 if( !FirstNameChar() )
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
168 return parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
169 while( NameChar() );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170 String match = parser.textFrom(start);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
171 return parser.success(match);
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
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174 private boolean FirstNameChar() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175 return parser.inCharRange('a', 'z') || parser.inCharRange('A', 'Z') || parser.match('_');
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
178 private boolean NameChar() {
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
179 return FirstNameChar() || parser.inCharRange('0', '9');
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180 }
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
182 }