Skip to content

Commit

Permalink
Fix conditional compile syntax highlighting (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron authored Mar 7, 2024
1 parent 7742b0e commit 6315d0b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
48 changes: 48 additions & 0 deletions src/grammar/brightscript.tmLanguage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,54 @@ import { standardizePath as s } from 'brighterscript';
const brightscriptTmlanguagePath = s`${__dirname}/../../syntaxes/brightscript.tmLanguage.json`;

describe('brightscript.tmlanguage.json', () => {
it('colors normal conditional compile statements properly', async () => {
await testGrammar(`
#if true
'^^^ keyword.preprocessor.if.brs
#elseif false
'^^^^^^^ keyword.preprocessor.elseif.brs
#else
'^^^^^ keyword.preprocessor.else.brs
#endif
'^^^^^^ keyword.preprocessor.endif.brs
`);
});

it('colors composite keyword conditional compile statements properly', async () => {
await testGrammar(`
#const IS_DEV_MODE=true
'^^^^^^ keyword.preprocessor.const.brs
#error Something bad happened
'^^^^^^ keyword.preprocessor.error.brs
#if true
'^^^ keyword.preprocessor.if.brs
#else if false
'^^^^^^^^ keyword.preprocessor.elseif.brs
#else
'^^^^^ keyword.preprocessor.else.brs
#end if
'^^^^^^^ keyword.preprocessor.endif.brs
`);
});

it('colors leading whitespace conditional compile statements properly', async () => {
//carrots should be shorter by 1 because \t turns into 1 char
await testGrammar(`
#\t const IS_DEV_MODE=true
'^^^^^^^^ keyword.preprocessor.const.brs
#\t error Something bad happened
'^^^^^^^^ keyword.preprocessor.error.brs
#\t if true
'^^^^^ keyword.preprocessor.if.brs
#\t else if false
'^^^^^^^ keyword.preprocessor.elseif.brs
#\t else
'^^^^^^^ keyword.preprocessor.else.brs
#\t end if
'^^^^^^^^^ keyword.preprocessor.endif.brs
`);
});

it('colors `continue for`', async () => {
await testGrammar(`
for i = 0 to 10
Expand Down
20 changes: 12 additions & 8 deletions syntaxes/brightscript.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -507,24 +507,28 @@
"preprocessor_keywords": {
"patterns": [
{
"match": "(?i:(#const))",
"name": "keyword.preprocessor.if.brs"
"match": "(?i:(#[ \t]*const))",
"name": "keyword.preprocessor.const.brs"
},
{
"match": "(?i:(#if))",
"match": "(?i:(#[ \t]*if))",
"name": "keyword.preprocessor.if.brs"
},
{
"match": "(?i:(#else\\s*if))",
"name": "keyword.preprocessor.if.brs"
"match": "(?i:(#[ \t]*else[ \t]*if))",
"name": "keyword.preprocessor.elseif.brs"
},
{
"match": "(?i:(#end\\s*if))",
"match": "(?i:(#[ \t]*end[ \t]*if))",
"name": "keyword.preprocessor.endif.brs"
},
{
"match": "(?i:(#else))",
"match": "(?i:(#[ \t]*else))",
"name": "keyword.preprocessor.else.brs"
},
{
"match": "(?i:(#[ \t]*error))",
"name": "keyword.preprocessor.error.brs"
}
]
},
Expand Down Expand Up @@ -1018,4 +1022,4 @@
]
}
}
}
}

0 comments on commit 6315d0b

Please sign in to comment.