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