Skip to content

Commit

Permalink
Permit using string macro with "qualified" name
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalVerb committed Sep 27, 2016
1 parent 26d6c20 commit c6ac5bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
17 changes: 17 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c6ac5bb

Please sign in to comment.