]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Parser: Add support for <<BR>>
authorDidier 'Ptitjes <ptitjes at free dot fr>
Sat, 31 Oct 2009 02:37:33 +0000 (03:37 +0100)
committerFlorian Brosch <flo.brosch@gmail.com>
Sat, 31 Oct 2009 02:37:33 +0000 (03:37 +0100)
src/libvaladoc/documentation/documentationparser.vala
src/libvaladoc/documentation/wikiscanner.vala
src/libvaladoc/parser/tokentype.vala

index 28e0fcc3814e419cb44c61f2422c6cacee8cbe52..c5edb741e8e91961ada28a89d40e0f796178743d 100644 (file)
@@ -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),
index 47640a7aac5e1a9ded020a519363427ca86c5881..c2ae1772e4854a4dc3248b2e08a270da12262f7e 100644 (file)
@@ -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;
+       }
 }
index 598aac3e849382247e8387538f656aee02295101..86f87dc4f24c30a311522c5c5ba1f84c6dc9a956 100644 (file)
@@ -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>");