@@ -672,15 +672,15 @@ meta_from_location({Line, Column, _}) ->
672672do_end_meta (Do , End ) ->
673673 case ? token_metadata () of
674674 true ->
675- [{do , meta_from_location ( ? location ( Do )) }, {'end' , meta_from_location ( ? location ( End ) )}];
675+ [{do , meta_from_token ( Do )}, {'end' , meta_from_token ( End )}];
676676 false ->
677677 []
678678 end .
679679
680680meta_from_token_with_closing (Begin , End ) ->
681681 case ? token_metadata () of
682682 true ->
683- [{closing , meta_from_location ( ? location ( End ) )} | meta_from_token (Begin )];
683+ [{closing , meta_from_token ( End )} | meta_from_token (Begin )];
684684 false ->
685685 meta_from_token (Begin )
686686 end .
@@ -778,21 +778,42 @@ build_map_update(Left, {Pipe, Struct, Map}, Right, Extra) ->
778778
779779% % Blocks
780780
781- build_block (Exprs ) -> build_block (Exprs , [] ).
781+ build_block (Exprs ) -> build_block (Exprs , none ).
782782
783- build_block ([{unquote_splicing , _ , [_ ]}]= Exprs , Meta ) ->
784- {'__block__' , Meta , Exprs };
785- build_block ([Expr ], _Meta ) ->
783+ build_block ([{unquote_splicing , _ , [_ ]}]= Exprs , BeforeAfter ) ->
784+ {'__block__' , block_meta (BeforeAfter ), Exprs };
785+ build_block ([{Op , ExprMeta , Args }], {Before , After }) ->
786+ ExprMetaWithExtra =
787+ case ? token_metadata () of
788+ true ->
789+ ParensEntry = meta_from_token (Before ) ++ [{closing , meta_from_token (After )}],
790+ case ExprMeta of
791+ % If there are multiple parens, those will result in subsequent
792+ % build_block/2 calls, so we can assume parens entry is first
793+ [{parens , Parens } | Meta ] ->
794+ [{parens , [ParensEntry | Parens ]} | Meta ];
795+
796+ Meta ->
797+ [{parens , [ParensEntry ]} | Meta ]
798+ end ;
799+ false ->
800+ ExprMeta
801+ end ,
802+ {Op , ExprMetaWithExtra , Args };
803+ build_block ([Expr ], _BeforeAfter ) ->
786804 Expr ;
787- build_block (Exprs , Meta ) ->
788- {'__block__' , Meta , Exprs }.
805+ build_block (Exprs , BeforeAfter ) ->
806+ {'__block__' , block_meta (BeforeAfter ), Exprs }.
807+
808+ block_meta (none ) -> [];
809+ block_meta ({Before , After }) -> meta_from_token_with_closing (Before , After ).
789810
790811% % Newlines
791812
792813newlines_pair (Left , Right ) ->
793814 case ? token_metadata () of
794815 true ->
795- newlines (? location (Left ), [{closing , meta_from_location ( ? location ( Right ) )}]);
816+ newlines (? location (Left ), [{closing , meta_from_token ( Right )}]);
796817 false ->
797818 []
798819 end .
@@ -1064,7 +1085,7 @@ build_paren_stab(_Before, [{Op, _, [_]}]=Exprs, _After) when ?rearrange_uop(Op)
10641085 {'__block__' , [], Exprs };
10651086build_paren_stab (Before , Stab , After ) ->
10661087 case check_stab (Stab , none ) of
1067- block -> build_block (reverse (Stab ), meta_from_token_with_closing ( Before , After ) );
1088+ block -> build_block (reverse (Stab ), { Before , After } );
10681089 stab -> handle_literal (collect_stab (Stab , [], []), Before , newlines_pair (Before , After ))
10691090 end .
10701091
0 commit comments