[pkg-d-commits] [ldc] 35/95: Extend config file grammar by backtick-enclosed strings

Matthias Klumpp mak at moszumanska.debian.org
Thu Jul 13 20:53:58 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v1.3.0-beta1
in repository ldc.

commit 55e912641d8d83a48930b853b21a602ad03d8a91
Author: Martin <noone at nowhere.com>
Date:   Sun Feb 26 13:46:29 2017 +0100

    Extend config file grammar by backtick-enclosed strings
---
 driver/config.d | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/driver/config.d b/driver/config.d
index 22c4ae0..42ccad7 100644
--- a/driver/config.d
+++ b/driver/config.d
@@ -138,9 +138,11 @@ array   =   "[" , ows ,
                 { string , ows , "," , ows } ,
             "]" ;
 group   =   "{" , ows , { setting , ows } , "}" ;
-string  =   quotstr, { ows , quotstr } ;
+string  =   ( quotstr , { ows , quotstr } ) |
+            ( btstr , { ows, btstr } ) ;
 quotstr =   '"' , { ? any char but '"', '\n' and '\r' ? | escseq } , '"' ;
 escseq  =   "\" , ["\" | '"' | "r" | "n" | "t" ] ;
+btstr   =   '`' , { ? any char but '`' ? } , '`' ;
 alpha   =   ? any char between "a" and "z" included
                     or between "A" and "Z" included ? ;
 digit   =   ? any char between "0" and "9" included ? ;
@@ -214,7 +216,7 @@ struct Parser
     Ahead ahead;
     Ahead* aheadp;
 
-    this(string content, string filename = "")
+    this(string content, string filename = null)
     {
         this.filename = filename;
         this.content = content;
@@ -363,6 +365,29 @@ struct Parser
             return Token.str;
         }
 
+        if (lastChar == '`')
+        {
+            string str;
+            while (lastChar == '`')
+            {
+                while (1)
+                {
+                    lastChar = getChar();
+                    if (lastChar == '`') break;
+                    if (lastChar == '\0')
+                    {
+                        error("Unexpected end of file in string literal");
+                    }
+                    str ~= lastChar;
+                }
+                lastChar = getChar();
+                while (isspace(lastChar)) lastChar = getChar();
+            }
+
+            outStr = str;
+            return Token.str;
+        }
+
         outStr = [lastChar];
         lastChar = getChar();
         return Token.unknown;
@@ -505,6 +530,8 @@ unittest
                 "abc\r\ndef\t\"quoted/\\123\"");
     testScalar(`"concatenated" " multiline"
                 " strings"`, "concatenated multiline strings");
+    testScalar("`abc\n\\ //comment \"`",
+                "abc\n\\ //comment \"");
 }
 
 unittest

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list