Skip to content

Commit

Permalink
fix #29968, qualify macro names in parsing int literals and cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Nov 28, 2018
1 parent f24711c commit 02007bd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
17 changes: 9 additions & 8 deletions NEWS.md
Expand Up @@ -6,18 +6,14 @@ New language features

* An *exception stack* is maintained on each task to make exception handling more robust and enable root cause analysis using `catch_stack` ([#28878]).


Language changes
----------------

* the constructor `BigFloat(::BigFloat)` now respects the global precision setting and always
returns a `BigFloat` with precision equal to `precision(BigFloat)` ([#29127]). The optional
`precision` argument to override the global setting is now a keyword instead of positional
argument ([#29157]).
* Parser inputs ending with a comma are now consistently treated as incomplete.
Previously they were sometimes parsed as tuples, depending on whitespace ([#28506]).
* `Regex` and `TimeZone` now behave like scalars when used in broadcasting ([#29913], [#30159]).
* `Char` now behaves like a read-only 0-dimensional array ([#29819]).
* Big integer literals and command syntax (backticks) are now parsed with the name of
the macro (`@int128_str`, `@uint128_str`, `@big_str`, `@cmd`) qualified to refer
to the `Core` module ([#29968]).

New library functions
---------------------
Expand All @@ -26,7 +22,6 @@ New library functions
* `isnothing(::Any)` function, to check whether something is a `Nothing`, returns a `Bool` ([#29679]).
* `getpid(::Process)` method ([#24064]).


Standard library changes
------------------------

Expand All @@ -38,6 +33,12 @@ Standard library changes
* `edit` can now be called on a module to edit the file that defines it ([#29636]).
* `diff` now supports arrays of arbitrary dimensionality and can operate over any dimension ([#29827]).
* `sprandn` now supports result types like `ComplexF64` or `Float32` ([#30083]).
* The constructor `BigFloat(::BigFloat)` now respects the global precision setting and always
returns a `BigFloat` with precision equal to `precision(BigFloat)` ([#29127]). The optional
`precision` argument to override the global setting is now a keyword instead of positional
argument ([#29157]).
* `Regex` and `TimeZone` now behave like scalars when used in broadcasting ([#29913], [#30159]).
* `Char` now behaves like a read-only 0-dimensional array ([#29819]).

Compiler/Runtime improvements
-----------------------------
Expand Down
8 changes: 8 additions & 0 deletions base/boot.jl
Expand Up @@ -457,6 +457,14 @@ end
atdoc = (source, mod, str, expr) -> Expr(:escape, expr)
atdoc!(λ) = global atdoc = λ

# macros for big integer syntax
macro int128_str end
macro uint128_str end
macro big_str end

# macro for command syntax
macro cmd end


# simple stand-alone print definitions for debugging
abstract type IO end
Expand Down
2 changes: 1 addition & 1 deletion base/sysimg.jl
Expand Up @@ -72,7 +72,7 @@ convert(::Type{T}, arg) where {T<:VecElement} = T(arg)
convert(::Type{T}, arg::T) where {T<:VecElement} = arg

# init core docsystem
import Core: @doc, @__doc__, WrappedException
import Core: @doc, @__doc__, WrappedException, @int128_str, @uint128_str, @big_str, @cmd
if isdefined(Core, :Compiler)
import Core.Compiler.CoreDocs
Core.atdoc!(CoreDocs.docm)
Expand Down
22 changes: 11 additions & 11 deletions src/julia-parser.scm
Expand Up @@ -408,10 +408,10 @@
((eq? pred char-bin?) (fix-uint-neg neg (sized-uint-literal n s 1)))
(is-float32-literal (numchk n s) (float n))
(n (if (and (integer? n) (> n 9223372036854775807))
`(macrocall @int128_str (null) ,s)
`(macrocall (core @int128_str) (null) ,s)
n))
((within-int128? s) `(macrocall @int128_str (null) ,s))
(else `(macrocall @big_str (null) ,s))))))
((within-int128? s) `(macrocall (core @int128_str) (null) ,s))
(else `(macrocall (core @big_str) (null) ,s))))))

(define (fix-uint-neg neg n)
(if neg
Expand All @@ -427,7 +427,7 @@
((<= l 16) (numchk n s) (uint16 n))
((<= l 32) (numchk n s) (uint32 n))
((<= l 64) (numchk n s) (uint64 n))
((<= l 128) `(macrocall @uint128_str (null) ,s))
((<= l 128) `(macrocall (core @uint128_str) (null) ,s))
(else (error "Hex or binary literal too large for UInt128")))))

(define (sized-uint-oct-literal n s)
Expand All @@ -440,7 +440,7 @@
(else (uint64 n)))
(begin (if (equal? s "0o") (numchk n s))
(if (oct-within-uint128? s)
`(macrocall @uint128_str (null) ,s)
`(macrocall (core @uint128_str) (null) ,s)
(error "Octal literal too large for UInt128"))))))

(define (strip-leading-0s s)
Expand Down Expand Up @@ -471,9 +471,9 @@
(>= 0 (compare-num-strings s "170141183460469231731687303715884105727"))))

(define (large-number? t)
(and (pair? t)
(eq? (car t) 'macrocall)
(memq (cadr t) '(@int128_str @uint128_str @big_str))))
(and (pair? t) (eq? (car t) 'macrocall)
(pair? (cadr t)) (eq? (car (cadr t)) 'core)
(memq (cadadr t) '(@int128_str @uint128_str @big_str))))

;; skip to end of comment, starting at #: either #...<eol> or #= .... =#.
(define (skip-comment port)
Expand Down Expand Up @@ -996,10 +996,10 @@
(if (eq? op '-)
(if (large-number? num)
(if (eqv? (cadddr num) "-170141183460469231731687303715884105728")
`(macrocall @big_str (null) "170141183460469231731687303715884105728")
`(macrocall (core @big_str) (null) "170141183460469231731687303715884105728")
`(,(car num) ,(cadr num) ,(caddr num) ,(string.tail (cadddr num) 1)))
(if (= num -9223372036854775808)
`(macrocall @int128_str (null) "9223372036854775808")
`(macrocall (core @int128_str) (null) "9223372036854775808")
(- num)))
num))

Expand Down Expand Up @@ -2340,7 +2340,7 @@
;; command syntax
((eqv? t #\`)
(take-token s)
`(macrocall @cmd ,(line-number-node s) ,(parse-raw-literal s #\`)))
`(macrocall (core @cmd) ,(line-number-node s) ,(parse-raw-literal s #\`)))

((or (string? t) (number? t) (large-number? t)) (take-token s))

Expand Down
2 changes: 1 addition & 1 deletion test/syntax.jl
Expand Up @@ -759,7 +759,7 @@ end
@test :(x`s\`"\x\$\\`) == :(@x_cmd "s`\"\\x\\\$\\")

# Check multiline command literals
@test :(@cmd "multiline\ncommand\n") == :```
@test Expr(:macrocall, GlobalRef(Core, Symbol("@cmd")), LineNumberNode(@__LINE__, Symbol(@__FILE__)), "multiline\ncommand\n") == :```
multiline
command
```
Expand Down

0 comments on commit 02007bd

Please sign in to comment.