| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 
 | %% -*- Mode: erlang; indent-tabs-mode: nil -*-
%% Copyright Ericsson AB 2017. All Rights Reserved.
%%% Try and catch indentation is hard
%%% Not everything in these test are set in stone
%%% better indentation rules can be added but by having
%%% these tests we can see what changes in new implementations
%%% and notice when doing unintentional changes
try_catch() ->
    try
        io:format(stdout, "Parsing file ~s, ",
                  [St0#leex.xfile]),
        {ok,Line3,REAs,Actions,St3} =
            parse_rules(Xfile, Line2, Macs, St2)
    catch
        exit:{badarg,R} ->
            foo(R),
            io:format(stdout,
                      "ERROR reason ~p~n",
                      R);
        error:R
          when R =:= 42 ->			% when should be indented
            foo(R);
        error:R
          when					% when should be indented
              R =:= 42 ->			% but unsure about this (maybe 2 more)
            foo(R);
        error:R when
              R =:= foo ->			% line should be 2 indented (works)
            foo(R);
        error:R ->
            foo(R),
            io:format(stdout,
                      "ERROR reason ~p~n",
                      R)
    after
        foo('after'),
        file:close(Xfile)
    end;
try_catch() ->
    try
        foo(bar)
    of
        X when true andalso
               kalle ->
            io:format(stdout, "Parsing file ~s, ",
                      [St0#leex.xfile]),
            {ok,Line3,REAs,Actions,St3} =
                parse_rules(Xfile, Line2, Macs, St2);
        X
          when false andalso			% when should be 2 indented
               bengt ->
            gurka();
        X when
              false andalso			% line should be 2 indented
              not bengt ->
            gurka();
        X ->
            io:format(stdout, "Parsing file ~s, ",
                      [St0#leex.xfile]),
            {ok,Line3,REAs,Actions,St3} =
                parse_rules(Xfile, Line2, Macs, St2)
    catch
        exit:{badarg,R} ->
            foo(R),
            io:format(stdout,
                      "ERROR reason ~p~n",
                      R);
        error:R ->
            foo(R),
            io:format(stdout,
                      "ERROR reason ~p~n",
                      R)
    after
        foo('after'),
        file:close(Xfile),
        bar(with_long_arg,
            with_second_arg)
    end;
try_catch() ->
    try foo()
    after
        foo(),
        bar(with_long_arg,
            with_second_arg)
    end.
indent_catch() ->
    D = B +
        float(43.1),
    B = catch oskar(X),
    A = catch (baz +
                   bax),
    catch foo(),
    C = catch B +
        float(43.1),
    case catch foo(X) of
        A ->
            B
    end,
    case
        catch foo(X)
    of
        A ->
            B
    end,
    case
        foo(X)
    of
        A ->
            catch B,
            X
    end,
    try sune of
        _ -> foo
    catch _:_ -> baf
    end,
    Variable = try
                   sune
               of
                   _ ->
                       X = 5,
                       (catch foo(X)),
                       X + 10
               catch _:_ -> baf
               after cleanup()
               end,
    try
        (catch sune)
    of
        _ ->
            foo1(),
    catch foo()  %% BUGBUG can't handle catch inside try without parentheses
    catch _:_ ->
            baf
    end,
    try
        (catch exit())
    catch
        _ ->
            catch baf()
    end,
    ok.
%% this used to result in 2x the correct indentation within the function
%% body, due to the function name being mistaken for a keyword
catcher(N) ->
    try generate_exception(N) of
        Val -> {N, normal, Val}
    catch
        throw:X -> {N, caught, thrown, X};
        exit:X -> {N, caught, exited, X};
        error:X -> {N, caught, error, X}
    end.
 |