Mercurial Hosting > luan
comparison core/src/luan/impl/ThemeParser.java @ 607:c5ad80f869da
improve theming indentation
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 07 Dec 2015 15:08:42 -0700 |
parents | b926e53910dd |
children | d2e0855b3105 |
comparison
equal
deleted
inserted
replaced
606:bd7a26d52737 | 607:c5ad80f869da |
---|---|
153 SetStmt setStmt = new SetStmt( new SetLocalVar(stackIndex(IO)), new ExpressionsExpr(requireCall) ); | 153 SetStmt setStmt = new SetStmt( new SetLocalVar(stackIndex(IO)), new ExpressionsExpr(requireCall) ); |
154 stmts.add(setStmt); | 154 stmts.add(setStmt); |
155 } | 155 } |
156 { | 156 { |
157 addSymbol(MOD); | 157 addSymbol(MOD); |
158 LuanElement se = se(0,"local M = {}"); | 158 LuanElement se = se(0,"local M = {['-INDENT-']=''}"); |
159 TableExpr.Field indent = new TableExpr.Field(new ConstExpr(null,INDENT),new ConstExpr(null,"")); | 159 TableExpr.Field indent = new TableExpr.Field(new ConstExpr(null,INDENT),new ConstExpr(null,"")); |
160 TableExpr tableExpr = new TableExpr( se, new TableExpr.Field[]{indent}, ExpList.emptyExpList ); | 160 TableExpr tableExpr = new TableExpr( se, new TableExpr.Field[]{indent}, ExpList.emptyExpList ); |
161 SetStmt setStmt = new SetStmt( new SetLocalVar(stackIndex(MOD)), tableExpr ); | 161 SetStmt setStmt = new SetStmt( new SetLocalVar(stackIndex(MOD)), tableExpr ); |
162 stmts.add(setStmt); | 162 stmts.add(setStmt); |
163 } | 163 } |
200 frame = frame.parent; | 200 frame = frame.parent; |
201 Stmt rtn = new SetStmt(fnName,fnDef); | 201 Stmt rtn = new SetStmt(fnName,fnDef); |
202 return rtn; | 202 return rtn; |
203 } | 203 } |
204 | 204 |
205 private Stmt parseBody(String tagName,String spaces,boolean afterIndent) throws ParseException { | 205 private Stmt parseBody(String tagName,final String spaces,boolean afterIndent) throws ParseException { |
206 List<Stmt> stmts = new ArrayList<Stmt>(); | 206 List<Stmt> stmts = new ArrayList<Stmt>(); |
207 int stackStart = symbolsSize(); | 207 int stackStart = symbolsSize(); |
208 int start = parser.currentIndex(); | 208 int start = parser.currentIndex(); |
209 { | 209 { |
210 addSymbol(INDENT); | 210 addSymbol(INDENT); |
223 } | 223 } |
224 int end = start; | 224 int end = start; |
225 while( !matchEndTag(tagName) ) { | 225 while( !matchEndTag(tagName) ) { |
226 if( parser.endOfInput() ) | 226 if( parser.endOfInput() ) |
227 throw exception("unclosed block"); | 227 throw exception("unclosed block"); |
228 Stmt block = parseBlock(spaces); | 228 Stmt block = parseBlock(spaces,afterIndent); |
229 if( block != null ) { | 229 if( block != null ) { |
230 addText(start,end,stmts,false); | 230 addText(start,end,stmts,false); |
231 start = parser.currentIndex(); | 231 start = parser.currentIndex(); |
232 stmts.add(block); | 232 stmts.add(block); |
233 afterIndent = false; | 233 afterIndent = false; |
272 return block; | 272 return block; |
273 } | 273 } |
274 | 274 |
275 private boolean matchEndTag(String tagName) { | 275 private boolean matchEndTag(String tagName) { |
276 parser.begin(); | 276 parser.begin(); |
277 /* | |
277 if( tagName.startsWith("define:") ) | 278 if( tagName.startsWith("define:") ) |
278 EndOfLine(); | 279 EndOfLine(); |
280 */ | |
281 if( EndOfLine() ) | |
282 InlineSpaces(); | |
279 return parser.match("{/") && parser.match(tagName) && parser.match('}') ? parser.success() : parser.failure(); | 283 return parser.match("{/") && parser.match(tagName) && parser.match('}') ? parser.success() : parser.failure(); |
280 } | 284 } |
281 | 285 |
282 private void addText(int start,int end,List<Stmt> stmts,boolean indent) { | 286 private void addText(int start,int end,List<Stmt> stmts,boolean indent) { |
283 List<Expressions> args = new ArrayList<Expressions>(); | 287 List<Expressions> args = new ArrayList<Expressions>(); |
295 FnCall writeCall = new FnCall( se(start), writeExp, ExpList.build(args) ); | 299 FnCall writeCall = new FnCall( se(start), writeExp, ExpList.build(args) ); |
296 stmts.add( new ExpressionsStmt(writeCall) ); | 300 stmts.add( new ExpressionsStmt(writeCall) ); |
297 } | 301 } |
298 } | 302 } |
299 | 303 |
300 private Stmt parseBlock(String spaces) throws ParseException { | 304 private Stmt parseBlock(String spaces,boolean afterIndent) throws ParseException { |
301 int start = parser.begin(); | 305 int start = parser.begin(); |
306 String tagSpaces = null; | |
307 if( afterIndent ) { | |
308 tagSpaces = spaces; | |
309 } else if( EndOfLine() ) { | |
310 int startSpaces = parser.currentIndex(); | |
311 InlineSpaces(); | |
312 tagSpaces = parser.textFrom(startSpaces); | |
313 } | |
302 if( !parser.match("{block:") ) | 314 if( !parser.match("{block:") ) |
303 return parser.failure(null); | 315 return parser.failure(null); |
304 String name = parseName(); | 316 String name = parseName(); |
305 if( name==null ) | 317 if( name==null ) |
306 throw exception("invalid block name"); | 318 throw exception("invalid block name"); |
307 if( !parser.match("}") ) | 319 if( !parser.match("}") ) |
308 return null; | 320 return null; |
321 if( tagSpaces != null ) { | |
322 parser.begin(); | |
323 InlineSpaces(); | |
324 if( EndOfLine() ) { | |
325 int startSpaces = parser.currentIndex(); | |
326 InlineSpaces(); | |
327 String line1Spaces = parser.textFrom(startSpaces); | |
328 if( line1Spaces.startsWith(tagSpaces) ) | |
329 spaces += line1Spaces.substring(tagSpaces.length()); | |
330 } | |
331 parser.failure(); // rollback | |
332 } | |
309 frame = new Frame(frame); | 333 frame = new Frame(frame); |
310 addSymbol(ENV); | 334 addSymbol(ENV); |
311 Stmt block = parseBody("block:"+name,spaces,false); | 335 Stmt block = parseBody("block:"+name,spaces,false); |
312 FnDef fnDef = newFnDef(start,block); | 336 FnDef fnDef = newFnDef(start,block); |
313 frame = frame.parent; | 337 frame = frame.parent; |