Grammar regex question, different highlight for same expression


#1

I’ve created a grammar for 6809 assembly, now I am adding syntax highlighting for assembler directives, here’s the excerpt I’m struggling with:

    # pragma directives
    {
        match: '\\b(?i)(\\*pragma(push|pop)?|(\\*)?pragma)\\b'
        name: 'storage.modifier'
    }
    {   # export missing!
        match: '\\b(?i)(6800compat|(6809|6309)(conv)?|index0tonone|cescapes|importundefexport|undefextern|dollar(not)?local|pcaspcr|shadow|nolist|autobranchlength|nosymbolcase|symbolnocase|condundefzero|forwardrefmax|qrts|m80ext|testmode)\\b'
        name: 'support.function.pseudo'
    }

As you can see, I want the pragma directives and the pragmas to have different highlighting. Now there is one pragma that I left out: export. The problem is, export can either be a directive of its own or a pragma, so I want it to have different highlighting depending whether it is preceded by ‘pragma’ or not.

export  ; highlight color 1
pragma export ; pragma in highlight color 1, export highlight color 2

I tried this:

    {
        match: '\\b(?i)(\\*pragma(push|pop)?|(\\*)?pragma)\s(export)\\b'
        name: 'storage.modifier'
        captures:
            '1':
                name: 'storage.modifier'
            '2':
                name: 'support.function.pseudo'
    }

Which is not working. I copied this again from the grammar example from the flight manual. Any suggestions?


#2

Perhaps put down a code example for the assembly code. It would help to visualize whereto you are aiming for. Also know that you can do push and pull separately.


#3

I’d would like to look something like this:

grammarexample

Line 4 is what I’m aiming for. Line 16 shows the problem I have, while line 2 shows export in another context that highlights it like I want it to be. So in short, everything fine is fine except line 16 - I want ‘export’ there to be of the same color as ‘6809conv’ in line 4.


#4

It is a first come first serve basis.
If you have in order for matching…
“pragma export”
“pragma .*”
“export”

“pragma export” will win the contest if it is found first, ignoring the following matches.


#5

match: '\\b(?i)(\\*pragma(push|pop)?|(\\*)?pragma)\s(export)\\b' should be:
match: '\\b(?i)(\\*pragma(push|pop)?|(\\*)?pragma)\\s(export)\\b'. You forgot to double-escape the \s.