aboutsummaryrefslogtreecommitdiffstats
path: root/public/prism/prism-cpp.js
blob: 0021d84a2cb3af0506ba6ade1208dbc533e86172 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
(function (Prism) {
  var keyword =
    /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/;
  var modName = /\b(?!<keyword>)\w+(?:\s*\.\s*\w+)*\b/.source.replace(
    /<keyword>/g,
    function () {
      return keyword.source;
    }
  );

  Prism.languages.cpp = Prism.languages.extend('c', {
    'class-name': [
      {
        pattern: RegExp(
          /(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source.replace(
            /<keyword>/g,
            function () {
              return keyword.source;
            }
          )
        ),
        lookbehind: true,
      },
      // This is intended to capture the class name of method implementations like:
      //   void foo::bar() const {}
      // However! The `foo` in the above example could also be a namespace, so we only capture the class name if
      // it starts with an uppercase letter. This approximation should give decent results.
      /\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,
      // This will capture the class name before destructors like:
      //   Foo::~Foo() {}
      /\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,
      // This also intends to capture the class name of method implementations but here the class has template
      // parameters, so it can't be a namespace (until C++ adds generic namespaces).
      /\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/,
    ],
    keyword: keyword,
    number: {
      pattern:
        /(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,
      greedy: true,
    },
    operator:
      />>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,
    boolean: /\b(?:false|true)\b/,
  });

  Prism.languages.insertBefore('cpp', 'string', {
    module: {
      // https://en.cppreference.com/w/cpp/language/modules
      pattern: RegExp(
        /(\b(?:import|module)\s+)/.source +
          '(?:' +
          // header-name
          /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source +
          '|' +
          // module name or partition or both
          /<mod-name>(?:\s*:\s*<mod-name>)?|:\s*<mod-name>/.source.replace(
            /<mod-name>/g,
            function () {
              return modName;
            }
          ) +
          ')'
      ),
      lookbehind: true,
      greedy: true,
      inside: {
        string: /^[<"][\s\S]+/,
        operator: /:/,
        punctuation: /\./,
      },
    },
    'raw-string': {
      pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
      alias: 'string',
      greedy: true,
    },
  });

  Prism.languages.insertBefore('cpp', 'keyword', {
    'generic-function': {
      pattern: /\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,
      inside: {
        function: /^\w+/,
        generic: {
          pattern: /<[\s\S]+/,
          alias: 'class-name',
          inside: Prism.languages.cpp,
        },
      },
    },
  });

  Prism.languages.insertBefore('cpp', 'operator', {
    'double-colon': {
      pattern: /::/,
      alias: 'punctuation',
    },
  });

  Prism.languages.insertBefore('cpp', 'class-name', {
    // the base clause is an optional list of parent classes
    // https://en.cppreference.com/w/cpp/language/class
    'base-clause': {
      pattern:
        /(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,
      lookbehind: true,
      greedy: true,
      inside: Prism.languages.extend('cpp', {}),
    },
  });

  Prism.languages.insertBefore(
    'inside',
    'double-colon',
    {
      // All untokenized words that are not namespaces should be class names
      'class-name': /\b[a-z_]\w*\b(?!\s*::)/i,
    },
    Prism.languages.cpp['base-clause']
  );
})(Prism);
span>= { pattern: /\b(?:format|put)\b=?[\w'$.]+/i, inside: { keyword: /^(?:format|put)(?==)/i, equals: /=/, format: { pattern: /(?:\w|\$\d)+\.\d?/, alias: 'number', }, }, }; var altformat = { pattern: /\b(?:format|put)\s+[\w']+(?:\s+[$.\w]+)+(?=;)/i, inside: { keyword: /^(?:format|put)/i, format: { pattern: /[\w$]+\.\d?/, alias: 'number', }, }, }; var globalStatements = { pattern: /((?:^|\s)=?)(?:catname|checkpoint execute_always|dm|endsas|filename|footnote|%include|libname|%list|lock|missing|options|page|resetline|%run|sasfile|skip|sysecho|title\d?)\b/i, lookbehind: true, alias: 'keyword', }; var submitStatement = { pattern: /(^|\s)(?:submit(?:\s+(?:load|norun|parseonly))?|endsubmit)\b/i, lookbehind: true, alias: 'keyword', }; var actionSets = /aStore|accessControl|aggregation|audio|autotune|bayesianNetClassifier|bioMedImage|boolRule|builtins|cardinality|cdm|clustering|conditionalRandomFields|configuration|copula|countreg|dataDiscovery|dataPreprocess|dataSciencePilot|dataStep|decisionTree|deduplication|deepLearn|deepNeural|deepRnn|ds2|ecm|entityRes|espCluster|explainModel|factmac|fastKnn|fcmpact|fedSql|freqTab|gVarCluster|gam|gleam|graphSemiSupLearn|hiddenMarkovModel|hyperGroup|ica|image|iml|kernalPca|langModel|ldaTopic|loadStreams|mbc|mixed|mlTools|modelPublishing|network|neuralNet|nmf|nonParametricBayes|nonlinear|optNetwork|optimization|panel|pca|percentile|phreg|pls|qkb|qlim|quantreg|recommend|regression|reinforcementLearn|robustPca|ruleMining|sampling|sandwich|sccasl|search(?:Analytics)?|sentimentAnalysis|sequence|session(?:Prop)?|severity|simSystem|simple|smartData|sparkEmbeddedProcess|sparseML|spatialreg|spc|stabilityMonitoring|svDataDescription|svm|table|text(?:Filters|Frequency|Mining|Parse|Rule(?:Develop|Score)|Topic|Util)|timeData|transpose|tsInfo|tsReconcile|uniTimeSeries|varReduce/ .source; var casActions = { pattern: RegExp( /(^|\s)(?:action\s+)?(?:<act>)\.[a-z]+\b[^;]+/.source.replace( /<act>/g, function () { return actionSets; } ), 'i' ), lookbehind: true, inside: { keyword: RegExp( /(?:<act>)\.[a-z]+\b/.source.replace(/<act>/g, function () { return actionSets; }), 'i' ), action: { pattern: /(?:action)/i, alias: 'keyword', }, comment: comment, function: func, 'arg-value': args['arg-value'], operator: args.operator, argument: args.arg, number: number, 'numeric-constant': numericConstant, punctuation: punctuation, string: string, }, }; var keywords = { pattern: /((?:^|\s)=?)(?:after|analysis|and|array|barchart|barwidth|begingraph|by|call|cas|cbarline|cfill|class(?:lev)?|close|column|computed?|contains|continue|data(?==)|define|delete|describe|document|do\s+over|do|dol|drop|dul|else|end(?:comp|source)?|entryTitle|eval(?:uate)?|exec(?:ute)?|exit|file(?:name)?|fill(?:attrs)?|flist|fnc|function(?:list)?|global|goto|group(?:by)?|headline|headskip|histogram|if|infile|keep|keylabel|keyword|label|layout|leave|legendlabel|length|libname|loadactionset|merge|midpoints|_?null_|name|noobs|nowd|ods|options|or|otherwise|out(?:put)?|over(?:lay)?|plot|print|put|raise|ranexp|rannor|rbreak|retain|return|select|session|sessref|set|source|statgraph|sum|summarize|table|temp|terminate|then\s+do|then|title\d?|to|var|when|where|xaxisopts|y2axisopts|yaxisopts)\b/i, lookbehind: true, }; Prism.languages.sas = { datalines: { pattern: /^([ \t]*)(?:cards|(?:data)?lines);[\s\S]+?^[ \t]*;/im, lookbehind: true, alias: 'string', inside: { keyword: { pattern: /^(?:cards|(?:data)?lines)/i, }, punctuation: /;/, }, }, 'proc-sql': { pattern: /(^proc\s+(?:fed)?sql(?:\s+[\w|=]+)?;)[\s\S]+?(?=^(?:proc\s+\w+|data|quit|run);|(?![\s\S]))/im, lookbehind: true, inside: { sql: { pattern: RegExp( /^[ \t]*(?:select|alter\s+table|(?:create|describe|drop)\s+(?:index|table(?:\s+constraints)?|view)|create\s+unique\s+index|insert\s+into|update)(?:<str>|[^;"'])+;/.source.replace( /<str>/g, function () { return stringPattern; } ), 'im' ), alias: 'language-sql', inside: Prism.languages.sql, }, 'global-statements': globalStatements, 'sql-statements': { pattern: /(^|\s)(?:disconnect\s+from|begin|commit|exec(?:ute)?|reset|rollback|validate)\b/i, lookbehind: true, alias: 'keyword', }, number: number, 'numeric-constant': numericConstant, punctuation: punctuation, string: string, }, }, 'proc-groovy': { pattern: /(^proc\s+groovy(?:\s+[\w|=]+)?;)[\s\S]+?(?=^(?:proc\s+\w+|data|quit|run);|(?![\s\S]))/im, lookbehind: true, inside: { comment: comment, groovy: { pattern: RegExp( /(^[ \t]*submit(?:\s+(?:load|norun|parseonly))?)(?:<str>|[^"'])+?(?=endsubmit;)/.source.replace( /<str>/g, function () { return stringPattern; } ), 'im' ), lookbehind: true, alias: 'language-groovy', inside: Prism.languages.groovy, }, keyword: keywords, 'submit-statement': submitStatement, 'global-statements': globalStatements, number: number, 'numeric-constant': numericConstant, punctuation: punctuation, string: string, }, }, 'proc-lua': { pattern: /(^proc\s+lua(?:\s+[\w|=]+)?;)[\s\S]+?(?=^(?:proc\s+\w+|data|quit|run);|(?![\s\S]))/im, lookbehind: true, inside: { comment: comment, lua: { pattern: RegExp( /(^[ \t]*submit(?:\s+(?:load|norun|parseonly))?)(?:<str>|[^"'])+?(?=endsubmit;)/.source.replace( /<str>/g, function () { return stringPattern; } ), 'im' ), lookbehind: true, alias: 'language-lua', inside: Prism.languages.lua, }, keyword: keywords, 'submit-statement': submitStatement, 'global-statements': globalStatements, number: number, 'numeric-constant': numericConstant, punctuation: punctuation, string: string, }, }, 'proc-cas': { pattern: /(^proc\s+cas(?:\s+[\w|=]+)?;)[\s\S]+?(?=^(?:proc\s+\w+|quit|data);|(?![\s\S]))/im, lookbehind: true, inside: { comment: comment, 'statement-var': { pattern: /((?:^|\s)=?)saveresult\s[^;]+/im, lookbehind: true, inside: { statement: { pattern: /^saveresult\s+\S+/i, inside: { keyword: /^(?:saveresult)/i, }, }, rest: args, }, }, 'cas-actions': casActions, statement: { pattern: /((?:^|\s)=?)(?:default|(?:un)?set|on|output|upload)[^;]+/im, lookbehind: true, inside: args, }, step: step, keyword: keywords, function: func, format: format, altformat: altformat, 'global-statements': globalStatements, number: number, 'numeric-constant': numericConstant, punctuation: punctuation, string: string, }, }, 'proc-args': { pattern: RegExp( /(^proc\s+\w+\s+)(?!\s)(?:[^;"']|<str>)+;/.source.replace( /<str>/g, function () { return stringPattern; } ), 'im' ), lookbehind: true, inside: args, }, /*Special keywords within macros*/ 'macro-keyword': macroKeyword, 'macro-variable': macroVariable, 'macro-string-functions': { pattern: /((?:^|\s|=))%(?:BQUOTE|NRBQUOTE|NRQUOTE|NRSTR|QUOTE|STR)\(.*?(?:[^%]\))/i, lookbehind: true, inside: { function: { pattern: /%(?:BQUOTE|NRBQUOTE|NRQUOTE|NRSTR|QUOTE|STR)/i, alias: 'keyword', }, 'macro-keyword': macroKeyword, 'macro-variable': macroVariable, 'escaped-char': { pattern: /%['"()<>=¬^~;,#]/, }, punctuation: punctuation, }, }, 'macro-declaration': { pattern: /^%macro[^;]+(?=;)/im, inside: { keyword: /%macro/i, }, }, 'macro-end': { pattern: /^%mend[^;]+(?=;)/im, inside: { keyword: /%mend/i, }, }, /*%_zscore(headcir, _lhc, _mhc, _shc, headcz, headcpct, _Fheadcz); */ macro: { pattern: /%_\w+(?=\()/, alias: 'keyword', }, input: { pattern: /\binput\s[-\w\s/*.$&]+;/i, inside: { input: { alias: 'keyword', pattern: /^input/i, }, comment: comment, number: number, 'numeric-constant': numericConstant, }, }, 'options-args': { pattern: /(^options)[-'"|/\\<>*+=:()\w\s]*(?=;)/im, lookbehind: true, inside: args, }, 'cas-actions': casActions, comment: comment, function: func, format: format, altformat: altformat, 'numeric-constant': numericConstant, datetime: { // '1jan2013'd, '9:25:19pm't, '18jan2003:9:27:05am'dt pattern: RegExp(stringPattern + '(?:dt?|t)'), alias: 'number', }, string: string, step: step, keyword: keywords, // In SAS Studio syntax highlighting, these operators are styled like keywords 'operator-keyword': { pattern: /\b(?:eq|ge|gt|in|le|lt|ne|not)\b/i, alias: 'operator', }, // Decimal (1.2e23), hexadecimal (0c1x) number: number, operator: /\*\*?|\|\|?|!!?|¦¦?|<[>=]?|>[<=]?|[-+\/=&]|[~¬^]=?/, punctuation: punctuation, }; })(Prism);