Skip to content

Commit

Permalink
WIP: Parser support for var"" interpolation
Browse files Browse the repository at this point in the history
This is required so that interpolation of variables with var"" is
allowed in contexts where a plain symbol (or $-interpolation) is
expected.

TODO: Still doesn't work within export / import and possibly other
contexts.
  • Loading branch information
c42f committed Jul 3, 2019
1 parent b84a992 commit 1fcfcc0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,17 @@
(define syntactic-op? (Set syntactic-operators))
(define syntactic-unary-op? (Set syntactic-unary-operators))

(define (var-interpolation? ex)
(and (pair? ex)
(eq? 'macrocall (car ex))
(pair? (cdr ex))
(eq? '|@var_str| (cadr ex))))

(define (symbol-or-interpolate? ex)
(or (symbol? ex)
(and (pair? ex)
(eq? '$ (car ex)))))
(eq? '$ (car ex)))
(var-interpolation? ex)))

(define (is-word-operator? op)
(every identifier-start-char? (string->list (symbol->string op))))
Expand Down Expand Up @@ -1486,6 +1493,7 @@
(var? (and (not nl) (or (and (symbol? var) (not (eq? var 'false))
(not (eq? var 'true)))
(and (length= var 2) (eq? (car var) '$))
(var-interpolation? var)
(error (string "invalid syntax \"catch " (deparse var) "\"")))))
(catch-block (if (eq? (require-token s) 'finally)
`(block ,(line-number-node s))
Expand Down
10 changes: 10 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1861,3 +1861,13 @@ let
a32325(x) = a32325()
end
@test a32325(0) === a32325()

# PR #32408
@test Meta.parse("try catch var\"##\" ; end") ==
Expr(:try,
Expr(:block),
Expr(:macrocall, Symbol("@var_str"), LineNumberNode(1,:none), "##"),
Expr(:block, LineNumberNode(1,:none)))
@test Meta.parse("function var\"#\" end") ==
Expr(:function,
Expr(:macrocall, Symbol("@var_str"), LineNumberNode(1,:none), "#"))

0 comments on commit 1fcfcc0

Please sign in to comment.