Skip to content

Commit 5f43ddd

Browse files
bugFix/syntax highlighting on AA function names (#627)
2 parents 61f141a + b2e2404 commit 5f43ddd

File tree

2 files changed

+295
-42
lines changed

2 files changed

+295
-42
lines changed

src/grammar/brightscript.tmLanguage.spec.ts

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,301 @@ describe('brightscript.tmlanguage.json', () => {
580580
`);
581581
});
582582

583+
it('handles function & variable declarations using reserved function names', async () => {
584+
await testGrammar(`
585+
thing = rnd
586+
' ^^^ entity.name.variable.local.brs
587+
' ^ keyword.operator.brs
588+
'^^^^^ entity.name.variable.local.brs
589+
`);
590+
591+
await testGrammar(`
592+
thing = rnd()
593+
' ^^^ entity.name.function.brs
594+
' ^ keyword.operator.brs
595+
'^^^^^ entity.name.variable.local.brs
596+
`);
597+
598+
await testGrammar(`
599+
thing = rnd
600+
' ^^^ entity.name.variable.local.brs
601+
' ^ keyword.operator.brs
602+
'^^^^^ entity.name.variable.local.brs
603+
604+
rnd = rnd
605+
' ^^^ entity.name.variable.local.brs
606+
' ^ keyword.operator.brs
607+
'^^^ entity.name.variable.local.brs
608+
`);
609+
610+
await testGrammar(`
611+
thing = rnd()
612+
' ^^^ entity.name.function.brs
613+
' ^ keyword.operator.brs
614+
'^^^^^ entity.name.variable.local.brs
615+
616+
rnd = rnd
617+
' ^^^ entity.name.variable.local.brs
618+
' ^ keyword.operator.brs
619+
'^^^ entity.name.variable.local.brs
620+
`);
621+
622+
await testGrammar(`
623+
rnd = rnd()
624+
' ^^^ entity.name.function.brs
625+
' ^ keyword.operator.brs
626+
'^^^ entity.name.variable.local.brs
627+
628+
rnd = rnd
629+
' ^^^ entity.name.variable.local.brs
630+
' ^ keyword.operator.brs
631+
'^^^ entity.name.variable.local.brs
632+
`);
633+
634+
await testGrammar(`
635+
sub rnd()
636+
' ^^^ entity.name.function.brs
637+
'^^^ keyword.declaration.function.brs
638+
639+
thing = rnd
640+
' ^^^ entity.name.variable.local.brs
641+
' ^ keyword.operator.brs
642+
'^^^^^ entity.name.variable.local.brs
643+
644+
rnd = rnd
645+
' ^^^ entity.name.variable.local.brs
646+
' ^ keyword.operator.brs
647+
'^^^ entity.name.variable.local.brs
648+
649+
end sub
650+
'^^^^^^^ keyword.declaration.function.brs
651+
`);
652+
653+
await testGrammar(`
654+
function rnd() as dynamic
655+
' ^^^^^^^ storage.type.brs
656+
' ^^ keyword.control.brs
657+
' ^^^ entity.name.function.brs
658+
'^^^^^^^^ keyword.declaration.function.brs
659+
660+
thing = rnd
661+
' ^^^ entity.name.variable.local.brs
662+
' ^ keyword.operator.brs
663+
'^^^^^ entity.name.variable.local.brs
664+
665+
rnd = rnd
666+
' ^^^ entity.name.variable.local.brs
667+
' ^ keyword.operator.brs
668+
'^^^ entity.name.variable.local.brs
669+
670+
return invalid
671+
' ^^^^^^^ constant.language.null.brs
672+
'^^^^^^ keyword.control.flow.return.brs
673+
674+
end function
675+
'^^^^^^^^^^^^ keyword.declaration.function.brs
676+
`);
677+
678+
await testGrammar(`
679+
sub nameless(rnd as dynamic)
680+
' ^^^^^^^ storage.type.brs
681+
' ^^ keyword.control.brs
682+
' ^^^ entity.name.variable.local.brs
683+
' ^^^^^^^^ entity.name.function.brs
684+
'^^^ keyword.declaration.function.brs
685+
686+
thing = rnd
687+
' ^^^ entity.name.variable.local.brs
688+
' ^ keyword.operator.brs
689+
'^^^^^ entity.name.variable.local.brs
690+
691+
rnd = rnd
692+
' ^^^ entity.name.variable.local.brs
693+
' ^ keyword.operator.brs
694+
'^^^ entity.name.variable.local.brs
695+
696+
end sub
697+
'^^^^^^^ keyword.declaration.function.brs
698+
`);
699+
700+
await testGrammar(`
701+
sub nameless(rnd = rnd as dynamic)
702+
' ^^^^^^^ storage.type.brs
703+
' ^^ keyword.control.brs
704+
' ^^^ entity.name.variable.local.brs
705+
' ^ keyword.operator.brs
706+
' ^^^ entity.name.variable.local.brs
707+
' ^^^^^^^^ entity.name.function.brs
708+
'^^^ keyword.declaration.function.brs
709+
710+
thing = rnd
711+
' ^^^ entity.name.variable.local.brs
712+
' ^ keyword.operator.brs
713+
'^^^^^ entity.name.variable.local.brs
714+
715+
rnd = rnd
716+
' ^^^ entity.name.variable.local.brs
717+
' ^ keyword.operator.brs
718+
'^^^ entity.name.variable.local.brs
719+
720+
end sub
721+
'^^^^^^^ keyword.declaration.function.brs
722+
`);
723+
724+
await testGrammar(`
725+
sub nameless(rnd = rnd() as dynamic)
726+
' ^^^^^^^ storage.type.brs
727+
' ^^ keyword.control.brs
728+
' ^^^ entity.name.function.brs
729+
' ^ keyword.operator.brs
730+
' ^^^ entity.name.variable.local.brs
731+
' ^^^^^^^^ entity.name.function.brs
732+
'^^^ keyword.declaration.function.brs
733+
734+
thing = rnd
735+
' ^^^ entity.name.variable.local.brs
736+
' ^ keyword.operator.brs
737+
'^^^^^ entity.name.variable.local.brs
738+
739+
rnd = rnd
740+
' ^^^ entity.name.variable.local.brs
741+
' ^ keyword.operator.brs
742+
'^^^ entity.name.variable.local.brs
743+
744+
end sub
745+
'^^^^^^^ keyword.declaration.function.brs
746+
`);
747+
748+
await testGrammar(`
749+
sub rnd(rnd = rnd as dynamic)
750+
' ^^^^^^^ storage.type.brs
751+
' ^^ keyword.control.brs
752+
' ^^^ entity.name.variable.local.brs
753+
' ^ keyword.operator.brs
754+
' ^^^ entity.name.variable.local.brs
755+
' ^^^ entity.name.function.brs
756+
'^^^ keyword.declaration.function.brs
757+
758+
thing = rnd
759+
' ^^^ entity.name.variable.local.brs
760+
' ^ keyword.operator.brs
761+
'^^^^^ entity.name.variable.local.brs
762+
763+
rnd = rnd
764+
' ^^^ entity.name.variable.local.brs
765+
' ^ keyword.operator.brs
766+
'^^^ entity.name.variable.local.brs
767+
768+
end sub
769+
'^^^^^^^ keyword.declaration.function.brs
770+
`);
771+
772+
await testGrammar(`
773+
sub rnd(randomVal as Dynamic, rnd as dynamic)
774+
' ^^^^^^^ storage.type.brs
775+
' ^^ keyword.control.brs
776+
' ^^^ entity.name.variable.local.brs
777+
' ^^^^^^^ storage.type.brs
778+
' ^^ keyword.control.brs
779+
' ^^^^^^^^^ entity.name.variable.local.brs
780+
' ^^^ entity.name.function.brs
781+
'^^^ keyword.declaration.function.brs
782+
783+
thing = rnd
784+
' ^^^ entity.name.variable.local.brs
785+
' ^ keyword.operator.brs
786+
'^^^^^ entity.name.variable.local.brs
787+
788+
rnd = rnd
789+
' ^^^ entity.name.variable.local.brs
790+
' ^ keyword.operator.brs
791+
'^^^ entity.name.variable.local.brs
792+
793+
end sub
794+
'^^^^^^^ keyword.declaration.function.brs
795+
`);
796+
797+
await testGrammar(`
798+
sub rnd(randomVal as Dynamic, rnd() as function)
799+
' ^^^^^^^^ storage.type.brs
800+
' ^^ keyword.control.brs
801+
' ^^^ entity.name.function.brs
802+
' ^^^^^^^ storage.type.brs
803+
' ^^ keyword.control.brs
804+
' ^^^^^^^^^ entity.name.variable.local.brs
805+
' ^^^ entity.name.function.brs
806+
'^^^ keyword.declaration.function.brs
807+
808+
thing = rnd
809+
' ^^^ entity.name.variable.local.brs
810+
' ^ keyword.operator.brs
811+
'^^^^^ entity.name.variable.local.brs
812+
813+
rnd = rnd
814+
' ^^^ entity.name.variable.local.brs
815+
' ^ keyword.operator.brs
816+
'^^^ entity.name.variable.local.brs
817+
818+
end sub
819+
'^^^^^^^ keyword.declaration.function.brs
820+
`);
821+
822+
await testGrammar(`
823+
val = {
824+
' ^ keyword.operator.brs
825+
'^^^ entity.name.variable.local.brs
826+
827+
rnd: sub()
828+
' ^^^ keyword.declaration.function.brs
829+
'^^^ entity.name.variable.local.brs
830+
831+
end sub
832+
'^^^^^^^ keyword.declaration.function.brs
833+
}
834+
`);
835+
836+
await testGrammar(`
837+
val = {
838+
' ^ keyword.operator.brs
839+
'^^^ entity.name.variable.local.brs
840+
841+
rnd: function() as dynamic
842+
' ^^^^^^^ storage.type.brs
843+
' ^^ keyword.control.brs
844+
' ^^^^^^^^ keyword.declaration.function.brs
845+
'^^^ entity.name.variable.local.brs
846+
847+
return invalid
848+
' ^^^^^^^ constant.language.null.brs
849+
'^^^^^^ keyword.control.flow.return.brs
850+
851+
end function
852+
'^^^^^^^^^^^^ keyword.declaration.function.brs
853+
}
854+
`);
855+
856+
await testGrammar(`
857+
val = {
858+
' ^ keyword.operator.brs
859+
'^^^ entity.name.variable.local.brs
860+
861+
rnd: {
862+
'^^^ entity.name.variable.local.brs
863+
864+
rnd: sub()
865+
' ^^^ keyword.declaration.function.brs
866+
'^^^ entity.name.variable.local.brs
867+
868+
end sub
869+
'^^^^^^^ keyword.declaration.function.brs
870+
}
871+
872+
end sub
873+
'^^^^^^^ keyword.declaration.function.brs
874+
}
875+
`);
876+
});
877+
583878
it('handles named public/protected/private function declarations', async () => {
584879
await testGrammar(`
585880
public sub write()

syntaxes/brightscript.tmLanguage.json

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@
133133
{
134134
"include": "#operators"
135135
},
136-
{
137-
"include": "#support_functions"
138-
},
139136
{
140137
"include": "#variables_and_params"
141138
},
@@ -947,49 +944,10 @@
947944
"match": "=|>=|<zz|>|<|<>|\\+|-|\\*|\\/|\\^|&|\\b(?i:(And|Not|Or|Mod))\\b",
948945
"name": "keyword.operator.brs"
949946
},
950-
"support_functions": {
951-
"patterns": [
952-
{
953-
"include": "#support_builtin_functions"
954-
},
955-
{
956-
"include": "#support_global_functions"
957-
},
958-
{
959-
"include": "#support_global_string_functions"
960-
},
961-
{
962-
"include": "#support_global_math_functions"
963-
},
964-
{
965-
"include": "#support_component_functions"
966-
}
967-
]
968-
},
969947
"global_constants": {
970948
"match": "(?i:\\b(line_num)\\b)",
971949
"name": "variable.language"
972950
},
973-
"support_builtin_functions": {
974-
"match": "(?i:\\b(GetLastRun(RuntimeError|CompileError)|Rnd|Box|Type|objfun|pos|eval)\\b)",
975-
"name": "support.function.brs"
976-
},
977-
"support_global_functions": {
978-
"match": "(?i:\\b(Re(adAsciiFile|bootSystem)|GetInterface|MatchFiles|Sleep|C(opyFile|reate(Directory|Object))|Delete(Directory|File)|UpTime|FormatDrive|ListDir|W(ait|riteAsciiFile))\\b)",
979-
"name": "support.function.brs"
980-
},
981-
"support_global_string_functions": {
982-
"match": "(?i:\\b(Right|Mid|Str(i(ng(i)?)?)?|Chr|Instr|UCase|Val|Asc|L(Case|e(n|ft)))\\b)",
983-
"name": "support.function.brs"
984-
},
985-
"support_global_math_functions": {
986-
"match": "(?i:\\b(S(in|qr|gn)|C(sng|dbl|os)|Tan|Int|Exp|Fix|Log|A(tn|bs))\\b)",
987-
"name": "support.function.brs"
988-
},
989-
"support_component_functions": {
990-
"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)",
991-
"name": "support.function.component.brs"
992-
},
993951
"class_roku_builtin": {
994952
"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)(?=\"))",
995953
"name": "support.class.brs"

0 commit comments

Comments
 (0)