[valadoc] libvaladoc: Avoid some lambdas by re-using methods



commit a41d55896eedf20fe0debbdc7558b74dae9b9368
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Sep 6 18:01:22 2017 +0200

    libvaladoc: Avoid some lambdas by re-using methods

 .../documentation/documentationparser.vala         |   22 ++++++++++----------
 .../importer/valadocdocumentationimporter.vala     |   14 ++++++++----
 2 files changed, 20 insertions(+), 16 deletions(-)
---
diff --git a/src/libvaladoc/documentation/documentationparser.vala 
b/src/libvaladoc/documentation/documentationparser.vala
index fe6d685..6e1535f 100644
--- a/src/libvaladoc/documentation/documentationparser.vala
+++ b/src/libvaladoc/documentation/documentationparser.vala
@@ -293,7 +293,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
                text.content += str;
        }
 
-       private void add_content_space () {
+       private void add_content_space (Token token) throws ParserError {
                // avoid double spaces
                var head = peek ();
                Text text_node = null;
@@ -314,17 +314,17 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
                }
        }
 
+       private void add_text (Token token) throws ParserError {
+               add_content_string (token.to_string ());
+       }
+
        private void init_valadoc_rules () {
                // Inline rules
 
                StubRule run = new StubRule ();
                run.set_name ("Run");
 
-               TokenType.Action add_text = (token) => {
-                       add_content_string (token.to_string ());
-               };
-
-               TokenType space = TokenType.SPACE.action ((token) => { add_content_space (); });
+               TokenType space = TokenType.SPACE.action (add_content_space);
                TokenType word = TokenType.any_word ().action (add_text);
 
                Rule optional_invisible_spaces =
@@ -335,7 +335,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
                Rule optional_spaces = 
                        Rule.option ({
                                Rule.many ({
-                                       TokenType.SPACE.action ((token) => { add_content_space (); })
+                                       TokenType.SPACE.action (add_content_space)
                                })
                        });
 
@@ -379,7 +379,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
 
                multiline_run = Rule.many ({
                                run_with_spaces,
-                               TokenType.EOL.action (() => { add_content_space (); })
+                               TokenType.EOL.action (add_content_space)
                        })
                        .set_name ("MultiLineRun");
 
@@ -551,7 +551,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
                                }),
                                Rule.many ({
                                        run,
-                                       TokenType.EOL.action (() => { add_content_space (); })
+                                       TokenType.EOL.action (add_content_space)
                                })
                        })
                        .set_name ("Paragraph")
@@ -572,7 +572,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
                                optional_invisible_spaces,
                                Rule.many ({
                                        Rule.seq({optional_invisible_spaces, run}),
-                                       TokenType.EOL.action (() => { add_content_space (); })
+                                       TokenType.EOL.action (add_content_space)
                                })
                        })
                        .set_name ("Warning")
@@ -594,7 +594,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
                                optional_invisible_spaces,
                                Rule.many ({
                                        Rule.seq({optional_invisible_spaces, run}),
-                                       TokenType.EOL.action (() => { add_content_space (); })
+                                       TokenType.EOL.action (add_content_space)
                                })
                        })
                        .set_name ("Note")
diff --git a/src/libvaladoc/importer/valadocdocumentationimporter.vala 
b/src/libvaladoc/importer/valadocdocumentationimporter.vala
index b74b430..ec96f72 100644
--- a/src/libvaladoc/importer/valadocdocumentationimporter.vala
+++ b/src/libvaladoc/importer/valadocdocumentationimporter.vala
@@ -83,11 +83,11 @@ public class Valadoc.Importer.ValadocDocumentationImporter : DocumentationImport
                                TokenType.VALADOC_COMMENT_START.action ((token) => { _comment_location = 
token.end; }),
                                Rule.many ({
                                        Rule.one_of ({
-                                               TokenType.ANY_WORD.action ((token) => { _comment.append 
(token.to_string ()); }),
-                                               TokenType.VALADOC_COMMENT_START.action ((token) => { 
_comment.append (token.to_string ()); }),
-                                               TokenType.VALADOC_SPACE.action ((token) => { _comment.append 
(token.to_string ()); }),
-                                               TokenType.VALADOC_TAB.action ((token) => { _comment.append 
(token.to_string ()); }),
-                                               TokenType.VALADOC_EOL.action ((token) => { _comment.append 
(token.to_string ()); })
+                                               TokenType.ANY_WORD.action (add_comment),
+                                               TokenType.VALADOC_COMMENT_START.action (add_comment),
+                                               TokenType.VALADOC_SPACE.action (add_comment),
+                                               TokenType.VALADOC_TAB.action (add_comment),
+                                               TokenType.VALADOC_EOL.action (add_comment)
                                        })
                                }),
                                TokenType.VALADOC_COMMENT_END,
@@ -117,6 +117,10 @@ public class Valadoc.Importer.ValadocDocumentationImporter : DocumentationImport
                _parser.set_root_rule (file);
        }
 
+       private void add_comment (Token token) throws ParserError {
+               _comment.append (token.to_string ());
+       }
+
        private enum InsertionMode {
                APPEND,
                PREPEND,


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