diff --git a/NEWS.md b/NEWS.md index a38239010056e..23695aa7a8dc0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -24,6 +24,14 @@ Language changes This can be changed back to the original color by setting the environment variable `JULIA_INFO_COLOR` to `"blue"`. One way of doing this is by adding `ENV["JULIA_INFO_COLOR"] = :blue` to the `.juliarc.jl` file. For more information regarding customizing colors in the REPL, see this [manual section]( http://docs.julialang.org/en/latest/manual/interacting-with-julia/#customizing-colors). + * Multiline and singleline command macros have been added. A command macro is + like a string macro, but the syntax uses backquotes (\`) + instead of double quotes, and the resulting macro called is suffixed with + `_cmd`. For instance, the syntax q\`xyz\` is equivalent to + `@q_cmd "xyz"`. + * String and command macros can now be qualified with their module. For + instance, `Base.r"x"` is now parsed as `Base.@r_str "x"`. Previously, this + syntax parsed as an implicit multiplication. Breaking changes ---------------- diff --git a/doc/manual/metaprogramming.rst b/doc/manual/metaprogramming.rst index 7c541fb1853b7..05653b6f8b9d0 100644 --- a/doc/manual/metaprogramming.rst +++ b/doc/manual/metaprogramming.rst @@ -864,13 +864,27 @@ majority of use cases, however, regular expressions are not constructed based on run-time data. In this majority of cases, the ability to write regular expressions as compile-time values is invaluable. +Like non-standard string literals, non-standard command literals exist using a +prefixed variant of the command literal syntax. The command literal +``custom`literal``` is parsed as ``@custom_cmd "literal"``. Julia itself does +not contain any non-standard command literals, but packages can make use of +this syntax. Aside from the different syntax and the ``_cmd`` suffix instead of +the ``_str`` suffix, non-standard command literals behave exactly like +non-standard string literals. + +In the event that two modules provide non-standard string or command literals +with the same name, it is possible to qualify the string or command literal +with a module name. For instance, if both ``Foo`` and ``Bar`` provide +non-standard string literal ``@x_str``, then one can write ``Foo.x"literal"`` +or ``Bar.x"literal"`` to disambiguate between the two. + The mechanism for user-defined string literals is deeply, profoundly powerful. Not only are Julia's non-standard literals implemented using it, but also the command literal syntax (```echo "Hello, $person"```) is implemented with the following innocuous-looking macro:: macro cmd(str) - :(cmd_gen($shell_parse(str))) + :(cmd_gen($(shell_parse(str)[1]))) end Of course, a large amount of complexity is hidden in the functions used