[valadoc] Parser: Add support for <<BR>>



commit 30ee5b0b29e7e61bfcbc2a24630c0fa0c18fea3d
Author: Didier 'Ptitjes <ptitjes at free dot fr>
Date:   Sat Oct 31 03:37:33 2009 +0100

    Parser: Add support for <<BR>>

 .../documentation/documentationparser.vala         |   15 ++++++++++-----
 src/libvaladoc/documentation/wikiscanner.vala      |   16 +++++++++++++++-
 src/libvaladoc/parser/tokentype.vala               |    2 ++
 3 files changed, 27 insertions(+), 6 deletions(-)
---
diff --git a/src/libvaladoc/documentation/documentationparser.vala b/src/libvaladoc/documentation/documentationparser.vala
index 28e0fcc..c5edb74 100644
--- a/src/libvaladoc/documentation/documentationparser.vala
+++ b/src/libvaladoc/documentation/documentationparser.vala
@@ -208,6 +208,14 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
 		}
 	}
 
+	private void add_content_string (string str) {
+		var text = peek () as Text;
+		if (text == null) {
+			push (text = _factory.create_text ());
+		}
+		text.content += str;
+	}
+
 	private void init_rules () {
 		// Inline rules
 
@@ -215,11 +223,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
 		run.set_name ("Run");
 
 		TokenType.Action add_text = (token) => {
-			var text = peek () as Text;
-			if (text == null) {
-				push (text = _factory.create_text ());
-			}
-			text.content += token.to_string ();
+			add_content_string (token.to_string ());
 		};
 
 		TokenType word = TokenType.any_word ().action (add_text);
@@ -233,6 +237,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
 					Rule.many ({
 						Rule.one_of ({
 							word,
+							TokenType.BREAK.action ((token) => { add_content_string ("\n"); }),
 							TokenType.LESS_THAN.action (add_text),
 							TokenType.GREATER_THAN.action (add_text),
 							TokenType.ALIGN_RIGHT.action (add_text),
diff --git a/src/libvaladoc/documentation/wikiscanner.vala b/src/libvaladoc/documentation/wikiscanner.vala
index 47640a7..c2ae177 100644
--- a/src/libvaladoc/documentation/wikiscanner.vala
+++ b/src/libvaladoc/documentation/wikiscanner.vala
@@ -226,7 +226,9 @@ public class Valadoc.WikiScanner : Object, Scanner {
 				break;
 
 			case '<':
-				emit_token (TokenType.LESS_THAN);
+				if (!look_for ("<<BR>>", TokenType.BREAK)) {
+					emit_token (TokenType.LESS_THAN);
+				}
 				break;
 
 			case '>':
@@ -383,4 +385,16 @@ public class Valadoc.WikiScanner : Object, Scanner {
 			emit_token (one);
 		}
 	}
+
+	private bool look_for (string str, TokenType type) throws ParserError {
+		for (int i = 1; i < str.length; i++) {
+			if (get_next_char (i) != str[i]) {
+				return false;
+			}
+		}
+
+		emit_token (type);
+		_skip = (int) (str.length - 1);
+		return true;
+	}
 }
diff --git a/src/libvaladoc/parser/tokentype.vala b/src/libvaladoc/parser/tokentype.vala
index 598aac3..86f87dc 100644
--- a/src/libvaladoc/parser/tokentype.vala
+++ b/src/libvaladoc/parser/tokentype.vala
@@ -29,6 +29,7 @@ public class Valadoc.TokenType : Object {
 	public static TokenType ANY_NUMBER;
 	public static TokenType EOF;
 	public static TokenType EOL;
+	public static TokenType BREAK;
  	public static TokenType AROBASE;
 	public static TokenType SPACE;
 	public static TokenType TAB;
@@ -68,6 +69,7 @@ public class Valadoc.TokenType : Object {
 			ANY_NUMBER = new TokenType.basic ("<any-number>");
 			EOF = new TokenType.basic ("\0", "<end-of-file>");
 			EOL = new TokenType.basic ("\n", "<end-of-line>");
+			BREAK = new TokenType.basic ("<<BR>>");
 			AROBASE = new TokenType.basic ("@");
 			SPACE = new TokenType.basic (" ", "<space>");
 			TAB = new TokenType.basic ("\t", "<tab>");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]