Sunday, July 23, 2017

Syntax highlight problem

Hi Vimmers,

I'm writing a syntax file for Swift language. Apple Swift. What I'm trying to accomplish is have different regions for a function call and a function definition. This is not so difficult because a function definition will always be preceded by the keyword 'func'. I want two different regions because Swift, like Objective-C, has parameter labels that can be declared on its functions. For example:

    func doSomething(param1: Int, paramLabel2 param2: Int)

When I call that function I should write:

    doSomething(1, paramLabel2: 0)

What I want with the syntax file is to highlight the parameters labels in the function definition and also in the function call. So I am trying this set of groups:

syn match  swiftDelimiter "[\[]{}()]" contained
syn region swiftBlock    transparent matchgroup=swiftDelimiter start=/{/ end=/}/ fold
syn region swiftArray    transparent matchgroup=swiftDelimiter start=/\[/ end=/\]/
syn region swiftBraces   transparent matchgroup=swiftDelimiter start=/\\\@<!(/ end=/)/
syn region swiftFunDecl  transparent matchgroup=swiftDelimiter start="^\%(.*\%(func\s\+\k\+\|[^.]init[?]\?\)\)\s*\zs(" end=")" contains=ALLBUT,swiftParam
syn match  swiftParam    contained containedin=swiftBraces display /\k\+\s*\%(:\)\@=/
syn match  swiftLabel    contained display /\(_\|\k\+\)\(\s\+\k\+\s*:\)\@=/ containedin=swiftBraces


The 'swiftFunDecl' matches every function definition and the 'swiftBraces' should match only other places where 'swiftFunDecl' doesn't match. But that isn't happening. The 'swiftBraces' still matches where 'swiftFunDecl' matches and, therefore, parameters are highlighted in the function definition where only labels should be highlighted.

I can't see what I'm doing wrong. Could someone help me with that?

Thanks in advance,
Alessandro Antonello

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: