Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid indentation for recursive if/end if #4

Closed
PierreTechoueyres opened this issue Mar 21, 2017 · 4 comments
Closed

Invalid indentation for recursive if/end if #4

PierreTechoueyres opened this issue Mar 21, 2017 · 4 comments
Labels

Comments

@PierreTechoueyres
Copy link
Collaborator

I've trouble correctly indenting recursive if / then / end if;
The attached file isn't correctly indented. Any clue to start resolving this ?
The result bellow isn't what I expect.

begin
  if 1 = 0 then
    if 1 = 0 then
    null;
  else
    null;
  end if;
  elsif 1 = 2
  if 1 = 0 then
    null;
  else
    null;
    end if;
  else
    null;
  end if;
end;
/
[test.multi-if.sql.txt](https://github.com/alex-hhh/emacs-sql-indent/files/859318/test.multi-if.sql.txt)

@alex-hhh
Copy link
Owner

alex-hhh commented Mar 22, 2017

This is a known issue, and it is not simple to fix. The workaround is to use begin/end blocks around the nested if statements, as in the example below. I pushed a fix for indenting an end if line when there's an elsif in the if-else chain, see deb9885.

Unfortunately, I do not have time to fix this issue. If you want to try fixing it, the problem is that sqlind-beginning-of-statement-1 does not detect the beginning of the statement correctly for nested if blocks, so the sqlind-syntax-of-line function computes an incorrect syntax.

begin
  if 1 = 0 then
    begin
      if 1 = 0 then
        null;
      else
        null;
      end if;
    end;
  elsif 1 = 2
    begin
      if 1 = 0 then
        null;
      else
        null;
      end if;
    end;
  else
    null;
  end if;
end;
/

@PierreTechoueyres
Copy link
Collaborator Author

Thanks for the hint. Unfortunately I must work with existing code and I can't enclose If blocks.
I'll try to work on this. Thanks for the start point.

@alex-hhh
Copy link
Owner

After a bit of thinking I think I got this working. Can you please try it out and see if it OK?

I wrote this code about 10 years ago and back than this seemed like a hard task...

@PierreTechoueyres
Copy link
Collaborator Author

Whaou, You're faster than light !!!
Many thanks for fixing this. And you've maybe wrote this code 10 years ago but it's always useful (at least for me).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants