Skip to content

Commit 85641da

Browse files
authored
fix: handle words starting with "this" e.g. thisAccount (#48)
Was ignoring thisA and highlighting ccount
1 parent 8d2bad4 commit 85641da

File tree

4 files changed

+45
-46
lines changed

4 files changed

+45
-46
lines changed

demo/testcode.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
Map<Id, CustomObject__c> myMap = new Map<Id, CustomObject__c>([SELECT Id FROM CustomObject__c WHERE Id NOT IN :newRecordsMap.keySet()]);
2626
Map<Id, String> myMap = new Map<Id, String>{a => b, c => d};
2727

28-
delete myAccount;
28+
delete thisAccount;
2929
Account a;
3030
String s;
3131
delete [SELECT Id FROM Account];
@@ -51,10 +51,10 @@
5151

5252
public List<SelectOption> recordTypes { get; private set; }
5353

54-
Database.insert(myAccounts, false, AccessLevel.USER_MODE);
55-
delete myAccount;
54+
Database.insert(thisAccounts, false, AccessLevel.USER_MODE);
55+
delete thisAccount;
5656
delete [SELECT Id FROM Account];
57-
myAcct = (Account)myacct;
57+
thisAcct = (Account)thisAcct;
5858

5959
public String myString { get; set; }
6060

@@ -517,7 +517,7 @@
517517
Boolean ai = (Boolean) false;
518518
System.debug('Should not be called');
519519
if (1 > 5) { // wtf!?
520-
Database.insert(myAccounts);
520+
Database.insert(thisAccounts);
521521
}
522522
}
523523

dist/apex.es.min.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ relevance:0}];function l(...e){return t.concat("(?!",e.join("|"),")")}const p={
66
scope:"number",
77
match:t.either(/\b(\d{4}\-\d{2}\-\d{2}T\d{2}\:\d{2}\:\d{2}(\.\d{1,3})?(\-|\+)\d{2}\:\d{2})\b/,/\b(\d{4}\-\d{2}\-\d{2}T\d{2}\:\d{2}\:\d{2}(\.\d{1,3})?(Z)?)\b/,/\b(\d{4}\-\d{2}\-\d{2})\b/,/\b0(x|X)[0-9a-fA-F_]+(U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?\b/,/\b0(b|B)[01_]+(U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?\b/,/\b([0-9]+)?\.[0-9]+((e|E)[0-9]+)?(F|f|D|d|M|m)?\b/,/(-?)\b[0-9]+(e|E)[0-9]+(F|f|D|d|M|m)?\b/,/(-?)\b[0-9]+(F|f|D|d|M|m)\b/,/(-?)\b[0-9]+(U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?\b/,/(-?)(\b0[0-9]+|(\b\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)/),
88
relevance:0
9-
},b=["try","catch","finally","get","set","put","if","for","else","do","while","continue","break","implements","extends","return","throw","when","new"],u=["instanceof","super","this"],d=["abstract","final","global","override","private","protected","public","static","testMethod","transient","virtual","webservice"],m=["anytype|0","blob|0","boolean|0","byte|0","currency|0","date|0","datetime|0","decimal|0","double|0","enum|0","float|0","integer|0","long|0","object|0","pagereference|8","selectoption|8","short|0","sobject|10","string|0","time|0","void|0","float|0"],E=["insert","update","upsert","delete","undelete","merge","convertLead"],A=["AppLauncher","Approval","Auth","Cache","Canvas","ChatterAnswers","CommercePayments","ConnectApi","Database","Datacloud","Dataweave","DataSource","Dom","EventBus","ExternalService","Flow","Functions","Invocable","KbManagement","LxScheduler","Messaging","Metadata","Pref_center","Process","QuickAction","Reports","RichMessageing","Schema","Search","Sfc","Sfdc_Checkout","sfdc_surveys","Site","Support","System","TerritoryMgmt","TxnSecurity","UserProvisioning","VisualEditor","Wave"],h=["AccessLevel","Address","Answers","ApexPages","Approval","Assert","AsyncInfo","AsyncOptions","BusinessHours","Cases","Collator","Continuation","Cookie","Crypto","Database","Date","Datetime","Decimal","Domain","DomainCreator","DomainParser","EmailMessages","EncodingUtil","EventBus","Exception","FeatureManagement","FlexQueue","Formula","FormulaRecalcFieldError","FormulaRecalcResult","Http","HttpRequest","HttpResponse","Ideas","JSON","JSONGenerator","JSONParser","Label","Limits","Location","Matcher","Math","Messaging","MultiStaticResourceCalloutMock","Network","OrgLimit","OrgLimits","Packaging","PageReference","Pattern","QueueableDuplicateSignature","QueueableDuplicateSignature.Builder","QuickAction","Request","ResetPasswordResult","RestContext","RestRequest","RestResponse","Search","Security","SelectOption","Site","SObject","SObjectAccessDecision","StaticResourceCalloutMock","Test","TimeZone","Type","URL","UserInfo","UserManagement","Version","WebServiceCallout","XmlStreamReader","XmlStreamWriter"],v=["AccessType","AccessLevel","DomainType","JSONToken","LoggingLevel","Quiddity","TriggerOperation","operationType"],S=["false","true","null"],g={
9+
},b=["try","catch","finally","get","set","put","if","for","else","do","while","continue","break","implements","extends","return","throw","when","new"],u=["instanceof","super","this"],d=["abstract","final","global","override","private","protected","public","static","testMethod","transient","virtual","webservice"],m=["anytype|0","blob|0","boolean|0","byte|0","currency|0","date|0","datetime|0","decimal|0","double|0","enum|0","float|0","integer|0","long|0","object|0","pagereference|8","selectoption|8","short|0","sobject|10","string|0","time|0","void|0","float|0"],E=["insert","update","upsert","delete","undelete","merge","convertLead"],A=["AppLauncher","Approval","Auth","Cache","Canvas","ChatterAnswers","CommercePayments","ConnectApi","Database","Datacloud","Dataweave","DataSource","Dom","EventBus","ExternalService","Flow","Functions","Invocable","KbManagement","LxScheduler","Messaging","Metadata","Pref_center","Process","QuickAction","Reports","RichMessageing","Schema","Search","Sfc","Sfdc_Checkout","sfdc_surveys","Site","Support","System","TerritoryMgmt","TxnSecurity","UserProvisioning","VisualEditor","Wave"],h=["AccessLevel","Address","Answers","ApexPages","Approval","Assert","AsyncInfo","AsyncOptions","BusinessHours","Cases","Collator","Continuation","Cookie","Crypto","Database","Date","Datetime","Decimal","Domain","DomainCreator","DomainParser","EmailMessages","EncodingUtil","EventBus","Exception","FeatureManagement","FlexQueue","Formula","FormulaRecalcFieldError","FormulaRecalcResult","Http","HttpRequest","HttpResponse","Ideas","JSON","JSONGenerator","JSONParser","Label","Limits","Location","Matcher","Math","Messaging","MultiStaticResourceCalloutMock","Network","OrgLimit","OrgLimits","Packaging","PageReference","Pattern","QueueableDuplicateSignature","QueueableDuplicateSignature.Builder","QuickAction","Request","ResetPasswordResult","RestContext","RestRequest","RestResponse","Search","Security","SelectOption","Site","SObject","SObjectAccessDecision","StaticResourceCalloutMock","Test","TimeZone","Type","URL","UserInfo","UserManagement","Version","WebServiceCallout","XmlStreamReader","XmlStreamWriter"],v=["AccessType","AccessLevel","DomainType","JSONToken","LoggingLevel","Quiddity","TriggerOperation","operationType"],S=["false","true","null"],R={
1010
match:/,/,scope:"punctuation",relevance:0
11-
},R=[/--/,/\+\+/,/\&\&|\|\|/,/\*\=|\/\=|\%\=|\+\=|-\=/,/\&\=|\^\=|<<\=|>>\=|>>>\=|\|\=/,/\&|~|\^|\|/,/<<|>>/,/<\=|>\=|\s(<|>)\s/,/\=\=|!\=/,/\=>/,/!(?=\w)/,/(?<=\s)(\?|:)(?=\s)/,r,/(?<!\?)\?(?!\?|\.|\[)/,/%[^%]|\*[^\/]|\/[^\/\*]|(?<!\-)\-(?!\-)|(?<!\+)\+(?!\+)/,/(?<!\=|!)\=(?!\=|>)/],T=A.concat(...h),y={
12-
$pattern:t.concat(/(?<!\.)\b/,a,/(?!\s*\()/),keyword:[...b,...d,...E],
13-
"variable.language":u,type:m,literal:S
11+
},T=[/--/,/\+\+/,/\&\&|\|\|/,/\*\=|\/\=|\%\=|\+\=|-\=/,/\&\=|\^\=|<<\=|>>\=|>>>\=|\|\=/,/\&|~|\^|\|/,/<<|>>/,/<\=|>\=|\s(<|>)\s/,/\=\=|!\=/,/\=>/,/!(?=\w)/,/(?<=\s)(\?|:)(?=\s)/,r,/(?<!\?)\?(?!\?|\.|\[)/,/%[^%]|\*[^\/]|\/[^\/\*]|(?<!\-)\-(?!\-)|(?<!\+)\+(?!\+)/,/(?<!\=|!)\=(?!\=|>)/],g=A.concat(...h),y={
12+
$pattern:t.concat(/(?<!\.)\b/,a,/\b/),keyword:[...b,...d,...E],type:m,literal:S
1413
},L=[...S,...b,...d,...A,...h,...v,...u,...E],N={
1514
match:t.concat(/\b/,t.either(...u),/\b/),scope:"variable.language",relevance:0
1615
},O=[{match:[t.concat(/\b/,t.either(...v)),/\./,a,/\b\s*(?![\.\(])/],scope:{
17-
1:"built_in",2:"punctuation",3:"variable"},relevance:0},{
16+
1:"built_in",2:"punctuation",3:"variable1"},relevance:0},{
1817
match:[t.concat(/\b/,t.either(...h)),/\./,a,/\b\s*(?![\.\(])/],scope:{
1918
1:"built_in",2:"punctuation",3:"type"},relevance:0},{
20-
match:[t.concat(/\b/,t.either(...A)),/\./,t.concat(c,/\b(?=\.)/)],scope:{
21-
1:"built_in",2:"punctuation",3:"type"}},{
19+
match:[t.concat(/\b/,t.either(...A)),/\./,c,/\b(?=\.)/],scope:{1:"built_in",
20+
2:"punctuation",3:"type"}},{
2221
match:[t.concat(/\b/,t.either(...A,...h)),/\./,c,/\b(?!\.)/],scope:{
2322
1:"built_in",2:"punctuation",3:"keyword"}},{
2423
match:[/\bTrigger\b/,/\./,/(isExecuting|isInsert|isUpdate|isDelete|isBefore|isAfter|isUndelete|new|newMap|old|oldMap|size|operationType)\b(?!\.)/],
@@ -27,16 +26,16 @@ match:[/\btrigger\b/,/\./,"operationtype",/\./,t.concat(c,/\b/)],scope:{
2726
1:"built_in",2:"punctuation",3:"keyword",4:"punctuation",5:"variable.constant"},
2827
relevance:10}],w=[{
2928
match:t.either(",",/;/,/(?<=\w)\>/,/\<(?=\w)/,/\{|\}/,/\(|\)/,/\{|\}/),
30-
scope:"punctuation",relevance:0},g],C=e.inherit(e.APOS_STRING_MODE,{
29+
scope:"punctuation",relevance:0},R],C=e.inherit(e.APOS_STRING_MODE,{
3130
scope:"string",relevance:0,contains:[{match:/\\'/,scope:"literal",relevance:0}]
3231
}),D=e.COMMENT("//",/[$\n]/,{relevance:0}),I=[e.COMMENT("/\\*","\\*/",{
3332
relevance:0,contains:[{begin:/\w+@/,relevance:0},{
3433
match:[/@(?:exception|throws)/,s,a],scope:{1:"doctag",3:"title.class"},
3534
relevance:0},{begin:"@[A-Za-z_-]+",scope:"doctag",relevance:0},{
36-
match:[/(?<=@param)\s+/,a],scope:{2:"variable"},relevance:0},{excludeBegin:!0,
35+
match:[/(?<=@param)\s+/,a],scope:{2:"variable2"},relevance:0},{excludeBegin:!0,
3736
excludeEnd:!0,contains:[e.BACKSLASH_ESCAPE],relevance:0,variants:[{begin:"`",
3837
end:"`",scope:"subst"},{begin:/'/,end:/'/,scope:"string"}]}]}),D],_={
39-
match:t.either(...R),scope:"operator",relevance:0},U={match:/(?<!\.)\bId\b/,
38+
match:t.either(...T),scope:"operator",relevance:0},U={match:/(?<!\.)\bId\b/,
4039
scope:"type",relevance:8},f=[{begin:/\b(list|set|map)(?=\s*<)/,
4140
beginScope:"type",end:/\>+/,endScope:"punctuation",contains:[{match:/\<|\,/,
4241
scope:"punctuation"},{match:c,scope:"type"}],relevance:8},{
@@ -47,7 +46,7 @@ match:[t.optional(c),/\[/,t.optional(/\d+/),/\]/],scope:{1:"variable",
4746
},end:/\)/,endScope:"punctuation",contains:[{match:[c,/\s*=/],scope:{
4847
1:"keyword",2:"operator"},contains:[_]},C,p],keywords:{literal:S}}],k={
4948
match:[/\b[a-zA-Z0-9\.]*Exception/,s,a],scope:{1:"type",3:"variable"},
50-
relevance:0},F={match:[/(?<!\.)/,c,/\s*(?=\=[^\>])/],scope:{2:"variable"},
49+
relevance:0},F={match:[/(?<!\.)/,c,/\s*(?=\=[^\>])/],scope:{2:"variable3"},
5150
relevance:0},P={match:[/(?<=\=\s*\()/,a,"(?=\\)\\s*"+a+")"],scope:{2:"type"},
5251
relevance:0},Y={match:[/\bnew\s+/,a,o],scope:{2:"type"},relevance:0};let W={
5352
scope:"params_call",begin:/\(/,beginScope:"punctuation",end:/\)/,
@@ -58,10 +57,10 @@ contains:[...i],starts:W},{match:[/^\s*/,l(...b),a,o],scope:{
5857
;W.contains=[C,Y,I,_,f,O,p,U,x,{keywords:{KEYWORDS:y},
5958
match:t.concat(/(?<=\s|\(|\,)/,l(...S),a,/\b/,/(?!\.)/),scope:"variable",
6059
relevance:0},{match:/\(|\,|\./,scope:"punctuation",relevance:0},{match:a,
61-
scope:"variable"}];const H={scope:"params",end:/\)/,endScope:"punctuation",
60+
scope:"variable4"}];const H={scope:"params",end:/\)/,endScope:"punctuation",
6261
relevance:1,keywords:y,contains:[p,C,I,f,...O,{match:/\,|\(/,scope:"punctuation"
6362
},U,{match:[/(?<=\(|\,)\s*/,a,/(?=\s)/],scope:{2:"type"}},{
64-
match:[s,a,/\s*(?=[,)])/],scope:{2:"variable"}}]},G={
63+
match:[s,a,/\s*(?=[,)])/],scope:{2:"variable5"}}]},G={
6564
match:[/\bswitch\s+on\s+/,a],scope:{1:"keyword",2:"variable"}};return{
6665
name:"Apex",aliases:["apex","lightning","soql"],case_insensitive:!0,
6766
disableAutodetect:!1,ignoreIllegals:!1,keywords:y,
@@ -70,7 +69,7 @@ contains:[I,M,C,p,P,f,[{begin:[/\btrigger/,s,a,s,"on",s,a],beginScope:{
7069
1:"keyword",3:"title.class",5:"operator",7:"type"},end:/(?=\{)/,returnEnd:!0,
7170
contains:[I,{begin:/\(/,end:/\)/,contains:[{
7271
match:/\b(before|after)\s+(insert|update|delete|merge|undelete)\b/,
73-
scope:"keyword",relevance:5},g]}]},{relevance:5,
72+
scope:"keyword",relevance:5},R]}]},{relevance:5,
7473
match:/\b(with|without|inherited)\s+sharing\b/,scope:"keyword"},{
7574
begin:[/(?!\.)/,/\b(class|interface)\b(?!\?|\.)/],beginScope:{2:"keyword"},
7675
end:/(?=\{)/,relevance:1,keywords:{type:m,keyword:b},contains:[{
@@ -80,15 +79,15 @@ match:[c,/(?=\.)/],scope:{1:"built_in"}},{match:t.concat(c,/(?=\>)/),
8079
scope:"type"},{match:c,scope:"title.class.inherited"},{match:/<|>|,/,
8180
scope:"punctuation"},O],relevance:0}]},{begin:[/\benum\s+/,a,/\s*\{/],
8281
beginScope:{2:"type",3:"punctuation"},end:/\}/,endScope:"punctuation",
83-
relevance:0,contains:[I,g,{match:t.concat(c),scope:"variable.constant"}]},{
82+
relevance:0,contains:[I,R,{match:t.concat(c),scope:"variable.constant"}]},{
8483
match:[/(public|private|protected)\s+/,a,o],scope:{1:"keyword",
8584
2:"title.function"},starts:H,relevance:1},{
8685
match:[/(?<!new)(?<!return)(?<=\<|\>|\w)\s+/,a,o],scope:{2:"title.function"},
8786
relevance:1,starts:H}],[{match:/as\s+(user|system)\b/,scope:"keyword"}],k,{
8887
match:[/\bfor\b\s*/,/\(/,a,s,a,/\s*/,/:/],scope:{3:"type",5:"variable",
8988
7:"operator"}},x,Y,N,O,U,{begin:[/\[/,/\s*(?=(SELECT|FIND)\b)/],end:/\]/,
9089
beginScope:{1:"punctuation"},endScope:"punctuation",scope:"soql",relevance:10,
91-
endsWithParent:!0,keywords:{literal:y.literal,built_in:T},contains:[p,_,C,g,{
90+
endsWithParent:!0,keywords:{literal:y.literal,built_in:g},contains:[p,_,C,R,{
9291
match:/\(|\)/,scope:"punctuation",relevance:0},...i,{begin:[/\bFROM\b/,s],
9392
beginScope:{1:"keyword"},end:/(?=\bWHERE\b|\]|\s|\))/,contains:[{match:a,
9493
scope:"type"},...i]},{
@@ -100,9 +99,9 @@ scope:"keyword",relevance:8},{
10099
match:[/(NEXT|LAST)_N_(DAY|FISCAL_QUARTER|FISCAL_YEAR|MONTH|QUARTER|WEEK|YEAR)S/,/\s*:\s*/,/\d+/],
101100
scope:{1:"keyword",2:"operator",3:"number"},relevance:8},{
102101
match:t.concat(/\b/,t.either(...y.keyword,"ABOVE_OR_BELOW","ABOVE","ACTIVE","ADVANCED","ALL","ANY","ARRAY","AS","ASC","BELOW","CATEGORY","CONTAINS","CUSTOM","DATA","DESC","DIVISION","ELSE","END","FIND","FROM","METADATA","NETWORK","ON","PricebookId","RETURNING","ROLLUP","ROWS","SEARCH","SECURITY_ENFORCED","SELECT","SNIPPET","SORT","SPELL_CORRECTION","STANDARD","THEN","USER_MODE","USING","WHEN","WHERE","WITH","SCOPE","Delegated","Everything","Mine","My_Territory","My_Team_Territory","Team","AND","AT","FIRST","FOR","HAVING","IN","LAST","LIKE","LIMIT","LISTVIEW","NOT","NULLS","OFFSET","OR","REFERENCE","TRACKING","TYPEOF","UPDATE","VIEW","VIEWSTAT"),/\b/),
103-
scope:"keyword"},{match:[/(?<=:)/,/\s*/,c,/(?!\()/],scope:{3:"variable"},
102+
scope:"keyword"},{match:[/(?<=:)/,/\s*/,c,/(?!\()/],scope:{3:"variable6"},
104103
relevance:0},{match:[/(?<=:|\.)/,a,/(?=\s*\()/],scope:{2:"title.function.invoke"
105104
},relevance:0},{match:/:/,scope:"operator",relevance:0}],illegal:"::"
106-
},G,F,_,w,i,{match:t.concat("(?<=this.)",a,"(?!\\()"),scope:"variable"},{
105+
},G,F,_,w,i,{match:t.concat("(?<=this.\b)",a,"(?!\\()"),scope:"variable7"},{
107106
match:[t.concat(/\b/,l(...L)),a,s,/(?=\{)/],scope:{2:"property"},relevance:0}]}}
108107
})();export default hljsGrammar;

0 commit comments

Comments
 (0)