@@ -587,9 +587,7 @@ def parse_unary(tokens: Peekable, p: float) -> "Object":
587587 return make_source_annotated_object (
588588 MatchFunction ,
589589 reduce (
590- lambda source_extent_one , source_extent_two : source_extent_one .coalesce (source_extent_two )
591- if source_extent_one
592- else None ,
590+ lambda source_extent_one , source_extent_two : join_source_extents (source_extent_one , source_extent_two ),
593591 cases_source_extents ,
594592 ),
595593 cases ,
@@ -671,9 +669,7 @@ def parse_binary(tokens: Peekable, p: float) -> "Object":
671669 if pl < p :
672670 break
673671 arg = parse_binary (tokens , pr )
674- l = make_source_annotated_object (
675- Apply , l .source_extent .coalesce (arg .source_extent ) if l .source_extent else None , l , arg
676- )
672+ l = make_source_annotated_object (Apply , join_source_extents (l .source_extent , arg .source_extent ), l , arg )
677673 continue
678674 prec = PS [op .value ]
679675 pl , pr = prec .pl , prec .pr
@@ -685,29 +681,25 @@ def parse_binary(tokens: Peekable, p: float) -> "Object":
685681 raise ParseError (f"expected variable in assignment { l !r} " )
686682 value = parse_binary (tokens , pr )
687683 l = make_source_annotated_object (
688- Assign , l .source_extent . coalesce ( value .source_extent ) if l . source_extent else None , l , value
684+ Assign , join_source_extents ( l .source_extent , value .source_extent ), l , value
689685 )
690686 elif op == Operator ("->" ):
691687 body = parse_binary (tokens , pr )
692688 l = make_source_annotated_object (
693- Function , l .source_extent . coalesce ( body .source_extent ) if l . source_extent else None , l , body
689+ Function , join_source_extents ( l .source_extent , body .source_extent ), l , body
694690 )
695691 elif op == Operator ("|>" ):
696692 func = parse_binary (tokens , pr )
697- l = make_source_annotated_object (
698- Apply , func .source_extent .coalesce (l .source_extent ) if func .source_extent else None , func , l
699- )
693+ l = make_source_annotated_object (Apply , join_source_extents (func .source_extent , l .source_extent ), func , l )
700694 elif op == Operator ("<|" ):
701695 arg = parse_binary (tokens , pr )
702- l = make_source_annotated_object (
703- Apply , l .source_extent .coalesce (arg .source_extent ) if l .source_extent else None , l , arg
704- )
696+ l = make_source_annotated_object (Apply , join_source_extents (l .source_extent , arg .source_extent ), l , arg )
705697 elif op == Operator (">>" ):
706698 r = parse_binary (tokens , pr )
707699 varname = gensym ()
708700 l = make_source_annotated_object (
709701 Function ,
710- l .source_extent . coalesce ( r .source_extent ) if l . source_extent else None ,
702+ join_source_extents ( l .source_extent , r .source_extent ),
711703 Var (varname ),
712704 Apply (r , Apply (l , Var (varname ))),
713705 )
@@ -716,32 +708,28 @@ def parse_binary(tokens: Peekable, p: float) -> "Object":
716708 varname = gensym ()
717709 l = make_source_annotated_object (
718710 Function ,
719- l .source_extent . coalesce ( r .source_extent ) if l . source_extent else None ,
711+ join_source_extents ( l .source_extent , r .source_extent ),
720712 Var (varname ),
721713 Apply (l , Apply (r , Var (varname ))),
722714 )
723715 elif op == Operator ("." ):
724716 binding = parse_binary (tokens , pr )
725717 l = make_source_annotated_object (
726- Where , l .source_extent . coalesce ( binding .source_extent ) if l . source_extent else None , l , binding
718+ Where , join_source_extents ( l .source_extent , binding .source_extent ), l , binding
727719 )
728720 elif op == Operator ("?" ):
729721 cond = parse_binary (tokens , pr )
730- l = make_source_annotated_object (
731- Assert , l .source_extent .coalesce (cond .source_extent ) if l .source_extent else None , l , cond
732- )
722+ l = make_source_annotated_object (Assert , join_source_extents (l .source_extent , cond .source_extent ), l , cond )
733723 elif op == Operator ("@" ):
734724 # TODO: revisit whether to use @ or . for field access
735725 at = parse_binary (tokens , pr )
736- l = make_source_annotated_object (
737- Access , l .source_extent .coalesce (at .source_extent ) if l .source_extent else None , l , at
738- )
726+ l = make_source_annotated_object (Access , join_source_extents (l .source_extent , at .source_extent ), l , at )
739727 else :
740728 assert isinstance (op , Operator )
741729 right = parse_binary (tokens , pr )
742730 l = make_source_annotated_object (
743731 Binop ,
744- l .source_extent . coalesce ( right .source_extent ) if l . source_extent else None ,
732+ join_source_extents ( l .source_extent , right .source_extent ),
745733 BinopKind .from_str (op .value ),
746734 l ,
747735 right ,
0 commit comments