Skip to content

Commit 18e5804

Browse files
committed
Working fix, sans JuliaSyntax
1 parent 1de5880 commit 18e5804

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

base/views.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ replace_ref_begin_end!(ex) = replace_ref_begin_end_!(ex, nothing)[1]
1818
# replace_ref_begin_end_!(ex,withex) returns (new ex, whether withex was used)
1919
function replace_ref_begin_end_!(ex, withex)
2020
used_withex = false
21-
if isa(ex,Symbol)
22-
if ex === :begin
21+
if isa(ex,Expr)
22+
if ex.head === :begin
2323
withex === nothing && error("Invalid use of begin")
2424
return withex[1], true
25-
elseif ex === :end
25+
elseif ex.head === :end
2626
withex === nothing && error("Invalid use of end")
2727
return withex[2], true
28-
end
29-
elseif isa(ex,Expr)
30-
if ex.head === :ref
28+
elseif ex.head === :ref
3129
ex.args[1], used_withex = replace_ref_begin_end_!(ex.args[1], withex)
3230
S = isa(ex.args[1],Symbol) ? ex.args[1]::Symbol : gensym(:S) # temp var to cache ex.args[1] if needed
3331
used_S = false # whether we actually need S

src/julia-parser.scm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
(define space-sensitive #f)
183183
; seeing `for` stops parsing macro arguments and makes a generator
184184
(define for-generator #f)
185-
; treat 'end' like a normal symbol instead of a reserved word
185+
; treat begin/end like special symbols instead of reserved words
186186
(define end-symbol #f)
187187
; treat newline like ordinary whitespace instead of as a potential separator
188188
(define whitespace-newline #f)
@@ -1624,7 +1624,7 @@
16241624
(parse-imports s word))
16251625
((do)
16261626
(error "invalid \"do\" syntax"))
1627-
(else (error "unhandled reserved word")))))))
1627+
(else (error (string "unhandled reserved word " word))))))))
16281628

16291629
(define (parse-do s)
16301630
(with-bindings
@@ -2545,6 +2545,10 @@
25452545
(symbol str)))
25462546
((eq? t 'true) '(true))
25472547
((eq? t 'false) '(false))
2548+
;; issue #57269: a[var"begin"] -> 'begin
2549+
;; a[begin] -> '(begin)
2550+
((and end-symbol (eq? t 'begin)) '(begin))
2551+
((and end-symbol (eq? t 'end)) '(end))
25482552
(else t)))
25492553

25502554
;; parens or tuple

src/julia-syntax.scm

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@
113113

114114
;; replace `begin` and `end` for the closest ref expression, so doesn't go inside nested refs
115115
(define (replace-beginend ex a n tuples last)
116-
(cond ((eq? ex 'end) (end-val a n tuples last))
117-
((eq? ex 'begin) (begin-val a n tuples last))
116+
(cond ((equal? ex '(begin)) (begin-val a n tuples last))
117+
((equal? ex '(end)) (end-val a n tuples last))
118118
((or (atom? ex) (quoted? ex)) ex)
119119
((eq? (car ex) 'ref)
120120
;; inside ref only replace within the first argument
@@ -1775,7 +1775,9 @@
17751775
(let ((a (cadr e))
17761776
(idxs (cddr e)))
17771777
(let* ((reuse (and (pair? a)
1778-
(contains (lambda (x) (or (eq? x 'begin) (eq? x 'end)))
1778+
(contains (lambda (x)
1779+
(or (equal? x '(begin))
1780+
(equal? x '(end))))
17791781
idxs)))
17801782
(arr (if reuse (make-ssavalue) a))
17811783
(stmts (if reuse `((= ,arr ,a)) '())))
@@ -2612,8 +2614,9 @@
26122614
(idxs (cddr lhs))
26132615
(rhs (caddr e)))
26142616
(let* ((reuse (and (pair? a)
2615-
(contains (lambda (x) (eq? x 'end))
2616-
idxs)))
2617+
(contains
2618+
(lambda (x) (equal? x '(end)))
2619+
idxs)))
26172620
(arr (if reuse (make-ssavalue) a))
26182621
(stmts (if reuse `((= ,arr ,(expand-forms a))) '()))
26192622
(rrhs (and (pair? rhs) (not (ssavalue? rhs)) (not (quoted? rhs))))

0 commit comments

Comments
 (0)