Skip to content

Commit c6ac5bb

Browse files
committed
Permit using string macro with "qualified" name
Close #6970. Close #14208.
1 parent 26d6c20 commit c6ac5bb

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
@@ -807,3 +807,20 @@ end
807807
```.head == :if
808808

809809
end
810+
811+
# Check qualified string macros
812+
Base.r"regex" == r"regex"
813+
814+
module QualifiedStringMacro
815+
module SubModule
816+
macro x_str(x)
817+
1
818+
end
819+
macro y_cmd(x)
820+
2
821+
end
822+
end
823+
end
824+
825+
@test QualifiedStringMacro.SubModule.x"" === 1
826+
@test QualifiedStringMacro.SubModule.y`` === 2

0 commit comments

Comments
 (0)