Mercurial Hosting > luan
changeset 600:b926e53910dd
change theming indentation
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 28 Sep 2015 00:32:27 -0600 |
parents | 50540f0813e2 |
children | d36027b41570 |
files | core/src/luan/impl/ThemeParser.java |
diffstat | 1 files changed, 13 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
diff -r 50540f0813e2 -r b926e53910dd core/src/luan/impl/ThemeParser.java --- a/core/src/luan/impl/ThemeParser.java Wed Sep 16 20:55:49 2015 -0600 +++ b/core/src/luan/impl/ThemeParser.java Mon Sep 28 00:32:27 2015 -0600 @@ -176,33 +176,33 @@ } private Stmt parseDef() throws ParseException { - int start = parser.begin(); + int start = parser.currentIndex(); if( !parser.match("{define:") ) - return parser.failure(null); + return null; String name = parseName(); if( name==null ) - throw exception("invalid block name"); + throw parser.exception("invalid block name"); + if( !parser.match("}") ) + throw parser.exception("unclosed define tag"); String spaces = ""; - if( BlankLine() ) { - while( BlankLine() ); + boolean indent = BlankLine(); + if( indent ) { int startSpaces = parser.currentIndex(); InlineSpaces(); spaces = parser.textFrom(startSpaces); } - if( !parser.match("}") ) - return null; Expr table = new GetLocalVar(null,stackIndex(MOD)); Settable fnName = new SetTableEntry(se(start),table,new ConstExpr(null,name)); frame = new Frame(frame); addSymbol(ENV); - Stmt block = parseBody("define:"+name,spaces,EndOfLine()); + Stmt block = parseBody("define:"+name,spaces,indent); FnDef fnDef = newFnDef(start,block); frame = frame.parent; Stmt rtn = new SetStmt(fnName,fnDef); - return parser.success(rtn); + return rtn; } - private Stmt parseBody(String tagName,String spaces,boolean initIndent) throws ParseException { + private Stmt parseBody(String tagName,String spaces,boolean afterIndent) throws ParseException { List<Stmt> stmts = new ArrayList<Stmt>(); int stackStart = symbolsSize(); int start = parser.currentIndex(); @@ -221,12 +221,6 @@ SetStmt setStmt = new SetStmt( new SetLocalVar(stackIndex(INDENT)), exp ); stmts.add(setStmt); } - boolean afterIndent = false; - if( initIndent && parser.match(spaces) ) { - addText(start,start,stmts,true); - start = parser.currentIndex(); - afterIndent = true; - } int end = start; while( !matchEndTag(tagName) ) { if( parser.endOfInput() ) @@ -280,15 +274,9 @@ private boolean matchEndTag(String tagName) { parser.begin(); - if( !parser.match('{') ) - return parser.failure(); - Spaces(); - if( !(parser.match('/') && parser.match(tagName)) ) - return parser.failure(); - Spaces(); - if( !parser.match('}') ) - return parser.failure(); - return parser.success(); + if( tagName.startsWith("define:") ) + EndOfLine(); + return parser.match("{/") && parser.match(tagName) && parser.match('}') ? parser.success() : parser.failure(); } private void addText(int start,int end,List<Stmt> stmts,boolean indent) { @@ -341,7 +329,6 @@ String name = parseName(); if( name==null ) return parser.failure(null); - Spaces(); if( !parser.match("}") ) return parser.failure(null); // rtn = "<% env." + name + (attrs.isEmpty() ? "()" : table(attrs)) + " %>"; @@ -369,18 +356,10 @@ return parser.success(rtn); } - private void Spaces() { - while( parser.anyOf(" \t\r\n") ); - } - private void InlineSpaces() { while( parser.anyOf(" \t") ); } - private void BlankLines() { - while( BlankLine() ); - } - private boolean BlankLine() { parser.begin(); while( parser.anyOf(" \t") );