Tsvi M
Tsvi M

Reputation: 333

.sublime-syntax multiple line function detection

I'm writing a .sublime-syntax for the Specman language and need help with multiple line method declaration.

A method is declared using the keyword is which comes after most of the other parts of the method declaration.

E.g.

fwd_init() @driver.clock is {

or

add(x : uint, y : uint) is also {

or

private do_stuff(field : my_type) is only {

etc...

My problem is that parts of the declaration can be quite long in case a lot of parameters are passed to the method, so I tend to split the line to multiple lines.

I'm having trouble matching the syntax for the method, as I need multiple line matches.

The following is what I have currently, but it's not working:

methods:
- match: (?=^\s*(?:private|static|final)?\s+[a-zA-Z](?:[a-zA-Z0-9_]+)?\s*\()
  set:
    - match: (?=\bis\b)
      push: method-declaration

Basically I want to return to lookahead, possibly match for the function, in case it's not a function pop it.

Upvotes: 1

Views: 223

Answers (1)

Tsvi M
Tsvi M

Reputation: 333

As I was writing the question I realized, all I needed to do is push the method-declaration onto the stack and first of all do a negative lookahead for is.

As follows:

methods:
  - match: (?=^\s*(?:private|static|final)?\s+[a-zA-Z](?:[a-zA-Z0-9_]+)?\s*\()
    push: method-declaration

method-declaration:
  - match: (?!is(?:\s+)(only|first|also)?)
    pop: true
  - ... parsing of the method declaration

Hope this helps anybody else looking for info on the subject.

Upvotes: 1

Related Questions