-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPython-Language.ps.ps1
More file actions
61 lines (54 loc) · 1.76 KB
/
Python-Language.ps.ps1
File metadata and controls
61 lines (54 loc) · 1.76 KB
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
Language function Python {
<#
.SYNOPSIS
Python Language Definition.
.DESCRIPTION
Allows PipeScript to generate Python.
Because Python does not support multiline comment blocks, PipeScript can be written inline inside of multiline string
PipeScript can be included in a Python string that starts and ends with ```{}```, for example ```"""{}"""```
.EXAMPLE
'print("Hello World")' > .\HelloWorld.py
Invoke-PipeScript .\HelloWorld.py
.EXAMPLE
Template.HelloWorld.py -Message "Hi" | Set-Content ".\Hi.py"
Invoke-PipeScript .\Hi.py
#>
[ValidatePattern('\.py$')]
param()
# The File Pattern for Python is any `.py` files.
$FilePattern = '\.py$'
# Python doesn't have multi-line comments per se, but it does have ignored block strings.
# So any `"""{` will start a block
$startComment = '(?>"""\{)'
# and any `}###` will end a block.
$endComment = '(?>\}""")'
$startPattern = "(?<PSStart>${startComment})"
$endPattern = "(?<PSEnd>${endComment})"
# The interpreter for Python is "python" (if present)
$Interpreter = 'python'
# The keywords map for Python is as follows:
$Keywords = Object @{
"def" = 'function ($Parameters)
$Body
'
"class" = 'class ${Name}:
$Members
'
"if" = 'if'
"elseif" = "elif"
"else" = "else"
"for" = "foreach", "for"
"raise" = "throw"
"break" = "break"
"continue" = "continue"
"not" = "-not"
"or" = "-or"
"and" = "-and"
"nonlocal" = '`$global:$VariablePath'
"True" = $true
"False" = $false
"while" = "while"
"yield" = ""
"import" = "import"
}
}