changeset 607:c5ad80f869da

improve theming indentation
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 07 Dec 2015 15:08:42 -0700
parents bd7a26d52737
children d2e0855b3105
files core/src/luan/impl/ThemeParser.java
diffstat 1 files changed, 28 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
diff -r bd7a26d52737 -r c5ad80f869da core/src/luan/impl/ThemeParser.java
--- a/core/src/luan/impl/ThemeParser.java	Fri Dec 04 09:39:23 2015 -0700
+++ b/core/src/luan/impl/ThemeParser.java	Mon Dec 07 15:08:42 2015 -0700
@@ -155,7 +155,7 @@
 		}
 		{
 			addSymbol(MOD);
-			LuanElement se = se(0,"local M = {}");
+			LuanElement se = se(0,"local M = {['-INDENT-']=''}");
 			TableExpr.Field indent = new TableExpr.Field(new ConstExpr(null,INDENT),new ConstExpr(null,""));
 			TableExpr tableExpr = new TableExpr( se, new TableExpr.Field[]{indent}, ExpList.emptyExpList );
 			SetStmt setStmt = new SetStmt( new SetLocalVar(stackIndex(MOD)), tableExpr );
@@ -202,7 +202,7 @@
 		return rtn;
 	}
 
-	private Stmt parseBody(String tagName,String spaces,boolean afterIndent) throws ParseException {
+	private Stmt parseBody(String tagName,final String spaces,boolean afterIndent) throws ParseException {
 		List<Stmt> stmts = new ArrayList<Stmt>();
 		int stackStart = symbolsSize();
 		int start = parser.currentIndex();
@@ -225,7 +225,7 @@
 		while( !matchEndTag(tagName) ) {
 			if( parser.endOfInput() )
 				throw exception("unclosed block");
-			Stmt block = parseBlock(spaces);
+			Stmt block = parseBlock(spaces,afterIndent);
 			if( block != null ) {
 				addText(start,end,stmts,false);
 				start = parser.currentIndex();
@@ -274,8 +274,12 @@
 
 	private boolean matchEndTag(String tagName) {
 		parser.begin();
+/*
 		if( tagName.startsWith("define:") )
 			EndOfLine();
+*/
+		if( EndOfLine() )
+			InlineSpaces();
 		return parser.match("{/") && parser.match(tagName) && parser.match('}') ? parser.success() : parser.failure();
 	}
 
@@ -297,8 +301,16 @@
 		}
 	}
 
-	private Stmt parseBlock(String spaces) throws ParseException {
+	private Stmt parseBlock(String spaces,boolean afterIndent) throws ParseException {
 		int start = parser.begin();
+		String tagSpaces = null;
+		if( afterIndent ) {
+			tagSpaces = spaces;
+		} else if( EndOfLine() ) {
+			int startSpaces = parser.currentIndex();
+			InlineSpaces();
+			tagSpaces = parser.textFrom(startSpaces);
+		}
 		if( !parser.match("{block:") )
 			return parser.failure(null);
 		String name = parseName();
@@ -306,6 +318,18 @@
 			throw exception("invalid block name");
 		if( !parser.match("}") )
 			return null;
+		if( tagSpaces != null ) {
+			parser.begin();
+			InlineSpaces();
+			if( EndOfLine() ) {
+				int startSpaces = parser.currentIndex();
+				InlineSpaces();
+				String line1Spaces = parser.textFrom(startSpaces);
+				if( line1Spaces.startsWith(tagSpaces) )
+					spaces += line1Spaces.substring(tagSpaces.length());
+			}
+			parser.failure();  // rollback
+		}
 		frame = new Frame(frame);
 		addSymbol(ENV);
 		Stmt block = parseBody("block:"+name,spaces,false);