Skip to content

Commit

Permalink
Powershell: Fixed lookbehind + refactoring (#3245)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Dec 10, 2021
1 parent 5688f48 commit d30a2da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
26 changes: 12 additions & 14 deletions components/prism-powershell.js
Expand Up @@ -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: /'(?:[^']|'')*'/,
Expand All @@ -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));
2 changes: 1 addition & 1 deletion components/prism-powershell.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d30a2da

Please sign in to comment.