Python-style empty last array item; improved error-handling; fixes; typos #4

Merged
merged 4 commits into from Apr 26, 2013

Conversation

Projects
None yet
2 participants
Contributor

djui commented Mar 20, 2013

A bunch of smaller tweaks. Haven't written testcases yet, will do later. And maybe the test should be extended to run against BurntSushi's test set.

Owner

kalta commented Mar 20, 2013

Thanks, I'll have a look as soon as I can

Owner

kalta commented Mar 22, 2013

Thanks.
Most of the changes are ok.
However, the case "a=[]" doesn't work correctly. Also, I think the "Fix to apply list string instead of binary" is not needed, as that part wasn't needed in my original code. I have reworked it a bit and the final parse_array/3 would be:

parse_array(Rest, Line, Acc) ->
    case parse_value(Rest, Line) of
        % Empty array
        {undefined, {[$]|Rest1], Line1}} ->
            {lists:reverse(Acc), parse_space(Rest1, Line1)};
        {undefined, _} ->
            throw({invalid_array, Line});
        {Value, {[$]|Rest1], Line1}} ->
            {lists:reverse([Value|Acc]), parse_space(Rest1, Line1)};
        {Value, {[$,|Rest1], Line1}} ->
            case parse_space(Rest1, Line1) of
                {[$]|Rest2], Line2} -> %% "Python-style" empty last array item
                    {lists:reverse([Value|Acc]), parse_space(Rest2, Line2)};
                {Rest2, Line2} ->
                    parse_array(Rest2, Line2, [Value|Acc])
            end;
        _ ->
            throw({invalid_array, Line})
    end.

I will add these changes to a djui-master branch to test it a bit more.

@kalta kalta merged commit f601a94 into kalta:master Apr 26, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment