Skip to content

Commit

Permalink
remove _mstr macros. closes #10228
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Feb 19, 2015
1 parent f65528c commit 7bd9769
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 41 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Language changes
* `round` rounds to the nearest integer using the default rounding mode,
which is ties to even by default ([#8750]).

* A custom triple-quoted string like `x"""..."""` no longer invokes an `x_mstr`
macro. Instead, the string is first unindented and then `x_str` is invoked,
as if the string had been single-quoted ([#10228]).

Compiler improvements
---------------------

Expand Down Expand Up @@ -1222,3 +1226,4 @@ Too numerous to mention.
[#10075]: https://github.com/JuliaLang/julia/issues/10075
[#10117]: https://github.com/JuliaLang/julia/issues/10117
[#10180]: https://github.com/JuliaLang/julia/issues/10180
[#10228]: https://github.com/JuliaLang/julia/issues/10228
2 changes: 0 additions & 2 deletions base/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ keywords[:...] = doc"""
RegexMatch("angry,\nBad world")
""" r""

@doc (@doc r"") @r_mstr

@doc doc"""
push!(collection, items...) → collection
Expand Down
22 changes: 6 additions & 16 deletions base/docs.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Docs

import Base.Markdown: @doc_str, @doc_mstr, MD
import Base.Markdown: @doc_str, MD

export doc, @doc

Expand Down Expand Up @@ -149,9 +149,9 @@ namify(sy::Symbol) = sy

function mdify(ex)
if isa(ex, AbstractString)
:(@doc_str $(esc(ex)))
:(@doc_str $ex)
elseif isexpr(ex, :macrocall) && namify(ex) == symbol("@mstr")
:(@doc_mstr $(esc(ex.args[2])))
:(@doc_str $(Expr(:triple_quoted_string, ex.args[2])))
else
esc(ex)
end
Expand Down Expand Up @@ -258,7 +258,7 @@ end

import Base: print, writemime

export HTML, @html_str, @html_mstr
export HTML, @html_str

export HTML, Text

Expand Down Expand Up @@ -289,15 +289,10 @@ writemime(io::IO, ::MIME"text/html", h::HTML) = print(io, h.content)
writemime(io::IO, ::MIME"text/html", h::HTML{Function}) = h.content(io)

@doc "Create an `HTML` object from a literal string." ->
macro html_str (s)
macro html_str(s)
:(HTML($s))
end

@doc (@doc html"") ->
macro html_mstr (s)
:(HTML($(Base.triplequoted(s))))
end

function catdoc(xs::HTML...)
HTML() do io
for x in xs
Expand All @@ -306,7 +301,7 @@ function catdoc(xs::HTML...)
end
end

export Text, @text_str, @text_mstr
export Text, @text_str

# @doc """
# `Text(s)`: Create an object that renders `s` as plain text.
Expand All @@ -332,11 +327,6 @@ macro text_str (s)
:(Text($s))
end

@doc (@doc text"") ->
macro text_mstr (s)
:(Text($(Base.triplequoted(s))))
end

function catdoc(xs::Text...)
Text() do io
for x in xs
Expand Down
6 changes: 1 addition & 5 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1383,12 +1383,9 @@ export
@__FILE__,
@b_str,
@r_str,
@r_mstr,
@v_str,
@text_str,
@text_mstr,
@html_str,
@html_mstr,
@int128_str,
@uint128_str,
@bigint_str,
Expand Down Expand Up @@ -1447,5 +1444,4 @@ export
@inline,
@noinline,
@doc,
@doc_str,
@doc_mstr
@doc_str
12 changes: 1 addition & 11 deletions base/markdown/Markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include("render/html.jl")

include("render/terminal/render.jl")

export readme, license, @md_str, @md_mstr, @doc_str, @doc_mstr
export readme, license, @md_str, @doc_str

parse(markdown::String; flavor = julia) = parse(IOBuffer(markdown), flavor = flavor)
parse_file(file::String; flavor = julia) = parse(readall(file), flavor = flavor)
Expand Down Expand Up @@ -49,20 +49,10 @@ macro md_str(s, t...)
mdexpr(s, t...)
end

macro md_mstr(s, t...)
s = Base.triplequoted(s)
mdexpr(s, t...)
end

macro doc_str(s, t...)
docexpr(s, t...)
end

macro doc_mstr(s, t...)
s = Base.triplequoted(s)
docexpr(s, t...)
end

function Base.display(d::Base.REPL.REPLDisplay, md::Vector{MD})
for md in md
display(d, md)
Expand Down
1 change: 0 additions & 1 deletion base/regex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ function compile(regex::Regex)
end

macro r_str(pattern, flags...) Regex(pattern, flags...) end
macro r_mstr(pattern, flags...) Regex(pattern, flags...) end

copy(r::Regex) = r

Expand Down
9 changes: 4 additions & 5 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -998,15 +998,14 @@
(let* ((str (begin (take-token s)
(parse-string-literal s #t)))
(nxt (peek-token s))
(suffix (if (triplequote-string-literal? str) '_mstr '_str))
(macname (symbol (string #\@ ex suffix)))
(macstr (cdr str)))
(macname (symbol (string #\@ ex '_str)))
(macstr (if (triplequote-string-literal? str) str (cadr str))))
(if (and (symbol? nxt) (not (operator? nxt))
(not (ts:space? s)))
;; string literal suffix, "s"x
(loop `(macrocall ,macname ,@macstr
(loop `(macrocall ,macname ,macstr
,(string (take-token s))))
(loop `(macrocall ,macname ,@macstr))))
(loop `(macrocall ,macname ,macstr))))
ex))
(else ex))))))

Expand Down
7 changes: 6 additions & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3303,7 +3303,12 @@ So far only the second case can actually occur.
((eq? (car e) 'macrocall)
;; expand macro
(let ((form
(apply invoke-julia-macro (cadr e) (cddr e))))
(if (and (length> e 2) (pair? (caddr e)) (eq? (caaddr e) 'triple_quoted_string))
;; for a custom triple-quoted string literal, first invoke mstr
;; to handle unindenting
(invoke-julia-macro (cadr e)
(julia-expand-macros `(macrocall @mstr ,(cadr (caddr e)))))
(apply invoke-julia-macro (cadr e) (cddr e)))))
(if (not form)
(error (string "macro \"" (cadr e) "\" not defined")))
(if (and (pair? form) (eq? (car form) 'error))
Expand Down

1 comment on commit 7bd9769

@MichaelHatherly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JeffBezanson, tripled-quoted string macros seem to be discarding all but the first argument now:

julia> macro test_str(args...)
           dump(args)
       end

julia> test"a"b
(ASCIIString,ASCIIString) ("a","b")

julia> test"""a"""b
(ASCIIString,) ("a",)

Not sure if this is the intended behavior?

Please sign in to comment.