Sublime Forum

How to match a function call spitted across multiples lines on '.sublime-syntax'

#1

I need to match this regex. It is working on other regex engines.

I know this is because sublime can only run against the current line, but how to properly overcome it on this situation?
I tried to use it on this but does not work:

  function_call2:
    - match: '([A-Za-z_][\w_]*)(\n\s)*?\s*\('
      push:
        - meta_scope: function.call.pawn
        - match: '^\s*\('
          pop: true

This is the full syntax:

0 Likes

#2
  function_call:
    - match: '\s*([A-Za-z_][\w_]*)[\s]*(\()'
      captures:
        1: function.call.pawn
        2: punctuation.definition.group.begin
      push:
        - meta_scope: meta.function-call
        - match: \)
          scope: punctuation.definition.group.end
        - match: ','
          scope: punctuation.separator.arguments
        # - include: pawn_expression

You would then split the “main” context into a context that only supports expressions (as they are valid as function arguments) and include that in the “main” context.

There is no sane way to match the last register_cvar call where the opening parens only come after another 4 lines or even just the next line (looks horrendous anyway), so my recommendation is to just not do it.

Btw, you have a typo (pawn_coment) in your context names.

0 Likes

#3

Thanks @FichteFoll. However is it possible to create a package to do the highlight?

If I run this:


view.add_regions( "FunctionCallHighlight", view.find_all( "([A-Za-z_][\w_]*)(\n\s)*?\s*\(" ), "function.call.AmxxPawn" )

I got to highlight the region but does not look right:

Is there a way to apply the scope function.call to my regex?
view.find_all( "([A-Za-z_][\w_]*)(\n\s)*?\s*\(" )

0 Likes

#4

view.find_by_selector(selector) can find all items that match a given scope and return them as regions, so that might do what you want.

0 Likes

#5

I want to the opposite, given the regions found by
view.find_all( "([A-Za-z_][\w_]*)(\n\s)*?\s*\(" ), I want to set a scope to them.

For example, if the region(s) returned by view.find_all have the scope source.c++, I want to add to them the scope function.call. So, doing yours view.find_by_selector( 'function.call' ), after apply my scope it will return the regions just marked. But the question is, how to mark them? It looks like it is not possible by the current API. Is it? If so, I would to do a feature request, or to improve the syntax file to match regex spreading across several lines, or to create a API to allow apply a scope to given positions.

And because is impossible to match register_cvar on this below using the *.sublime-syntax file, as the regexes are compared only against the current line, so I cannot match something which is spreading across several lines:

    cvar_isFirstServerStart      = register_cvar
                                               
   
              
                  ( "gal_server_starting", "1", FCVAR_SPONLY );
0 Likes

#6

Ahh I see; yes to my knowledge the only way to assign syntax scopes is as a part of a syntax definition, but I’ve never delved very deeply into that aspect of Sublime so I may be wrong.

0 Likes

#7

View.add_regions uses the foreground color of a scope as background color if no background was specified.

0 Likes

#8

How to add a background?
add_regions(key, [regions], <scope>, <icon>, <flags>)

I do not see it on the api page.

0 Likes

#9

Background for the scope as determined by your color scheme.

0 Likes

#10

You said: “if no background was specified.” implies on “uses the foreground color of a scope as background color”. But actually it does not say anything, as it says everything else could be possible.

So, View.add_regions does not add a scope a chunk of text. This is a feature request. A native to add a scope for a chunk of text.

Issue opened on: A native to apply a scope give a chunk of text - https://github.com/SublimeTextIssues/Core/issues/1412

0 Likes