Sublime Forum

Tricky syntax hilighting scenario

#1

I am trying to put together a modern Fortran (i know, i know) syntax highlighting definition. I know there is one floating around on github somewhere, but i tried it and wasnt super impressed, so now im doing it myself with the JSON-PropertyList conversion method. I have almost everything working just as I would like except for type definitions. Here is an example of what im trying to highlight:

TYPE,ABSTRACT,EXTENDS(BaseType) :: ExtendedType
! other code that highlights just fine
ENDTYPE ExtendedType

There will always be a TYPE and ENDTYPE, but the ABSTRACT and EXTENDS(…) are optional. A couple of things are making this tricky. First, I want to be able to capture the name of the type, in this case “ExtendedType” so that I can apply the entity.name… scope to it so that I can do a goto anything on it. Second, there is another context in which the TYPE keyword gets used to declare an instance of a particular type. Heres an example:

SUBROUTINE foo(bar)
    TYPE(ExtendedType),INTENT(IN) :: bar

ENDSUBROUTINE foo

In this case i do not want to apply the entity.name scope to “bar.” I feel like i should be able to match the EXTENDS(BaseType) and ABSTRACT keywords first, which will consume them, then match TYPE :: ExtendedType and capture the keyword and the name of the type, but this doesnt seem to work. I guess I dont understand the mechanics of the match consumption, and it doesnt appear to be defined very explicitly… Maybe it only operates on a line-by-line basis? Even so, I am currently trying to match ABSTRACT and EXTENDS(…) before TYPE :: … however TYPE is getting highlighted, but ABSTRACT and EXTENDS are not. Any suggestions?

thanks!

0 Likes

#2

…anybody?

0 Likes