From 79ce2f8786449d854eff06becb382eeffd6aa713 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 10 Jan 2014 20:19:24 -0500 Subject: [PATCH] parse chains of binary ~ as a macro call to `@~`. closes #4882 --- NEWS.md | 10 +++++++--- src/julia-parser.scm | 14 +++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1597361af736f..9ecd5567e6fcb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,8 +9,6 @@ New language features * Tuples (of integers, symbols, or bools) can now be used as type parameters ([#5164]). - * `import module: name1, name2, ...` ([#5214]). - * Default "inner" constructors now accept any arguments. Constructors that look like `MyType(a, b) = new(a, b)` can and should be removed ([#4026]). @@ -21,6 +19,9 @@ New language features * When reloading code, types whose definitions have not changed can be ignored in some cases. + * Binary `~` now parses as a vararg macro call to `@~`. + For example `x~y~z` => `@~ x y z` ([#4882]). + New library functions --------------------- @@ -110,7 +111,6 @@ Deprecated or removed [#4042]: https://github.com/JuliaLang/julia/issues/4042 [#5164]: https://github.com/JuliaLang/julia/issues/5164 -[#5214]: https://github.com/JuliaLang/julia/issues/5214 [#4026]: https://github.com/JuliaLang/julia/issues/4026 [#4799]: https://github.com/JuliaLang/julia/issues/4799 [#4862]: https://github.com/JuliaLang/julia/issues/4862 @@ -139,6 +139,7 @@ Deprecated or removed [#987]: https://github.com/JuliaLang/julia/issues/987 [#2345]: https://github.com/JuliaLang/julia/issues/2345 [#5330]: https://github.com/JuliaLang/julia/issues/5330 +[#4882]: https://github.com/JuliaLang/julia/issues/4882 Julia v0.2.0 Release Notes ========================== @@ -190,6 +191,8 @@ New language features * Methods can be added to functions in other modules using dot syntax, as in `Foo.bar(x) = 0`. + * `import module: name1, name2, ...` ([#5214]). + * A semicolon is now allowed after an `import` or `using` statement ([#4130]). * In an interactive session (REPL), you can use `;cmd` to run `cmd` via an interactive @@ -512,6 +515,7 @@ Too numerous to mention. [#4235]: https://github.com/JuliaLang/julia/issues/4235 [#4284]: https://github.com/JuliaLang/julia/issues/4284 [#4412]: https://github.com/JuliaLang/julia/issues/4412 +[#5214]: https://github.com/JuliaLang/julia/issues/5214 [packages chapter]: http://docs.julialang.org/en/latest/manual/packages/ [sorting functions]: http://docs.julialang.org/en/latest/stdlib/sort/ diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 338414196c3f3..b9cc3010c01ba 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -445,9 +445,9 @@ ; parse right-to-left binary operator ; produces structures like (= a (= b (= c d))) (define (parse-RtoL s down ops) - (let ((ex (down s)) - (t (peek-token s)) - (spc (ts:space? s))) + (let loop ((ex (down s)) + (t (peek-token s)) + (spc (ts:space? s))) (if (not (memq t ops)) ex (begin (take-token s) @@ -457,6 +457,14 @@ ex) ((syntactic-op? t) (list t ex (parse-RtoL s down ops))) + ((eq? t '~) + (let ((args (parse-chain s down '~))) + (if (memq (peek-token s) ops) + `(macrocall @~ ,ex ,@(butlast args) + ,(loop (last args) + (peek-token s) + (ts:space? s))) + `(macrocall @~ ,ex ,@args)))) (else (list 'call t ex (parse-RtoL s down ops))))))))