Indenting Based on Unbalanced Paranthesis

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Indenting Based on Unbalanced Paranthesis

Danny Gratzer
I am writing an indentation script for a simple language. The language is has very simple constructs and the indentation really only has 3 rules:

1. A comment has goes from a // until a newline, anything in a comment should be ignored.

2. If the line above contains a semi-colon, the indentation should be 0.

3. Otherwise, indent to 1 more than the most recent unbalanced ( and to 4 spaces if all paranthesis are balanced.

The last rule is kinda stumping me, does anyone have any advice?

--
Danny Gratzer

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Indenting Based on Unbalanced Paranthesis

Danny Gratzer
Oh actually 1 more rule

4. If the line above matches "let:$", or "in:$" where $ is the end of line, indent by 1 more than this line.


On Thu, Nov 29, 2012 at 5:24 PM, Danny Gratzer <[hidden email]> wrote:
I am writing an indentation script for a simple language. The language is has very simple constructs and the indentation really only has 3 rules:

1. A comment has goes from a // until a newline, anything in a comment should be ignored.

2. If the line above contains a semi-colon, the indentation should be 0.

3. Otherwise, indent to 1 more than the most recent unbalanced ( and to 4 spaces if all paranthesis are balanced.

The last rule is kinda stumping me, does anyone have any advice?

--
Danny Gratzer



--
Danny Gratzer

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Indenting Based on Unbalanced Paranthesis

Danny Gratzer
Excuse me, rule 3. should read:

3. Otherwise, indent to 1 more than the most recent unbalanced ( and to the same level as the last line if all parenthesis are balanced and no other rules apply.




On Thu, Nov 29, 2012 at 5:27 PM, Danny Gratzer <[hidden email]> wrote:
Oh actually 1 more rule

4. If the line above matches "let:$", or "in:$" where $ is the end of line, indent by 1 more than this line.


On Thu, Nov 29, 2012 at 5:24 PM, Danny Gratzer <[hidden email]> wrote:
I am writing an indentation script for a simple language. The language is has very simple constructs and the indentation really only has 3 rules:

1. A comment has goes from a // until a newline, anything in a comment should be ignored.

2. If the line above contains a semi-colon, the indentation should be 0.

3. Otherwise, indent to 1 more than the most recent unbalanced ( and to 4 spaces if all paranthesis are balanced.

The last rule is kinda stumping me, does anyone have any advice?

--
Danny Gratzer



--
Danny Gratzer



--
Danny Gratzer

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Indenting Based on Unbalanced Paranthesis

Benjamin R. Haskell-8
[Reversed the top-posting, per list preference]

On Thu, Nov 29, 2012 at 5:24 PM, Danny Gratzer wrote:

> I am writing an indentation script for a simple language. The language
> is has very simple constructs and the indentation really only has 3
> rules:
>
> 1. A comment has goes from a // until a newline, anything in a comment
> should be ignored.
>
> 2. If the line above contains a semi-colon, the indentation should be 0.
>
> 3. Otherwise, indent to 1 more than the most recent unbalanced ( and
> to 4 spaces if all paranthesis are balanced.
>
> The last rule is kinda stumping me, does anyone have any advice?

Don't write the indent file if you don't have to. What language are
you trying to indent?

Indenting gets slow if you have to scan the whole file.  Unless you're
never dealing with at-all long files.  Is there anything other than
semi-colons and parenthesis (im)balance that can be used for resetting
indentation?


On Thu, Nov 29, 2012 at 5:27 PM, Danny Gratzer wrote:

> Oh actually 1 more rule
>
> 4. If the line above matches "let:$", or "in:$" where $ is the end of
> line, indent by 1 more than this line.

On Thu, 29 Nov 2012, Danny Gratzer wrote:

> Excuse me, rule 3. should read:
>
> 3. Otherwise, indent to 1 more than the most recent unbalanced ( and to the
> same level as the last line if all parenthesis are balanced and no other
> rules apply.

It'd be helpful to see some samples of what you're trying to indent.
Especially to see whether the scan all the way to the start of the file
can be avoided.

--
Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Indenting Based on Unbalanced Paranthesis

Benjamin Fritz
In reply to this post by Danny Gratzer
On Thursday, November 29, 2012 5:24:53 PM UTC-6, Danny Gratzer wrote:

> I am writing an indentation script for a simple language. The language is has very simple constructs and the indentation really only has 3 rules:
>
>
> 1. A comment has goes from a // until a newline, anything in a comment should be ignored.
>
>
>
> 2. If the line above contains a semi-colon, the indentation should be 0.
>
>
> 3. Otherwise, indent to 1 more than the most recent unbalanced ( and to 4 spaces if all paranthesis are balanced.
>
>
>
> The last rule is kinda stumping me, does anyone have any advice?
>
>

I'd try using the searchpair() or searchpairpos() functions for an exact solution which works in all cases.

Or a simpler solution might just check the previous line for an opening (, but this will be hard to get right for nested parentheses groups.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Indenting Based on Unbalanced Paranthesis

Danny Gratzer
In reply to this post by Benjamin R. Haskell-8
Apologizes for the top posting,

No indenting exists for this previously, it's a language (currently unnamed) I'm writing as an experiment in functional programming and to learn to parse.


I can't think of any other markers really, the syntax for the language is pretty minimalistic, here's a quicksort implementation that has 95% of the language in it:

quicksort (ls) := 
    if (= (length ls) 1) 
        ls
        (let
            pivot = car ls,
            less  = filter (lambda(x) -> < x pivot) (cdr ls),
            more  = filter (lambda(x) -> >= x pivot) (cdr ls),
            in:
                append (quicksort less) (cons pivot (quicksort more)));

main := quicksort [1 2 3 5 18 4 1 4 1 4]

Since () are used to group function applications their extremely common. I was originally thinking a syntax similar to Scheme's or Common Lisp's might do it, but I'm confused how they manage it based on their indent files, I'm still pretty newbie-ish at this sort of vim stuff.
 


On Thu, Nov 29, 2012 at 6:08 PM, Benjamin R. Haskell <[hidden email]> wrote:
[Reversed the top-posting, per list preference]


On Thu, Nov 29, 2012 at 5:24 PM, Danny Gratzer wrote:

I am writing an indentation script for a simple language. The language is has very simple constructs and the indentation really only has 3 rules:

1. A comment has goes from a // until a newline, anything in a comment should be ignored.

2. If the line above contains a semi-colon, the indentation should be 0.

3. Otherwise, indent to 1 more than the most recent unbalanced ( and to 4 spaces if all paranthesis are balanced.

The last rule is kinda stumping me, does anyone have any advice?

Don't write the indent file if you don't have to. What language are you trying to indent?

Indenting gets slow if you have to scan the whole file.  Unless you're never dealing with at-all long files.  Is there anything other than semi-colons and parenthesis (im)balance that can be used for resetting indentation?



On Thu, Nov 29, 2012 at 5:27 PM, Danny Gratzer wrote:

Oh actually 1 more rule

4. If the line above matches "let:$", or "in:$" where $ is the end of
line, indent by 1 more than this line.

On Thu, 29 Nov 2012, Danny Gratzer wrote:

Excuse me, rule 3. should read:

3. Otherwise, indent to 1 more than the most recent unbalanced ( and to the
same level as the last line if all parenthesis are balanced and no other
rules apply.

It'd be helpful to see some samples of what you're trying to indent. Especially to see whether the scan all the way to the start of the file can be avoided.

--
Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php



--
Danny Gratzer

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Indenting Based on Unbalanced Paranthesis

David Fishburn-2
In reply to this post by Danny Gratzer

On Thu, Nov 29, 2012 at 6:24 PM, Danny Gratzer <[hidden email]> wrote:
I am writing an indentation script for a simple language. The language is has very simple constructs and the indentation really only has 3 rules:

...

Not sure if you have looked into this plugin:

IndentAnything : Write indentations or enhance existing indentations without writing code 

It can make writing an indent file very easy, it really depends on your rules and how anal you might want to be.

Certainly worth a look.

HTH,
David
  

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php