Skip to content

Commit 94c275b

Browse files
author
James Brundage
committed
Adding Inline Kotlin Transpiler (#110)
1 parent 4059685 commit 94c275b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<#
2+
.SYNOPSIS
3+
Kotlin Inline PipeScript Transpiler.
4+
.DESCRIPTION
5+
Transpiles Kotlin with Inline PipeScript into Kotlin.
6+
7+
Multiline comments with /*{}*/ will be treated as blocks of PipeScript.
8+
9+
Multiline comments can be preceeded or followed by 'empty' syntax, which will be ignored.
10+
11+
This for Inline PipeScript to be used with operators, and still be valid Kotlin syntax.
12+
13+
The Kotlin Inline PipeScript Transpiler will consider the following syntax to be empty:
14+
15+
* ```null```
16+
* ```""```
17+
* ```''```
18+
#>
19+
[ValidateScript({
20+
$cmdInfo = $_
21+
if ($cmdInfo.Source -match '\.kt$') {
22+
return $true
23+
}
24+
return $false
25+
})]
26+
param(
27+
# The command information. This will include the path to the file.
28+
[Parameter(Mandatory,ValueFromPipeline)]
29+
$CommandInfo
30+
)
31+
32+
begin {
33+
# We start off by declaring a number of regular expressions:
34+
$startComment = '/\*' # * Start Comments ```\*```
35+
$endComment = '\*/' # * End Comments ```/*```
36+
$Whitespace = '[\s\n\r]{0,}'
37+
# * IgnoredContext ```String.empty```, ```null```, blank strings and characters
38+
$IgnoredContext = "(?<ignore>(?>$("null", '""', "''" -join '|'))\s{0,}){0,1}"
39+
# * StartRegex ```$IgnoredContext + $StartComment + '{' + $Whitespace```
40+
$startRegex = "(?<PSStart>${IgnoredContext}${startComment}\{$Whitespace)"
41+
# * EndRegex ```$whitespace + '}' + $EndComment + $ignoredContext```
42+
$endRegex = "(?<PSEnd>$Whitespace\}${endComment}\s{0,}${IgnoredContext})"
43+
}
44+
45+
process {
46+
47+
$fileInfo = $commandInfo.Source -as [IO.FileInfo]
48+
$fileText = [IO.File]::ReadAllText($fileInfo.Fullname)
49+
50+
.>PipeScript.Inline -SourceFile $CommandInfo.Source -SourceText $fileText -StartPattern $startRegex -EndPattern $endRegex
51+
}

0 commit comments

Comments
 (0)