From c6ac5bb7a1bc54bc6e79f79c535be4f3effbdaa7 Mon Sep 17 00:00:00 2001 From: Fengyang Wang Date: Tue, 27 Sep 2016 05:02:33 +0000 Subject: [PATCH] Permit using string macro with "qualified" name Close #6970. Close #14208. --- src/julia-parser.scm | 14 ++++++++------ test/parse.jl | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 12a7db072f1c78..3e4d0c247cec7a 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -1067,13 +1067,14 @@ (take-token s) (loop (list* 'curly ex (parse-arglist s #\} )))) ((#\" #\`) - (if (and (symbol? ex) (not (operator? ex)) + (if (and (or (symbol? ex) (valid-modref? ex)) + (not (operator? ex)) (not (ts:space? s))) ;; custom string and command literals; x"s" => @x_str "s" (let* ((macstr (begin (take-token s) (parse-raw-literal s t))) (nxt (peek-token s)) - (macname (symbol (string #\@ ex (macsuffix t))))) + (macname (macroify-name ex (macsuffix t)))) (if (and (symbol? nxt) (not (operator? nxt)) (not (ts:space? s))) ;; string literal suffix, "s"x @@ -2060,10 +2061,11 @@ (or (symbol? (cadr e)) (valid-modref? (cadr e))))) -(define (macroify-name e) - (cond ((symbol? e) (symbol (string #\@ e))) - ((valid-modref? e) `(|.| ,(cadr e) - (quote ,(macroify-name (cadr (caddr e)))))) +(define (macroify-name e . suffixes) + (cond ((symbol? e) (symbol (apply string #\@ e suffixes))) + ((valid-modref? e) + `(|.| ,(cadr e) + (quote ,(apply macroify-name (cadr (caddr e)) suffixes)))) (else (error (string "invalid macro use \"@(" (deparse e) ")\"" ))))) (define (simple-string-literal? e) (string? e)) diff --git a/test/parse.jl b/test/parse.jl index 95d3ea33deaf48..997506f1151502 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -807,3 +807,20 @@ end ```.head == :if end + +# Check qualified string macros +Base.r"regex" == r"regex" + +module QualifiedStringMacro +module SubModule +macro x_str(x) + 1 +end +macro y_cmd(x) + 2 +end +end +end + +@test QualifiedStringMacro.SubModule.x"" === 1 +@test QualifiedStringMacro.SubModule.y`` === 2