python.min.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*! `python` grammar compiled for Highlight.js 11.7.0 */
  2. var hljsGrammar=(()=>{"use strict";return e=>{
  3. const n=e.regex,a=/[\p{XID_Start}_]\p{XID_Continue}*/u,s=["and","as","assert","async","await","break","case","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","in","is","lambda","match","nonlocal|10","not","or","pass","raise","return","try","while","with","yield"],i={
  4. $pattern:/[A-Za-z]\w+|__\w+__/,keyword:s,
  5. built_in:["__import__","abs","all","any","ascii","bin","bool","breakpoint","bytearray","bytes","callable","chr","classmethod","compile","complex","delattr","dict","dir","divmod","enumerate","eval","exec","filter","float","format","frozenset","getattr","globals","hasattr","hash","help","hex","id","input","int","isinstance","issubclass","iter","len","list","locals","map","max","memoryview","min","next","object","oct","open","ord","pow","print","property","range","repr","reversed","round","set","setattr","slice","sorted","staticmethod","str","sum","super","tuple","type","vars","zip"],
  6. literal:["__debug__","Ellipsis","False","None","NotImplemented","True"],
  7. type:["Any","Callable","Coroutine","Dict","List","Literal","Generic","Optional","Sequence","Set","Tuple","Type","Union"]
  8. },t={className:"meta",begin:/^(>>>|\.\.\.) /},r={className:"subst",begin:/\{/,
  9. end:/\}/,keywords:i,illegal:/#/},l={begin:/\{\{/,relevance:0},b={
  10. className:"string",contains:[e.BACKSLASH_ESCAPE],variants:[{
  11. begin:/([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?'''/,end:/'''/,
  12. contains:[e.BACKSLASH_ESCAPE,t],relevance:10},{
  13. begin:/([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?"""/,end:/"""/,
  14. contains:[e.BACKSLASH_ESCAPE,t],relevance:10},{
  15. begin:/([fF][rR]|[rR][fF]|[fF])'''/,end:/'''/,
  16. contains:[e.BACKSLASH_ESCAPE,t,l,r]},{begin:/([fF][rR]|[rR][fF]|[fF])"""/,
  17. end:/"""/,contains:[e.BACKSLASH_ESCAPE,t,l,r]},{begin:/([uU]|[rR])'/,end:/'/,
  18. relevance:10},{begin:/([uU]|[rR])"/,end:/"/,relevance:10},{
  19. begin:/([bB]|[bB][rR]|[rR][bB])'/,end:/'/},{begin:/([bB]|[bB][rR]|[rR][bB])"/,
  20. end:/"/},{begin:/([fF][rR]|[rR][fF]|[fF])'/,end:/'/,
  21. contains:[e.BACKSLASH_ESCAPE,l,r]},{begin:/([fF][rR]|[rR][fF]|[fF])"/,end:/"/,
  22. contains:[e.BACKSLASH_ESCAPE,l,r]},e.APOS_STRING_MODE,e.QUOTE_STRING_MODE]
  23. },o="[0-9](_?[0-9])*",c=`(\\b(${o}))?\\.(${o})|\\b(${o})\\.`,d="\\b|"+s.join("|"),m={
  24. className:"number",relevance:0,variants:[{
  25. begin:`(\\b(${o})|(${c}))[eE][+-]?(${o})[jJ]?(?=${d})`},{begin:`(${c})[jJ]?`},{
  26. begin:`\\b([1-9](_?[0-9])*|0+(_?0)*)[lLjJ]?(?=${d})`},{
  27. begin:`\\b0[bB](_?[01])+[lL]?(?=${d})`},{begin:`\\b0[oO](_?[0-7])+[lL]?(?=${d})`
  28. },{begin:`\\b0[xX](_?[0-9a-fA-F])+[lL]?(?=${d})`},{begin:`\\b(${o})[jJ](?=${d})`
  29. }]},g={className:"comment",begin:n.lookahead(/# type:/),end:/$/,keywords:i,
  30. contains:[{begin:/# type:/},{begin:/#/,end:/\b\B/,endsWithParent:!0}]},p={
  31. className:"params",variants:[{className:"",begin:/\(\s*\)/,skip:!0},{begin:/\(/,
  32. end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:i,
  33. contains:["self",t,m,b,e.HASH_COMMENT_MODE]}]};return r.contains=[b,m,t],{
  34. name:"Python",aliases:["py","gyp","ipython"],unicodeRegex:!0,keywords:i,
  35. illegal:/(<\/|->|\?)|=>/,contains:[t,m,{begin:/\bself\b/},{beginKeywords:"if",
  36. relevance:0},b,g,e.HASH_COMMENT_MODE,{match:[/\bdef/,/\s+/,a],scope:{
  37. 1:"keyword",3:"title.function"},contains:[p]},{variants:[{
  38. match:[/\bclass/,/\s+/,a,/\s*/,/\(\s*/,a,/\s*\)/]},{match:[/\bclass/,/\s+/,a]}],
  39. scope:{1:"keyword",3:"title.class",6:"title.class.inherited"}},{
  40. className:"meta",begin:/^[\t ]*@/,end:/(?=#)|$/,contains:[m,p,b]}]}}})()
  41. ;export default hljsGrammar;