File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -565,6 +565,25 @@ name of compatibility, perhaps with a warning.)
565
565
arises from ` (set! pred char-hex?) ` in ` parse-number ` accepting hex exponent
566
566
digits, all of which are detected as invalid except for a trailing ` f ` when
567
567
processed by ` isnumtok_base ` .
568
+ * ` begin ` and ` end ` are not parsed as keywords when indexing. Typed comprehensions
569
+ initially look the same, but can be distinguished from indexing once we handle
570
+ a ` for ` token; it is safe to treat ` begin ` and ` end ` as keywords afterwards. The
571
+ reference parser * only* handles this well when there's a newline before ` for ` :
572
+ ``` julia
573
+ Any[foo (i)
574
+ for i in x if begin
575
+ true
576
+ end
577
+ ]
578
+ ```
579
+ works, while
580
+ ``` julia
581
+ Any[foo (i) for i in x if begin
582
+ true
583
+ end
584
+ ]
585
+ ```
586
+ does not. JuliaSyntax handles both cases.
568
587
569
588
## Parsing / AST oddities and warts
570
589
Original file line number Diff line number Diff line change @@ -2526,6 +2526,7 @@ end
2526
2526
# then reconstructing the nested flattens and generators when converting to Expr.
2527
2527
#
2528
2528
# [x for a = as for b = bs if cond1 for c = cs if cond2] ==> (comprehension (flatten x (= a as) (filter (= b bs) cond1) (filter (= c cs) cond2)))
2529
+ # [x for a = as if begin cond2 end] => (comprehension (generator x (filter (= a as) (block cond2))))
2529
2530
#
2530
2531
# flisp: parse-generator
2531
2532
function parse_generator (ps:: ParseState , mark, flatten= false )
@@ -2562,7 +2563,8 @@ end
2562
2563
# flisp: parse-comprehension
2563
2564
function parse_comprehension (ps:: ParseState , mark, closer)
2564
2565
ps = ParseState (ps, whitespace_newline= true ,
2565
- space_sensitive= false )
2566
+ space_sensitive= false ,
2567
+ end_symbol= false )
2566
2568
parse_generator (ps, mark)
2567
2569
bump_closing_token (ps, closer)
2568
2570
return (K " comprehension" , EMPTY_FLAGS)
Original file line number Diff line number Diff line change @@ -620,6 +620,7 @@ tests = [
620
620
" [x \n\n for a in as]" => " (comprehension (generator x (= a as)))"
621
621
# parse_generator
622
622
" [x for a = as for b = bs if cond1 for c = cs if cond2]" => " (comprehension (flatten x (= a as) (filter (= b bs) cond1) (filter (= c cs) cond2)))"
623
+ " [x for a = as if begin cond2 end]" => " (comprehension (generator x (filter (= a as) (block cond2))))"
623
624
" [(x)for x in xs]" => " (comprehension (generator x (error-t) (= x xs)))"
624
625
" (a for x in xs if cond)" => " (generator a (filter (= x xs) cond))"
625
626
" (xy for x in xs for y in ys)" => " (flatten xy (= x xs) (= y ys))"
You can’t perform that action at this time.
0 commit comments