Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
295 changes: 295 additions & 0 deletions src/grammar/brightscript.tmLanguage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,301 @@ describe('brightscript.tmlanguage.json', () => {
`);
});

it('handles function & variable declarations using reserved function names', async () => {
await testGrammar(`
thing = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^^^ entity.name.variable.local.brs
`);

await testGrammar(`
thing = rnd()
' ^^^ entity.name.function.brs
' ^ keyword.operator.brs
'^^^^^ entity.name.variable.local.brs
`);

await testGrammar(`
thing = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^^^ entity.name.variable.local.brs

rnd = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs
`);

await testGrammar(`
thing = rnd()
' ^^^ entity.name.function.brs
' ^ keyword.operator.brs
'^^^^^ entity.name.variable.local.brs

rnd = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs
`);

await testGrammar(`
rnd = rnd()
' ^^^ entity.name.function.brs
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs

rnd = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs
`);

await testGrammar(`
sub rnd()
' ^^^ entity.name.function.brs
'^^^ keyword.declaration.function.brs

thing = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^^^ entity.name.variable.local.brs

rnd = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs

end sub
'^^^^^^^ keyword.declaration.function.brs
`);

await testGrammar(`
function rnd() as dynamic
' ^^^^^^^ storage.type.brs
' ^^ keyword.control.brs
' ^^^ entity.name.function.brs
'^^^^^^^^ keyword.declaration.function.brs

thing = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^^^ entity.name.variable.local.brs

rnd = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs

return invalid
' ^^^^^^^ constant.language.null.brs
'^^^^^^ keyword.control.flow.return.brs

end function
'^^^^^^^^^^^^ keyword.declaration.function.brs
`);

await testGrammar(`
sub nameless(rnd as dynamic)
' ^^^^^^^ storage.type.brs
' ^^ keyword.control.brs
' ^^^ entity.name.variable.local.brs
' ^^^^^^^^ entity.name.function.brs
'^^^ keyword.declaration.function.brs

thing = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^^^ entity.name.variable.local.brs

rnd = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs

end sub
'^^^^^^^ keyword.declaration.function.brs
`);

await testGrammar(`
sub nameless(rnd = rnd as dynamic)
' ^^^^^^^ storage.type.brs
' ^^ keyword.control.brs
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
' ^^^ entity.name.variable.local.brs
' ^^^^^^^^ entity.name.function.brs
'^^^ keyword.declaration.function.brs

thing = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^^^ entity.name.variable.local.brs

rnd = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs

end sub
'^^^^^^^ keyword.declaration.function.brs
`);

await testGrammar(`
sub nameless(rnd = rnd() as dynamic)
' ^^^^^^^ storage.type.brs
' ^^ keyword.control.brs
' ^^^ entity.name.function.brs
' ^ keyword.operator.brs
' ^^^ entity.name.variable.local.brs
' ^^^^^^^^ entity.name.function.brs
'^^^ keyword.declaration.function.brs

thing = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^^^ entity.name.variable.local.brs

rnd = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs

end sub
'^^^^^^^ keyword.declaration.function.brs
`);

await testGrammar(`
sub rnd(rnd = rnd as dynamic)
' ^^^^^^^ storage.type.brs
' ^^ keyword.control.brs
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
' ^^^ entity.name.variable.local.brs
' ^^^ entity.name.function.brs
'^^^ keyword.declaration.function.brs

thing = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^^^ entity.name.variable.local.brs

rnd = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs

end sub
'^^^^^^^ keyword.declaration.function.brs
`);

await testGrammar(`
sub rnd(randomVal as Dynamic, rnd as dynamic)
' ^^^^^^^ storage.type.brs
' ^^ keyword.control.brs
' ^^^ entity.name.variable.local.brs
' ^^^^^^^ storage.type.brs
' ^^ keyword.control.brs
' ^^^^^^^^^ entity.name.variable.local.brs
' ^^^ entity.name.function.brs
'^^^ keyword.declaration.function.brs

thing = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^^^ entity.name.variable.local.brs

rnd = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs

end sub
'^^^^^^^ keyword.declaration.function.brs
`);

await testGrammar(`
sub rnd(randomVal as Dynamic, rnd() as function)
' ^^^^^^^^ storage.type.brs
' ^^ keyword.control.brs
' ^^^ entity.name.function.brs
' ^^^^^^^ storage.type.brs
' ^^ keyword.control.brs
' ^^^^^^^^^ entity.name.variable.local.brs
' ^^^ entity.name.function.brs
'^^^ keyword.declaration.function.brs

thing = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^^^ entity.name.variable.local.brs

rnd = rnd
' ^^^ entity.name.variable.local.brs
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs

end sub
'^^^^^^^ keyword.declaration.function.brs
`);

await testGrammar(`
val = {
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs

rnd: sub()
' ^^^ keyword.declaration.function.brs
'^^^ entity.name.variable.local.brs

end sub
'^^^^^^^ keyword.declaration.function.brs
}
`);

await testGrammar(`
val = {
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs

rnd: function() as dynamic
' ^^^^^^^ storage.type.brs
' ^^ keyword.control.brs
' ^^^^^^^^ keyword.declaration.function.brs
'^^^ entity.name.variable.local.brs

return invalid
' ^^^^^^^ constant.language.null.brs
'^^^^^^ keyword.control.flow.return.brs

end function
'^^^^^^^^^^^^ keyword.declaration.function.brs
}
`);

await testGrammar(`
val = {
' ^ keyword.operator.brs
'^^^ entity.name.variable.local.brs

rnd: {
'^^^ entity.name.variable.local.brs

rnd: sub()
' ^^^ keyword.declaration.function.brs
'^^^ entity.name.variable.local.brs

end sub
'^^^^^^^ keyword.declaration.function.brs
}

end sub
'^^^^^^^ keyword.declaration.function.brs
}
`);
});

it('handles named public/protected/private function declarations', async () => {
await testGrammar(`
public sub write()
Expand Down
42 changes: 0 additions & 42 deletions syntaxes/brightscript.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@
{
"include": "#operators"
},
{
"include": "#support_functions"
},
{
"include": "#variables_and_params"
},
Expand Down Expand Up @@ -947,49 +944,10 @@
"match": "=|>=|<zz|>|<|<>|\\+|-|\\*|\\/|\\^|&|\\b(?i:(And|Not|Or|Mod))\\b",
"name": "keyword.operator.brs"
},
"support_functions": {
"patterns": [
{
"include": "#support_builtin_functions"
},
{
"include": "#support_global_functions"
},
{
"include": "#support_global_string_functions"
},
{
"include": "#support_global_math_functions"
},
{
"include": "#support_component_functions"
}
]
},
"global_constants": {
"match": "(?i:\\b(line_num)\\b)",
"name": "variable.language"
},
"support_builtin_functions": {
"match": "(?i:\\b(GetLastRun(RuntimeError|CompileError)|Rnd|Box|Type|objfun|pos|eval)\\b)",
"name": "support.function.brs"
},
"support_global_functions": {
"match": "(?i:\\b(Re(adAsciiFile|bootSystem)|GetInterface|MatchFiles|Sleep|C(opyFile|reate(Directory|Object))|Delete(Directory|File)|UpTime|FormatDrive|ListDir|W(ait|riteAsciiFile))\\b)",
"name": "support.function.brs"
},
"support_global_string_functions": {
"match": "(?i:\\b(Right|Mid|Str(i(ng(i)?)?)?|Chr|Instr|UCase|Val|Asc|L(Case|e(n|ft)))\\b)",
"name": "support.function.brs"
},
"support_global_math_functions": {
"match": "(?i:\\b(S(in|qr|gn)|C(sng|dbl|os)|Tan|Int|Exp|Fix|Log|A(tn|bs))\\b)",
"name": "support.function.brs"
},
"support_component_functions": {
"match": "(?i:\\b(R(ight|e(set(Index)?|ad(B(yte(IfAvailable)?|lock)|File|Line)?|move(Head|Tail|Index)))|Ge(nXML(Header)?|t(Res(ource|ponse(Headers|Code))|X|M(i(nute|llisecond)|o(nth|de(l)?)|essage)|B(yte(sPerBlock|Array)|o(o(tVersion(Number)?|lean)|dy))|S(t(orageCardInfo|a(ndards|tusByte)|ring(Count)?)|i(zeInMegabytes|gnedByte)|ource(Host|Identity|Port)|ub|ec(tionList|ond)|afe(X|Height|Y|Width))|H(o(stName|ur)|e(ight|ad))|Y(ear)?|N(extArticle|ame(dElements)?)|C(hildElements|ontrols|urrent(Standard|Con(trolValue|fig)|Input))|T(i(tle|me(Server|Zone))|o(String|File)|ext|ail)|I(n(t|dex|puts)|dentity)|ZoneDateTime|D(e(scription|vice(BootCount|Name|U(niqueId|ptime)))|a(y(OfWeek)?|ta))|U(se(dInMegabytes|rData)|tcDateTime)|Ent(ityEncode|ry)|V(ersion(Number)?|alue)|KeyList|F(ileSystemType|loat|a(ilureReason|mily)|reeInMegabytes)|W(holeState|idth)|LocalDateTime|Attributes))|M(id|D5|ap(StereoOutput(Aux)?|DigitalOutput))|Boolean|S(h(ift|ow)|canWiFi|t((Clear|Display)?|art|r(i(ng)?)?)|implify|ubtract(Milliseconds|Seconds)|e(nd(RawMessage|B(yte|lock)|Line)?|t(R(ollOverRegion|e(s(ize|olution)|c(tangle|eiveEol)))|X|M(i(n(imumTransferRate|ute)|llisecond)|o(nth|de(CaseSensitive)?)|ultiscreenBezel)|B(yteEventPort|o(olean|dy)|a(ckground(Bitmap|Color)|udRate))|S(t(andard|ring)|ub|e(ndEol|cond)|afeTextRegion)|H(o(stName|ur)|eight)|Y(ear)?|Name|C(hannelVolumes(Aux)?|ontrolValue|ursor(Bitmap|Pos(ition)?))|Time(Server|Zone)?|I(n(t|put)|P4(Gateway|Broadcast|Netmask|Address))|OutputState|D(HCP|omain|e(stination|fault(Mode|Transistion))|a(y(OfWeek)?|te(Time)?))|U(ser(Data|AndPassword)|tcDateTime|rl)|P(o(werSaveMode|rt)|assword|roxy)|E(ntry|cho|ol)|V(iewMode|olume(Aux)?)|F(o(nt|r(egroundColor|groundColor))|l(oat|ashRate))|W(holeState|i(dth|Fi(Passphrase|ESSID)))|L(ineEventPort|o(calDateTime|opMode)|auguage)|Audio(Mode(Aux)?|Stream(Aux)?|Output(Aux)?))|ek(Relative|ToEnd|Absolute)))|H(ide|ead|asAttribute)|N(ormalize|ext)|C(hr|ount|urrentPosition|l(s|ear(Region|Events)?))|T(o(Base64String|HexString|kenize|AsciiString)|estInter(netConnectivity|face)|rim)|I(s(MousePresent|N(ext|ame)|InputActive|Empty|Valid|LittleEndianCPU)|n(str|te(ger)|valid))|Object|D(ynamic|isplay(Preload|File(Ex)?)|o(uble|esExist)|elete)|U(n(shift|pack)|Case)|P(o(st(Message|From(String|File))|p(String(s)?)?)|ush(String)?|eek|lay(StaticImage|File)?|arse(String|File)?|reloadFile(Ex)?)|E(nable(R(ollover|egion)|Cursor|Input|Output)|xists)|Void|F(indIndex|unction|l(oat|ush)|rom(Base64String|HexString|AsciiString))|W(hile|aitMessage|rite(File)?)|L(ookup|e(n|ft))|A(s(ync(GetTo(String|File)|Head|PostFrom(String|File)|Flush)|c)?|tEof|dd(Re(ctangle(Region|_region)|place)|Milliseconds|BodyElement|Seconds|Head(er)?|CircleRegion|Tail|DNSServer|E(vent|lement(WithBody)?)|Attribute)|pp(end(String|File)?|ly))|ToStr)\\b)",
"name": "support.function.component.brs"
},
"class_roku_builtin": {
"match": "(?i:(?<=\")(roAppInfo|roAppManager|roAppMemoryMonitor|roAppMemoryMonitorEvent|roAppendFile|roArray|roAssetCollection|roAssetFetcher|roAssetFetcherEvent|roAssetFetcherProgressEvent|roAssetPool|roAssetPoolFiles|roAssetRealizer|roAssetRealizerEvent|roAssociativeArray|roAudioConfiguration|roAudioEvent|roAudioEventMx|roAudioGuide|roAudioMetadata|roAudioOutput|roAudioPlayer|roAudioPlayerEvent|roAudioPlayerMx|roAudioResource|roBitmap|roBlockCipher|roBoolean|roBrSub|roBrightPackage|roBtClient|roBtClientEvent|roBtClientManager|roBtClientManagerEvent|roBtManager|roByteArray|roCECStatus|roCECStatusEvent|roCanvasWidget|roCaptionRenderer|roCaptionRendererEvent|roCecInterface|roCecRxFrameEvent|roCecTxCompleteEvent|roChannelManager|roChannelStore|roChannelStoreEvent|roCharDisplay|roClockWidget|roCodeRegistrationScreen|roCodeRegistrationScreenEvent|roCompositor|roConfigurationElements|roControlDown|roControlPort|roControlUp|roCreateFile|roDataGramSocket|roDatagramEvent|roDatagramReceiver|roDatagramSender|roDatagramSocket|roDateTime|roDeviceCrypto|roDeviceCustomization|roDeviceInfo|roDeviceInfoEvent|roDiskErrorEvent|roDiskMonitor|roDouble|roDsa|roEVPCipher|roEVPDigest|roElectron|roElectronEvent|roFileSystem|roFileSystemEvent|roFloat|roFont|roFontMetrics|roFontRegistry|roFunction|roGPIOButton|roGPIOControlPort|roGlobal|roGpioButton|roGpioControlPort|roGridScreen|roGridScreenEvent|roHMAC|roHashGenerator|roHdmiHotPlugEvent|roHdmiInputChanged|roHdmiOutputChanged|roHdmiStatus|roHdmiStatusEvent|roHtmlWidget|roHtmlWidgetEvent|roHttpAgent|roHttpEvent|roHttpServer|roIRDownEvent|roIRRepeatEvent|roIRUpEvent|roIRReceiver|roIRRemote|roIRRemotePress|roIRTransmitCompleteEvent|roIRTransmitter|roImageBuffer|roImageCanvas|roImageCanvasEvent|roImageMetaData|roImageMetadata|roImagePlayer|roImageWidget|roInput|roInputEvent|roInt|roIntrinsicDouble|roInvalid|roJRE|roKeyStore|roKeyboard|roKeyboardPress|roKeyboardScreen|roKeyboardScreenEvent|roList|roListScreen|roListScreenEvent|roLocalization|roLongInteger|roMediaServer|roMediaStreamer|roMediaStreamerEvent|roMessageDialog|roMessageDialogEvent|roMessagePort|roMicrophone|roMicrophoneEvent|roMimeStream|roMimeStreamEvent|roNetworkAdvertisement|roNetworkAttached|roNetworkConfiguration|roNetworkDetached|roNetworkDiscovery|roNetworkHotplug|roNetworkStatistics|roNetworkTimeEvent|roNodeJs|roNodeJsEvent|roOneLineDialog|roOneLineDialogEvent|roOpenVpn|roParagraphScreen|roParagraphScreenEvent|roPassKey|roPath|roPinEntryDialog|roPinEntryDialogEvent|roPosterScreen|roPosterScreenEvent|roPowerEvent|roPowerManager|roProgramGuide|roPtp|roPtpEvent|roQuadravoxButton|roQuadravoxSNS5|roRSA|roRSSArticle|roRSSParser|roReadFile|roReadWriteFile|roRectangle|roRegex|roRegion|roRegistry|roRegistrySection|roRemoteInfo|roResourceManager|roRssArticle|roRssParser|roRtspStream|roRtspStreamEvent|roSGNode|roSGNodeEvent|roSGScreen|roSGScreenEvent|roScreen|roSearchHistory|roSearchScreen|roSearchScreenEvent|roSequenceMatchEvent|roSequenceMatcher|roSerialPort|roSlideShow|roSlideShowEvent|roSnmpAgent|roSnmpEvent|roSocketAddress|roSocketEvent|roSpringboardScreen|roSpringboardScreenEvent|roSprite|roSqliteDatabase|roSqliteEvent|roSqliteStatement|roStorageAttached|roStorageDetached|roStorageHotplug|roStorageInfo|roStreamByteEvent|roStreamConnectResultEvent|roStreamEndEvent|roStreamLineEvent|roStreamQueue|roStreamQueueEvent|roStreamSocket|roString|roSyncManager|roSyncManagerEvent|roSyncPool|roSyncPoolEvent|roSyncPoolFiles|roSyncPoolProgressEvent|roSyncSpec|roSystemLog|roSystemLogEvent|roSystemTime|roTCPConnectEvent|roTCPServer|roTCPStream|roTextField|roTextScreen|roTextScreenEvent|roTextToSpeech|roTextToSpeechEvent|roTextWidget|roTextWidgetEvent|roTextureManager|roTextureRequest|roTextureRequestEvent|roTimeSpan|roTimer|roTimerEvent|roTimespan|roTouchCalibrationEvent|roTouchEvent|roTouchScreen|roTuner|roTunerEvent|roUPnPActionResult|roUPnPController|roUPnPDevice|roUPnPSearchEvent|roUPnPService|roUPnPServiceEvent|roUniversalControlEvent|roUrlEvent|roUrlTransfer|roUsbFilesystem|roUsbHidEmulator|roUsbHidLedEmulatorEvent|roUsbPowerControl|roVideoEvent|roVideoInput|roVideoMode|roVideoPlayer|roVideoPlayerEvent|roVideoScreen|roVideoScreenEvent|roVirtualMemory|roWriteFile|roXMLElement|roXMLList)(?=\"))",
"name": "support.class.brs"
Expand Down