UNPKG

reprism

Version:

Modular Syntax highlighting for the web

102 lines (100 loc) 3.01 kB
export default { language: 'batch', init: Prism => { (function (Prism) { const variable = /%%?[~:\w]+%?|!\S+!/ const parameter = { pattern: /\/[a-z?]+(?=[ :]|$):?|-[a-z]\b|--[a-z-]+\b/im, alias: 'attr-name', inside: { punctuation: /:/, }, } const string = /"[^"]*"/ const number = /(?:\b|-)\d+\b/ Prism.languages.batch = { comment: [ /^::.*/m, { pattern: /((?:^|[&(])[ \t]*)rem\b(?:[^^&)\r\n]|\^(?:\r\n|[\s\S]))*/im, lookbehind: true, }, ], label: { pattern: /^:.*/m, alias: 'property', }, command: [ { // FOR command pattern: /((?:^|[&(])[ \t]*)for(?: ?\/[a-z?](?:[ :](?:"[^"]*"|\S+))?)* \S+ in \([^)]+\) do/im, lookbehind: true, inside: { keyword: /^for\b|\b(?:in|do)\b/i, string, parameter, variable, number, punctuation: /[()',]/, }, }, { // IF command pattern: /((?:^|[&(])[ \t]*)if(?: ?\/[a-z?](?:[ :](?:"[^"]*"|\S+))?)* (?:not )?(?:cmdextversion \d+|defined \w+|errorlevel \d+|exist \S+|(?:"[^"]*"|\S+)?(?:==| (?:equ|neq|lss|leq|gtr|geq) )(?:"[^"]*"|\S+))/im, lookbehind: true, inside: { keyword: /^if\b|\b(?:not|cmdextversion|defined|errorlevel|exist)\b/i, string, parameter, variable, number, operator: /\^|==|\b(?:equ|neq|lss|leq|gtr|geq)\b/i, }, }, { // ELSE command pattern: /((?:^|[&()])[ \t]*)else\b/im, lookbehind: true, inside: { keyword: /^else\b/i, }, }, { // SET command pattern: /((?:^|[&(])[ \t]*)set(?: ?\/[a-z](?:[ :](?:"[^"]*"|\S+))?)* (?:[^^&)\r\n]|\^(?:\r\n|[\s\S]))*/im, lookbehind: true, inside: { keyword: /^set\b/i, string, parameter, variable: [variable, /\w+(?=(?:[*\/%+\-&^|]|<<|>>)?=)/], number, operator: /[*\/%+\-&^|]=?|<<=?|>>=?|[!~_=]/, punctuation: /[()',]/, }, }, { // Other commands pattern: /((?:^|[&(])[ \t]*@?)\w+\b(?:[^^&)\r\n]|\^(?:\r\n|[\s\S]))*/im, lookbehind: true, inside: { keyword: /^\w+\b/i, string, parameter, label: { pattern: /(^\s*):\S+/m, lookbehind: true, alias: 'property', }, variable, number, operator: /\^/, }, }, ], operator: /[&@]/, punctuation: /[()']/, } }(Prism)) }, }