Skip to content

Commit 6e09c0c

Browse files
committed
Permit using string macro with "qualified" name
Close JuliaLang#6970. Close JuliaLang#14208.
1 parent fe85d33 commit 6e09c0c

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/julia-parser.scm

+8-6
Original file line numberDiff line numberDiff line change
@@ -1067,13 +1067,14 @@
10671067
(take-token s)
10681068
(loop (list* 'curly ex (parse-arglist s #\} ))))
10691069
((#\" #\`)
1070-
(if (and (symbol? ex) (not (operator? ex))
1070+
(if (and (or (symbol? ex) (valid-modref? ex))
1071+
(not (operator? ex))
10711072
(not (ts:space? s)))
10721073
;; custom string and command literals; x"s" => @x_str "s"
10731074
(let* ((macstr (begin (take-token s)
10741075
(parse-raw-literal s t)))
10751076
(nxt (peek-token s))
1076-
(macname (symbol (string #\@ ex (macsuffix t)))))
1077+
(macname (macroify-name ex (macsuffix t))))
10771078
(if (and (symbol? nxt) (not (operator? nxt))
10781079
(not (ts:space? s)))
10791080
;; string literal suffix, "s"x
@@ -2060,10 +2061,11 @@
20602061
(or (symbol? (cadr e))
20612062
(valid-modref? (cadr e)))))
20622063

2063-
(define (macroify-name e)
2064-
(cond ((symbol? e) (symbol (string #\@ e)))
2065-
((valid-modref? e) `(|.| ,(cadr e)
2066-
(quote ,(macroify-name (cadr (caddr e))))))
2064+
(define (macroify-name e . suffixes)
2065+
(cond ((symbol? e) (symbol (apply string #\@ e suffixes)))
2066+
((valid-modref? e)
2067+
`(|.| ,(cadr e)
2068+
(quote ,(apply macroify-name (cadr (caddr e)) suffixes))))
20672069
(else (error (string "invalid macro use \"@(" (deparse e) ")\"" )))))
20682070

20692071
(define (simple-string-literal? e) (string? e))

test/parse.jl

+17
Original file line numberDiff line numberDiff line change
@@ -818,3 +818,20 @@ type Type
818818
end
819819
end
820820
@test method_exists(Mod18756.Type, ())
821+
822+
# Check qualified string macros
823+
Base.r"regex" == r"regex"
824+
825+
module QualifiedStringMacro
826+
module SubModule
827+
macro x_str(x)
828+
1
829+
end
830+
macro y_cmd(x)
831+
2
832+
end
833+
end
834+
end
835+
836+
@test QualifiedStringMacro.SubModule.x"" === 1
837+
@test QualifiedStringMacro.SubModule.y`` === 2

0 commit comments

Comments
 (0)