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:["","<#","<]","