Sublime Forum

How to add function definition support for a new language

#1

Hello,
I’m using a nesC programming language. Sublime cannot resolve/find where the function definition is, most probably because of language specific function ‘wiring’ mechanism.
Is there a way to define rules for finding function definition for a new language? How complicated is it to do?
I’m using custom package that supports syntax highlighting for this language.

0 Likes

#2

Sublime Text’s builtin goto definition relies on the syntax definition. Since nesC is a C-like language, most likely the syntax definition you used is not parsing it well.

0 Likes

#3

Do you know, which part of syntax definition responsible for parsing function definition?

0 Likes

#4

Rules are simple but it’s hard (or even not possible?) to write grammar to perfectly parse C lanugage with ST’s syntax engine.

For example, if something is scoped as entity.name.function then ST should know this identifer is the name of a function defenition. Scoping function names is relatively easy but when it comes to scope variable names, it’s hard.

0 Likes

#5

Not completely following, because I’m new to ST.
But here is a syntax description package that is used - https://github.com/MBradbury/Packages/blob/master/C%2B%2B/nesC.sublime-syntax.
So I believe the scoping you are talking about is somewhere in this section:

global-maybe-function:
    - include: comments
    # Consume pointer info, macros and any type info that was offset by macros
    - match: \*
      scope: keyword.operator.c
    - include: types
    - include: modifiers-parens
    - include: modifiers
    # All uppercase identifier just before a newline is most likely a macro
    - match: '[[:upper:][:digit:]_]+\s*$'
    # Identifier that is not the function name - likely a macro
    - match: '{{identifier}}(?!\s*(\(|$))(?=\s+)'
    # Real function definition
    - match: '{{identifier}}(?=\s*(\(|$))'
      scope: meta.function.c entity.name.function.c
      set: function-definition-params
    - match: '(?=\S)'
      pop: true
0 Likes

#6

Without actual test case and expect output, it’s hard to start an real case discussion, unless you only want to know the theory, which is already given I believe.

0 Likes