Skip to content
Permalink
Browse files
Powershell: Fixed lookbehind + refactoring (#3245)
  • Loading branch information
RunDevelopment committed Dec 10, 2021
1 parent 5688f48 commit d30a2da6ab099dd584848ed31266c7d41dda8648
Showing with 13 additions and 15 deletions.
  1. +12 −14 components/prism-powershell.js
  2. +1 −1 components/prism-powershell.min.js
@@ -15,15 +15,7 @@
{
pattern: /"(?:`[\s\S]|[^`"])*"/,
greedy: true,
inside: {
'function': {
// Allow for one level of nesting
pattern: /(^|[^`])\$\((?:\$\([^\r\n()]*\)|(?!\$\()[^\r\n)])*\)/,
lookbehind: true,
// Populated at end of file
inside: {}
}
}
inside: null // see below
},
{
pattern: /'(?:[^']|'')*'/,
@@ -45,16 +37,22 @@
// per http://technet.microsoft.com/en-us/library/hh847744.aspx
'keyword': /\b(?:Begin|Break|Catch|Class|Continue|Data|Define|Do|DynamicParam|Else|ElseIf|End|Exit|Filter|Finally|For|ForEach|From|Function|If|InlineScript|Parallel|Param|Process|Return|Sequence|Switch|Throw|Trap|Try|Until|Using|Var|While|Workflow)\b/i,
'operator': {
pattern: /(\W?)(?:!|-(?:b?(?:and|x?or)|as|(?:Not)?(?:Contains|In|Like|Match)|eq|ge|gt|is(?:Not)?|Join|le|lt|ne|not|Replace|sh[lr])\b|-[-=]?|\+[+=]?|[*\/%]=?)/i,
pattern: /(^|\W)(?:!|-(?:b?(?:and|x?or)|as|(?:Not)?(?:Contains|In|Like|Match)|eq|ge|gt|is(?:Not)?|Join|le|lt|ne|not|Replace|sh[lr])\b|-[-=]?|\+[+=]?|[*\/%]=?)/i,
lookbehind: true
},
'punctuation': /[|{}[\];(),.]/
};

// Variable interpolation inside strings, and nested expressions
var stringInside = powershell.string[0].inside;
stringInside.boolean = powershell.boolean;
stringInside.variable = powershell.variable;
stringInside.function.inside = powershell;
powershell.string[0].inside = {
'function': {
// Allow for one level of nesting
pattern: /(^|[^`])\$\((?:\$\([^\r\n()]*\)|(?!\$\()[^\r\n)])*\)/,
lookbehind: true,
inside: powershell
},
'boolean': powershell.boolean,
'variable': powershell.variable,
};

}(Prism));

Some generated files are not rendered by default. Learn more.

0 comments on commit d30a2da

Please sign in to comment.