From b8e8a6f5700ab53107757fef6f510035cbbec0d5 Mon Sep 17 00:00:00 2001 From: David Schach <636977+dschach@users.noreply.github.com> Date: Mon, 6 Nov 2023 21:16:45 -0800 Subject: [PATCH] refactor: rearrange modules to better order for parsing (#30) --- dist/apex.es.min.js | 145 +++++++++-------- dist/apex.min.js | 139 ++++++++-------- src/languages/apex.js | 210 ++++++++++++++----------- test/markup/apex/apexcode.expected.txt | 12 +- 4 files changed, 277 insertions(+), 229 deletions(-) diff --git a/dist/apex.es.min.js b/dist/apex.es.min.js index b2728d8..1b647d1 100644 --- a/dist/apex.es.min.js +++ b/dist/apex.es.min.js @@ -1,105 +1,112 @@ /*! `apex` grammar compiled for Highlight.js 11.9.0 */ var hljsGrammar=(()=>{"use strict";return e=>{ -const t=e.regex,a="[a-zA-Z][a-zA-Z_0-9]*",n="\\b"+a+"\\b",c="@"+a,o=/(?=\s*\()/,s=/\s+/,r=/\?\.\b/,i=[{ +const t=e.regex,a="[a-zA-Z][a-zA-Z_0-9]*",c="\\b"+a+"\\b",n="@"+a,s=/(?=\s*\()/,o=/\s+/,r=/\?\./,i=[{ match:/(?>\=|>>>\=|\|\=/,/\&|~|\^|\|/,/<<|>>/,/<\=|>\=|\s(<|>)\s/,/\=\=|!\=/,/\=>/,/!(?=\w)/,/(?<=\s)(\?|:)(?=\s)/,r,/(?)/],S=m.concat("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={ -$pattern:t.concat(/(?>\=|>>>\=|\|\=/,/\&|~|\^|\|/,/<<|>>/,/<\=|>\=|\s(<|>)\s/,/\=\=|!\=/,/\=>/,/!(?=\w)/,/(?<=\s)(\?|:)(?=\s)/,r,/(?)/],g=A.concat(...h),y={ +$pattern:t.concat(/(?/,/\<(?=\w)/,/\{|\}/,/\(|\)/,/\{|\}/), -scope:"punctuation",relevance:0},A],y=e.inherit(e.APOS_STRING_MODE,{ +scope:"punctuation",relevance:0},T],D=e.inherit(e.APOS_STRING_MODE,{ scope:"string",relevance:0,contains:[{match:/\\'/,scope:"literal",relevance:0}] -}),O=e.COMMENT("//",/[$\n]/,{relevance:0}),L=[e.COMMENT("/\\*","\\*/",{ +}),w=e.COMMENT("//",/[$\n]/,{relevance:0}),I=[e.COMMENT("/\\*","\\*/",{ relevance:0,contains:[{begin:/\w+@/,relevance:0},{ -match:[/@(?:exception|throws)/,s,a],scope:{1:"doctag",3:"title.class"}, +match:[/@(?:exception|throws)/,o,a],scope:{1:"doctag",3:"title.class"}, relevance:0},{begin:"@[A-Za-z_-]+",scope:"doctag",relevance:0},{ match:[/(?<=@param)\s+/,a],scope:{2:"variable"},relevance:0},{begin:"`",end:"`", -scope:"string",contains:[e.BACKSLASH_ESCAPE],relevance:0}]}),O],N={ -match:t.either(...h),scope:"operator",relevance:0},w={match:/(?+/,endScope:"punctuation",contains:[{match:/\<|\,/, -scope:"punctuation"},{match:n,scope:"type"}],relevance:8},{ -match:[t.optional(n),/\[/,t.optional(/\d+/),/\]/],scope:{1:"variable", +scope:"punctuation"},{match:c,scope:"type"}],relevance:8},{ +match:[t.optional(c),/\[/,t.optional(/\d+/),/\]/],scope:{1:"variable", 2:"punctuation",3:"number",4:"punctuation"}},{match:[a,/\[\]/],scope:{1:"type", -2:"punctuation"},relevance:0}],D=[{match:t.concat(c,/\b(?!\s*\()/),scope:"meta" -},{scope:"meta",begin:[t.concat(c,/\b/),/\s*/,/\(/],beginScope:{3:"punctuation" -},end:/\)/,endScope:"punctuation",contains:[{match:[n,/\s*=/],scope:{ -1:"keyword",2:"operator"},contains:[N]},y,p],keywords:{literal:E}}],I={ -match:[/\b[a-zA-Z0-9\.]*Exception/,s,a],scope:{1:"title.class",3:"variable"}, -relevance:0},_={match:[/(?])/],scope:{2:"variable"}, -relevance:0},U={match:[/(?<=\=\s*\()/,a,"(?=\\)\\s*"+a+")"],scope:{2:"type"}, -relevance:0},M={match:[/\bnew\s+/,a,o],scope:{2:"type"},relevance:0},f={ -begin:/\((?!(\s*\[))/,beginScope:"punctuation",end:/\)/,endScope:"punctuation", -relevance:0,keywords:v,contains:[y,M,L,N,C,R,p,w,{keywords:{KEYWORDS:v}, -match:t.concat(/(?<=\s|\(|\,)/,l(...E),a,/\b/,/(?!\.)/),scope:"variable", -relevance:0},{match:/\,|\./,scope:"punctuation",relevance:0}]},k=[{ -match:[t.concat(/\b/,l(...S)),/\??(?<=\.)/,a,o],scope:{3:"title.function.invoke" -},relevance:0},{match:[/^\s*/,l(...b),a,o],scope:{3:"title.function.invoke"}, -relevance:0}],F={scope:"params",end:/\)/,endScope:"punctuation",relevance:0, -keywords:v,illegal:b,contains:[p,y,L,C,...R,{match:/\,|\(/,scope:"punctuation" -},w,{match:[/(?<=\(|\,)\s*/,a,/(?=\s)/],scope:{2:"type"}},{ -match:[s,a,/\s*(?=[,)])/],scope:{2:"variable"}}]},Y=[{ -begin:[/\btrigger/,s,a,s,"on",s,a],beginScope:{1:"keyword",3:"title.class", -5:"operator",7:"type"},end:/(?=\{)/,returnEnd:!0,contains:[L,{begin:/\(/, +2:"punctuation"},relevance:0}],f=[{match:t.concat(n,/\b(?!\s*\()/),scope:"meta" +},{scope:"meta",begin:[t.concat(n,/\b/),/\s*/,/\(/],beginScope:{3:"punctuation" +},end:/\)/,endScope:"punctuation",contains:[{match:[c,/\s*=/],scope:{ +1:"keyword",2:"operator"},contains:[_]},D,p],keywords:{literal:S}}],k={ +match:[/\b[a-zA-Z0-9\.]*Exception/,o,a],scope:{1:"title.class",3:"variable"}, +relevance:0},F={match:[/(?])/],scope:{2:"variable"}, +relevance:0},Y={match:[/(?<=\=\s*\()/,a,"(?=\\)\\s*"+a+")"],scope:{2:"type"}, +relevance:0},P={match:[/\bnew\s+/,a,s],scope:{2:"type"},relevance:0};let W={ +scope:"params_call",begin:/\(/,beginScope:"punctuation",end:/\)/, +endScope:"punctuation",relevance:0,keywords:y,contains:[]};const H=[{ +match:[/(?<=\.)/,a,s],scope:{2:"title.function.invoke"},relevance:1, +contains:[...i],starts:W},{match:[/^\s*/,l(...b),a,s],scope:{ +3:"title.function.invoke"},relevance:1,starts:W}] +;W.contains=[D,P,I,_,M,N,p,U,H,{keywords:{KEYWORDS:y}, +match:t.concat(/(?<=\s|\(|\,)/,l(...S),a,/\b/,/(?!\.)/),scope:"variable", +relevance:0},{match:/\(|\,|\./,scope:"punctuation",relevance:0},{match:a, +scope:"variable"}];const x={scope:"params",end:/\)/,endScope:"punctuation", +relevance:1,keywords:y,contains:[p,D,I,M,...N,{match:/\,|\(/,scope:"punctuation" +},U,{match:[/(?<=\(|\,)\s*/,a,/(?=\s)/],scope:{2:"type"}},{ +match:[o,a,/\s*(?=[,)])/],scope:{2:"variable"}}]},G=[{ +begin:[/\btrigger/,o,a,o,"on",o,a],beginScope:{1:"keyword",3:"title.class", +5:"operator",7:"type"},end:/(?=\{)/,returnEnd:!0,contains:[I,{begin:/\(/, end:/\)/,contains:[{ match:/\b(before|after)\s+(insert|update|delete|merge|undelete)\b/, -scope:"keyword",relevance:5},A]}]},{relevance:5, +scope:"keyword",relevance:5},T]}]},{relevance:5, match:/\b(with|without|inherited)\s+sharing\b/,scope:"keyword"},{ begin:[/(?!\.)/,/\bclass\b(?!\?|\.)/],beginScope:{2:"keyword"},end:/(?=\{)/, -relevance:1,keywords:{type:d,keyword:b},contains:[{match:[/(?<=\bclass)\s+/,a], +relevance:1,keywords:{type:m,keyword:b},contains:[{match:[/(?<=\bclass)\s+/,a], scope:{2:"title.class"}},{returnEnd:!0,endsWithParent:!0, -beginKeywords:"implements extends",end:/\{/,contains:[R,{match:[n,/(?=\.)/], -scope:{1:"built_in"}},{match:t.concat(n,/(?=>)/),scope:"type"},{ +beginKeywords:"implements extends",end:/\{/,contains:[{ match:t.concat(/\b/,t.either("schedulable","batchable","queueable","comparable","callable"),/\b\s*(?!>)/), -scope:"title.class.inherited",relevance:8},{match:t.concat(n,/(?!<)/), -scope:"title.class.inherited"},{match:/<|>|,/,scope:"punctuation"}],relevance:0 -}]},{begin:[/\benum\s+/,a,/\s*\{/],beginScope:{2:"type",3:"punctuation"}, -end:/\}/,endScope:"punctuation",relevance:0,contains:[L,A,{match:t.concat(n), -scope:"variable.constant"}]},{match:[/(public|private|protected)\s+/,a,o], -scope:{1:"keyword",2:"title.function"},starts:F,relevance:0},{ -match:[/(?|\w)\s+/,a,o],scope:{2:"title.function"}, -relevance:0,starts:F}],P={match:[/\bswitch\s+on\s+/,a],scope:{1:"keyword", -2:"variable"}},W={ -keyword:[].concat(...v.keyword).concat("ABOVE_OR_BELOW","ACTIVE","ADVANCED","ALL","ANY","ARRAY","AS","ASC","BY","CATEGORY","CONTAINS","CUSTOM","DATA","DESC","DIVISION","END","FIELDS","FIND","FROM","LAST","METADATA","NETWORK","ON","ORDER","RETURNING","ROLLUP","ROWS","SEARCH","SELECT","SNIPPET","SORT","SPELL_CORRECTION","STANDARD","USER_MODE","WHERE","PricebookId","WITH","SECURITY_ENFORCED","USING","SCOPE","Delegated","Everything","Mine","My_Territory","My_Team_Territory","Team","TYPEOF","ELSE","END","THEN","WHEN").concat("ABOVE","AND","AT","BY","CATEGORY","DATA","FIRST","FOR","GROUP","HAVING","IN","LAST","LIKE","LIMIT","LISTVIEW","NOT","NULLS","OFFSET","OR","REFERENCE","TRACKING","TYPEOF","UPDATE","UPDATE","VIEW","VIEWSTAT"), +scope:"title.class.inherited",relevance:8},{match:[c,/(?=\.)/],scope:{ +1:"built_in"}},{match:t.concat(c,/(?=\>)/),scope:"type"},{match:c, +scope:"title.class.inherited"},{match:/<|>|,/,scope:"punctuation"},N], +relevance:0}]},{begin:[/\benum\s+/,a,/\s*\{/],beginScope:{2:"type", +3:"punctuation"},end:/\}/,endScope:"punctuation",relevance:0,contains:[I,T,{ +match:t.concat(c),scope:"variable.constant"}]},{ +match:[/(public|private|protected)\s+/,a,s],scope:{1:"keyword", +2:"title.function"},starts:x,relevance:1},{ +match:[/(?|\w)\s+/,a,s],scope:{2:"title.function"}, +relevance:1,starts:x}],B={match:[/\bswitch\s+on\s+/,a],scope:{1:"keyword", +2:"variable"}},K={ +keyword:[].concat(...y.keyword).concat("ABOVE_OR_BELOW","ACTIVE","ADVANCED","ALL","ANY","ARRAY","AS","ASC","BY","CATEGORY","CONTAINS","CUSTOM","DATA","DESC","DIVISION","END","FIELDS","FIND","FROM","LAST","METADATA","NETWORK","ON","ORDER","RETURNING","ROLLUP","ROWS","SEARCH","SELECT","SNIPPET","SORT","SPELL_CORRECTION","STANDARD","USER_MODE","WHERE","PricebookId","WITH","SECURITY_ENFORCED","USING","SCOPE","Delegated","Everything","Mine","My_Territory","My_Team_Territory","Team","TYPEOF","ELSE","END","THEN","WHEN").concat("ABOVE","AND","AT","BY","CATEGORY","DATA","FIRST","FOR","GROUP","HAVING","IN","LAST","LIKE","LIMIT","LISTVIEW","NOT","NULLS","OFFSET","OR","REFERENCE","TRACKING","TYPEOF","UPDATE","UPDATE","VIEW","VIEWSTAT"), type:["AVG","convertCurrency","convertTimezone","COUNT_DISTINCT","COUNT","DISTANCE","EXCLUDES","FORMAT","GEOLOCATION","GROUP BY CUBE","GROUP BY ROLLUP","GROUPING","INCLUDES","MAX","MIN","SUM","toLabel"], "title.function":["DAY_IN_MONTH","HOUR_IN_DAY","DAY_IN_WEEK","DAY_IN_YEAR","DAY_ONLY","CALENDAR_MONTH","CALENDAR_QUARTER","CALENDAR_YEAR","FISCAL_MONTH","FISCAL_QUARTER","FISCAL_YEAR","TODAY","TOMORROW","YESTERDAY","WEEK_IN_MONTH","WEEK_IN_YEAR"], -literal:v.literal,built_in:S};return{name:"Apex", +literal:y.literal,built_in:g};return{name:"Apex", aliases:["apex","lightning","soql"],case_insensitive:!0,disableAutodetect:!1, -ignoreIllegals:!1,keywords:v, +ignoreIllegals:!1,keywords:y, illegal:["","\x3c!--","!DOCTYPE",/","<%%",":-",/\bmergesort\(/,/\bvar\s+env\b/,/\bdef\b\s\W:/,/"[^"]+"/,/\(\*|\*\)/], -contains:[D,U,C,L,Y,[{match:/as\s+(user|system)\b/,scope:"keyword"}],i,I,{ -match:[/\bfor\b\s*/,/\(/,a,s,a,/\s*/,/:/],scope:{3:"type",5:"variable", -7:"operator"}},k,M,T,R,p,N,f,g,w,{begin:[/\[/,/\s*(?=(SELECT|FIND)\b)/], -end:/\]/,beginScope:{1:"punctuation"},endScope:"punctuation",scope:"soql", -relevance:10,endsWithParent:!0,keywords:W,contains:[{begin:/\bSELECT\b/, -beginScope:"keyword",end:/\bFROM\b/,returnEnd:!0,keywords:W,contains:[A,{ -match:[/(?=[\s\,])/,a,/(?=[\s\,])/],scope:{2:"subst"}}]},p,N,y,A,{match:/\(|\)/, -scope:"punctuation",relevance:0},...i,{begin:[/\bFROM\b/,s],beginScope:{ +contains:[I,f,D,p,Y,M,G,[{match:/as\s+(user|system)\b/,scope:"keyword"}],k,{ +match:[/\bfor\b\s*/,/\(/,a,o,a,/\s*/,/:/],scope:{3:"type",5:"variable", +7:"operator"}},H,P,L,N,U,{begin:[/\[/,/\s*(?=(SELECT|FIND)\b)/],end:/\]/, +beginScope:{1:"punctuation"},endScope:"punctuation",scope:"soql",relevance:10, +endsWithParent:!0,keywords:K,contains:[{begin:/\bSELECT\b/,beginScope:"keyword", +end:/\bFROM\b/,returnEnd:!0,keywords:K,contains:[T,{ +match:[/(?=[\s\,])/,a,/(?=[\s\,])/],scope:{2:"subst"}}]},p,_,D,T,{match:/\(|\)/, +scope:"punctuation",relevance:0},...i,{begin:[/\bFROM\b/,o],beginScope:{ 1:"keyword"},end:/(?=\bWHERE\b|\]|\s|\))/,contains:[{match:a,scope:"type"},...i] },{ match:/(NEXT|LAST|THIS)_(90_DAY|DAY|FISCAL_QUARTER|FISCAL_YEAR|MONTH|QUARTER|WEEK|YEAR)S?\b/, scope:"keyword",relevance:8},{ match:[/(NEXT|LAST)_N_(DAY|FISCAL_QUARTER|FISCAL_YEAR|MONTH|QUARTER|WEEK|YEAR)S/,/\s*:\s*/,/\d+/], scope:{1:"keyword",2:"operator",3:"number"},relevance:8},{ -match:[/(?<=:)/,/\s*/,n,/(?!\()/],scope:{3:"variable"},relevance:0},{ +match:[/(?<=:)/,/\s*/,c,/(?!\()/],scope:{3:"variable"},relevance:0},{ match:[/(?<=:|\.)/,a,/(?=\s*\()/],scope:{2:"title.function.invoke"},relevance:0 -},{match:/:/,scope:"operator",relevance:0}],illegal:"::"},y,P,_]}}})() -;export default hljsGrammar; \ No newline at end of file +},{match:/:/,scope:"operator",relevance:0}],illegal:"::"},B,F,_,C,i,{ +match:t.concat("(?<=this.)",a,"(?!\\()"),scope:"variable"},{ +match:[t.concat(/\b/,l(...O)),a,o,/(?=\{)/],scope:{2:"property"},relevance:0}]}} +})();export default hljsGrammar; \ No newline at end of file diff --git a/dist/apex.min.js b/dist/apex.min.js index af32689..fe510f7 100644 --- a/dist/apex.min.js +++ b/dist/apex.min.js @@ -1,105 +1,112 @@ /*! `apex` grammar compiled for Highlight.js 11.9.0 */ (()=>{var e=(()=>{"use strict";return e=>{ -const t=e.regex,a="[a-zA-Z][a-zA-Z_0-9]*",n="\\b"+a+"\\b",c="@"+a,s=/(?=\s*\()/,o=/\s+/,i=/\?\.\b/,r=[{ -match:/(?>\=|>>>\=|\|\=/,/\&|~|\^|\|/,/<<|>>/,/<\=|>\=|\s(<|>)\s/,/\=\=|!\=/,/\=>/,/!(?=\w)/,/(?<=\s)(\?|:)(?=\s)/,i,/(?)/],S=m.concat("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={ -$pattern:t.concat(/(?>\=|>>>\=|\|\=/,/\&|~|\^|\|/,/<<|>>/,/<\=|>\=|\s(<|>)\s/,/\=\=|!\=/,/\=>/,/!(?=\w)/,/(?<=\s)(\?|:)(?=\s)/,r,/(?)/],g=A.concat(...h),y={ +$pattern:t.concat(/(?/,/\<(?=\w)/,/\{|\}/,/\(|\)/,/\{|\}/), -scope:"punctuation",relevance:0},A],y=e.inherit(e.APOS_STRING_MODE,{ +scope:"punctuation",relevance:0},T],D=e.inherit(e.APOS_STRING_MODE,{ scope:"string",relevance:0,contains:[{match:/\\'/,scope:"literal",relevance:0}] -}),O=e.COMMENT("//",/[$\n]/,{relevance:0}),L=[e.COMMENT("/\\*","\\*/",{ +}),w=e.COMMENT("//",/[$\n]/,{relevance:0}),I=[e.COMMENT("/\\*","\\*/",{ relevance:0,contains:[{begin:/\w+@/,relevance:0},{ match:[/@(?:exception|throws)/,o,a],scope:{1:"doctag",3:"title.class"}, relevance:0},{begin:"@[A-Za-z_-]+",scope:"doctag",relevance:0},{ match:[/(?<=@param)\s+/,a],scope:{2:"variable"},relevance:0},{begin:"`",end:"`", -scope:"string",contains:[e.BACKSLASH_ESCAPE],relevance:0}]}),O],N={ -match:t.either(...h),scope:"operator",relevance:0},w={match:/(?+/,endScope:"punctuation",contains:[{match:/\<|\,/, -scope:"punctuation"},{match:n,scope:"type"}],relevance:8},{ -match:[t.optional(n),/\[/,t.optional(/\d+/),/\]/],scope:{1:"variable", +scope:"punctuation"},{match:c,scope:"type"}],relevance:8},{ +match:[t.optional(c),/\[/,t.optional(/\d+/),/\]/],scope:{1:"variable", 2:"punctuation",3:"number",4:"punctuation"}},{match:[a,/\[\]/],scope:{1:"type", -2:"punctuation"},relevance:0}],D=[{match:t.concat(c,/\b(?!\s*\()/),scope:"meta" -},{scope:"meta",begin:[t.concat(c,/\b/),/\s*/,/\(/],beginScope:{3:"punctuation" -},end:/\)/,endScope:"punctuation",contains:[{match:[n,/\s*=/],scope:{ -1:"keyword",2:"operator"},contains:[N]},y,p],keywords:{literal:E}}],I={ +2:"punctuation"},relevance:0}],f=[{match:t.concat(n,/\b(?!\s*\()/),scope:"meta" +},{scope:"meta",begin:[t.concat(n,/\b/),/\s*/,/\(/],beginScope:{3:"punctuation" +},end:/\)/,endScope:"punctuation",contains:[{match:[c,/\s*=/],scope:{ +1:"keyword",2:"operator"},contains:[_]},D,p],keywords:{literal:S}}],k={ match:[/\b[a-zA-Z0-9\.]*Exception/,o,a],scope:{1:"title.class",3:"variable"}, -relevance:0},_={match:[/(?])/],scope:{2:"variable"}, -relevance:0},U={match:[/(?<=\=\s*\()/,a,"(?=\\)\\s*"+a+")"],scope:{2:"type"}, -relevance:0},M={match:[/\bnew\s+/,a,s],scope:{2:"type"},relevance:0},f={ -begin:/\((?!(\s*\[))/,beginScope:"punctuation",end:/\)/,endScope:"punctuation", -relevance:0,keywords:v,contains:[y,M,L,N,C,g,p,w,{keywords:{KEYWORDS:v}, -match:t.concat(/(?<=\s|\(|\,)/,l(...E),a,/\b/,/(?!\.)/),scope:"variable", -relevance:0},{match:/\,|\./,scope:"punctuation",relevance:0}]},k=[{ -match:[t.concat(/\b/,l(...S)),/\??(?<=\.)/,a,s],scope:{3:"title.function.invoke" -},relevance:0},{match:[/^\s*/,l(...b),a,s],scope:{3:"title.function.invoke"}, -relevance:0}],F={scope:"params",end:/\)/,endScope:"punctuation",relevance:0, -keywords:v,illegal:b,contains:[p,y,L,C,...g,{match:/\,|\(/,scope:"punctuation" -},w,{match:[/(?<=\(|\,)\s*/,a,/(?=\s)/],scope:{2:"type"}},{ -match:[o,a,/\s*(?=[,)])/],scope:{2:"variable"}}]},Y=[{ +relevance:0},F={match:[/(?])/],scope:{2:"variable"}, +relevance:0},Y={match:[/(?<=\=\s*\()/,a,"(?=\\)\\s*"+a+")"],scope:{2:"type"}, +relevance:0},P={match:[/\bnew\s+/,a,s],scope:{2:"type"},relevance:0};let W={ +scope:"params_call",begin:/\(/,beginScope:"punctuation",end:/\)/, +endScope:"punctuation",relevance:0,keywords:y,contains:[]};const H=[{ +match:[/(?<=\.)/,a,s],scope:{2:"title.function.invoke"},relevance:1, +contains:[...i],starts:W},{match:[/^\s*/,l(...b),a,s],scope:{ +3:"title.function.invoke"},relevance:1,starts:W}] +;W.contains=[D,P,I,_,M,N,p,U,H,{keywords:{KEYWORDS:y}, +match:t.concat(/(?<=\s|\(|\,)/,l(...S),a,/\b/,/(?!\.)/),scope:"variable", +relevance:0},{match:/\(|\,|\./,scope:"punctuation",relevance:0},{match:a, +scope:"variable"}];const x={scope:"params",end:/\)/,endScope:"punctuation", +relevance:1,keywords:y,contains:[p,D,I,M,...N,{match:/\,|\(/,scope:"punctuation" +},U,{match:[/(?<=\(|\,)\s*/,a,/(?=\s)/],scope:{2:"type"}},{ +match:[o,a,/\s*(?=[,)])/],scope:{2:"variable"}}]},G=[{ begin:[/\btrigger/,o,a,o,"on",o,a],beginScope:{1:"keyword",3:"title.class", -5:"operator",7:"type"},end:/(?=\{)/,returnEnd:!0,contains:[L,{begin:/\(/, +5:"operator",7:"type"},end:/(?=\{)/,returnEnd:!0,contains:[I,{begin:/\(/, end:/\)/,contains:[{ match:/\b(before|after)\s+(insert|update|delete|merge|undelete)\b/, -scope:"keyword",relevance:5},A]}]},{relevance:5, +scope:"keyword",relevance:5},T]}]},{relevance:5, match:/\b(with|without|inherited)\s+sharing\b/,scope:"keyword"},{ begin:[/(?!\.)/,/\bclass\b(?!\?|\.)/],beginScope:{2:"keyword"},end:/(?=\{)/, -relevance:1,keywords:{type:d,keyword:b},contains:[{match:[/(?<=\bclass)\s+/,a], +relevance:1,keywords:{type:m,keyword:b},contains:[{match:[/(?<=\bclass)\s+/,a], scope:{2:"title.class"}},{returnEnd:!0,endsWithParent:!0, -beginKeywords:"implements extends",end:/\{/,contains:[g,{match:[n,/(?=\.)/], -scope:{1:"built_in"}},{match:t.concat(n,/(?=>)/),scope:"type"},{ +beginKeywords:"implements extends",end:/\{/,contains:[{ match:t.concat(/\b/,t.either("schedulable","batchable","queueable","comparable","callable"),/\b\s*(?!>)/), -scope:"title.class.inherited",relevance:8},{match:t.concat(n,/(?!<)/), -scope:"title.class.inherited"},{match:/<|>|,/,scope:"punctuation"}],relevance:0 -}]},{begin:[/\benum\s+/,a,/\s*\{/],beginScope:{2:"type",3:"punctuation"}, -end:/\}/,endScope:"punctuation",relevance:0,contains:[L,A,{match:t.concat(n), -scope:"variable.constant"}]},{match:[/(public|private|protected)\s+/,a,s], -scope:{1:"keyword",2:"title.function"},starts:F,relevance:0},{ +scope:"title.class.inherited",relevance:8},{match:[c,/(?=\.)/],scope:{ +1:"built_in"}},{match:t.concat(c,/(?=\>)/),scope:"type"},{match:c, +scope:"title.class.inherited"},{match:/<|>|,/,scope:"punctuation"},N], +relevance:0}]},{begin:[/\benum\s+/,a,/\s*\{/],beginScope:{2:"type", +3:"punctuation"},end:/\}/,endScope:"punctuation",relevance:0,contains:[I,T,{ +match:t.concat(c),scope:"variable.constant"}]},{ +match:[/(public|private|protected)\s+/,a,s],scope:{1:"keyword", +2:"title.function"},starts:x,relevance:1},{ match:[/(?|\w)\s+/,a,s],scope:{2:"title.function"}, -relevance:0,starts:F}],P={match:[/\bswitch\s+on\s+/,a],scope:{1:"keyword", -2:"variable"}},W={ -keyword:[].concat(...v.keyword).concat("ABOVE_OR_BELOW","ACTIVE","ADVANCED","ALL","ANY","ARRAY","AS","ASC","BY","CATEGORY","CONTAINS","CUSTOM","DATA","DESC","DIVISION","END","FIELDS","FIND","FROM","LAST","METADATA","NETWORK","ON","ORDER","RETURNING","ROLLUP","ROWS","SEARCH","SELECT","SNIPPET","SORT","SPELL_CORRECTION","STANDARD","USER_MODE","WHERE","PricebookId","WITH","SECURITY_ENFORCED","USING","SCOPE","Delegated","Everything","Mine","My_Territory","My_Team_Territory","Team","TYPEOF","ELSE","END","THEN","WHEN").concat("ABOVE","AND","AT","BY","CATEGORY","DATA","FIRST","FOR","GROUP","HAVING","IN","LAST","LIKE","LIMIT","LISTVIEW","NOT","NULLS","OFFSET","OR","REFERENCE","TRACKING","TYPEOF","UPDATE","UPDATE","VIEW","VIEWSTAT"), +relevance:1,starts:x}],B={match:[/\bswitch\s+on\s+/,a],scope:{1:"keyword", +2:"variable"}},K={ +keyword:[].concat(...y.keyword).concat("ABOVE_OR_BELOW","ACTIVE","ADVANCED","ALL","ANY","ARRAY","AS","ASC","BY","CATEGORY","CONTAINS","CUSTOM","DATA","DESC","DIVISION","END","FIELDS","FIND","FROM","LAST","METADATA","NETWORK","ON","ORDER","RETURNING","ROLLUP","ROWS","SEARCH","SELECT","SNIPPET","SORT","SPELL_CORRECTION","STANDARD","USER_MODE","WHERE","PricebookId","WITH","SECURITY_ENFORCED","USING","SCOPE","Delegated","Everything","Mine","My_Territory","My_Team_Territory","Team","TYPEOF","ELSE","END","THEN","WHEN").concat("ABOVE","AND","AT","BY","CATEGORY","DATA","FIRST","FOR","GROUP","HAVING","IN","LAST","LIKE","LIMIT","LISTVIEW","NOT","NULLS","OFFSET","OR","REFERENCE","TRACKING","TYPEOF","UPDATE","UPDATE","VIEW","VIEWSTAT"), type:["AVG","convertCurrency","convertTimezone","COUNT_DISTINCT","COUNT","DISTANCE","EXCLUDES","FORMAT","GEOLOCATION","GROUP BY CUBE","GROUP BY ROLLUP","GROUPING","INCLUDES","MAX","MIN","SUM","toLabel"], "title.function":["DAY_IN_MONTH","HOUR_IN_DAY","DAY_IN_WEEK","DAY_IN_YEAR","DAY_ONLY","CALENDAR_MONTH","CALENDAR_QUARTER","CALENDAR_YEAR","FISCAL_MONTH","FISCAL_QUARTER","FISCAL_YEAR","TODAY","TOMORROW","YESTERDAY","WEEK_IN_MONTH","WEEK_IN_YEAR"], -literal:v.literal,built_in:S};return{name:"Apex", +literal:y.literal,built_in:g};return{name:"Apex", aliases:["apex","lightning","soql"],case_insensitive:!0,disableAutodetect:!1, -ignoreIllegals:!1,keywords:v, +ignoreIllegals:!1,keywords:y, illegal:["","\x3c!--","!DOCTYPE",/","<%%",":-",/\bmergesort\(/,/\bvar\s+env\b/,/\bdef\b\s\W:/,/"[^"]+"/,/\(\*|\*\)/], -contains:[D,U,C,L,Y,[{match:/as\s+(user|system)\b/,scope:"keyword"}],r,I,{ +contains:[I,f,D,p,Y,M,G,[{match:/as\s+(user|system)\b/,scope:"keyword"}],k,{ match:[/\bfor\b\s*/,/\(/,a,o,a,/\s*/,/:/],scope:{3:"type",5:"variable", -7:"operator"}},k,M,T,g,p,N,f,R,w,{begin:[/\[/,/\s*(?=(SELECT|FIND)\b)/], -end:/\]/,beginScope:{1:"punctuation"},endScope:"punctuation",scope:"soql", -relevance:10,endsWithParent:!0,keywords:W,contains:[{begin:/\bSELECT\b/, -beginScope:"keyword",end:/\bFROM\b/,returnEnd:!0,keywords:W,contains:[A,{ -match:[/(?=[\s\,])/,a,/(?=[\s\,])/],scope:{2:"subst"}}]},p,N,y,A,{match:/\(|\)/, -scope:"punctuation",relevance:0},...r,{begin:[/\bFROM\b/,o],beginScope:{ -1:"keyword"},end:/(?=\bWHERE\b|\]|\s|\))/,contains:[{match:a,scope:"type"},...r] +7:"operator"}},H,P,L,N,U,{begin:[/\[/,/\s*(?=(SELECT|FIND)\b)/],end:/\]/, +beginScope:{1:"punctuation"},endScope:"punctuation",scope:"soql",relevance:10, +endsWithParent:!0,keywords:K,contains:[{begin:/\bSELECT\b/,beginScope:"keyword", +end:/\bFROM\b/,returnEnd:!0,keywords:K,contains:[T,{ +match:[/(?=[\s\,])/,a,/(?=[\s\,])/],scope:{2:"subst"}}]},p,_,D,T,{match:/\(|\)/, +scope:"punctuation",relevance:0},...i,{begin:[/\bFROM\b/,o],beginScope:{ +1:"keyword"},end:/(?=\bWHERE\b|\]|\s|\))/,contains:[{match:a,scope:"type"},...i] },{ match:/(NEXT|LAST|THIS)_(90_DAY|DAY|FISCAL_QUARTER|FISCAL_YEAR|MONTH|QUARTER|WEEK|YEAR)S?\b/, scope:"keyword",relevance:8},{ match:[/(NEXT|LAST)_N_(DAY|FISCAL_QUARTER|FISCAL_YEAR|MONTH|QUARTER|WEEK|YEAR)S/,/\s*:\s*/,/\d+/], scope:{1:"keyword",2:"operator",3:"number"},relevance:8},{ -match:[/(?<=:)/,/\s*/,n,/(?!\()/],scope:{3:"variable"},relevance:0},{ +match:[/(?<=:)/,/\s*/,c,/(?!\()/],scope:{3:"variable"},relevance:0},{ match:[/(?<=:|\.)/,a,/(?=\s*\()/],scope:{2:"title.function.invoke"},relevance:0 -},{match:/:/,scope:"operator",relevance:0}],illegal:"::"},y,P,_]}}})() -;hljs.registerLanguage("apex",e)})(); \ No newline at end of file +},{match:/:/,scope:"operator",relevance:0}],illegal:"::"},B,F,_,C,i,{ +match:t.concat("(?<=this.)",a,"(?!\\()"),scope:"variable"},{ +match:[t.concat(/\b/,l(...O)),a,o,/(?=\{)/],scope:{2:"property"},relevance:0}]}} +})();hljs.registerLanguage("apex",e)})(); \ No newline at end of file diff --git a/src/languages/apex.js b/src/languages/apex.js index 6183893..57f969d 100644 --- a/src/languages/apex.js +++ b/src/languages/apex.js @@ -12,11 +12,11 @@ export default function (hljs) { const APEX_IDENT_WORD_RE = '\\b' + APEX_IDENT_RE + '\\b'; const ANNOTATION_RE = '@' + APEX_IDENT_RE; const SPACEPARENS_LOOKAHEAD = /(?=\s*\()/; - const PARENS_LOOKAHEAD = /(?=\()/; + //const PARENS_LOOKAHEAD = /(?=\()/; const SPACE = /\s+/; const ACCESSOR = /(?)/), - scope: 'type' - }, { match: regex.concat( /\b/, @@ -676,10 +678,19 @@ export default function (hljs) { relevance: 8 }, { - match: regex.concat(APEX_IDENT_WORD_RE, /(?!<)/), + match: [APEX_IDENT_WORD_RE, /(?=\.)/], + scope: { 1: 'built_in' } + }, + { + match: regex.concat(APEX_IDENT_WORD_RE, /(?=\>)/), + scope: 'type' + }, + { + match: APEX_IDENT_WORD_RE, scope: 'title.class.inherited' }, - { match: /<|>|,/, scope: 'punctuation' } + { match: /<|>|,/, scope: 'punctuation' }, + NAMESPACES ], relevance: 0 }; @@ -778,7 +789,7 @@ export default function (hljs) { 2: 'title.function' }, starts: PARAMS_DECLARATION, - relevance: 0 + relevance: 1 }, { // * method declaration @@ -788,7 +799,7 @@ export default function (hljs) { SPACEPARENS_LOOKAHEAD ], scope: { 2: 'title.function' }, - relevance: 0, + relevance: 1, starts: PARAMS_DECLARATION } ]; @@ -1049,6 +1060,22 @@ export default function (hljs) { } }; + const THIS = { + match: regex.concat('(?<=this.)', APEX_IDENT_RE, '(?!\\()'), + scope: 'variable' + }; + + const PROPERTY = { + match: [ + regex.concat(/\b/, noneOf(...RESERVED_WORDS)), + APEX_IDENT_RE, + SPACE, + /(?=\{)/ + ], + scope: { 2: 'property' }, + relevance: 0 + }; + const ILLEGALS = [ '@author John Smith */ @IsTest(Seealldata=true) -public with sharing class L2Char implements Database.batchable { +public with sharing class L2Char implements Database.batchable { public static final String ERROR = 0x0001; @InvocableMethod(label='my invocable') @@ -16,10 +16,10 @@ Account a = new Account(); a.Custom__c = 'stringvalue'; insert a; - Boolean ai = (Boolean) false; + Boolean ai = (Boolean) false; System.debug('Should not be called'); - if (1 > 5 && !Test.isRunningTest()) { // wtf!? - Database.insert(myAccounts, false); + if (1 > 5 && !Test.isRunningTest()) { // wtf!? + Database.insert(myAccounts, false); } } } @@ -39,10 +39,10 @@ } @testVisible -private List<SelectOption> recordTypes { get; private set; } +private List<SelectOption> recordTypes { get; private set; } for(Account a : [SELECT Id FROM Account WHERE LastModifiedDate = LAST_N_DAYS:3]){ - Assert.fail(); + Assert.fail(); } trigger CTrig on Custom__c (before insert){