0

I'm making a custom rule for programming language Lint to :

  • match 1 or more empty lines after {, and
  • another rule to match empty line before }.

As an example in this code, I want these rules to match line 2 and line 5 :

class Test {                   /* Line 1 */
                               /* Line 2 */
  func example() {             /* Line 3 */
  }                            /* Line 4 */
                               /* Line 5 */
}

I had tried to do it with positive lookahead/lookbehind but with no luck (?<=\{)\n.

Could anyone help with it ?

Update:

Added whitespeace to the example.

class Test { 

  func example() { 
  }

}

1 Answers1

1

This is matching what you want:

\{\h*\R\K\h*\R|\R\K\h*\R(?=\h*\})
//added__^^^

Explanation:

  \{    : open brace
  \h*   : 0 or more horizontal spaces
  \R    : any kind of line break
  \K    : forget all we have seen until this position
  \h*   : 0 or more horizontal spaces
  \R    : any kind of line break
|       : OR
  \R    : any kind of line break
  \K    : forget all we have seen until this position
  \h*   : 0 or more horizontal spaces
  \R    : any kind of line break
  (?=   : positive lookahead
    \h* : 0 or more horizontal spaces
    \}  : close brace
  )     : end lookahead
Toto
  • 19,304