Skip to content

Commit 5877861

Browse files
author
James Brundage
committed
Adding Inline Rust Support (#43)
1 parent 433784c commit 5877861

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<#
2+
.SYNOPSIS
3+
Rust Inline PipeScript Transpiler.
4+
.DESCRIPTION
5+
Transpiles Rust with Inline PipeScript into Rust.
6+
7+
Multiline comments with /*{}*/ will be treated as blocks of PipeScript.
8+
#>
9+
[ValidateScript({
10+
$cmdInfo = $_
11+
if ($cmdInfo.Source -match '\.rs$') {
12+
return $true
13+
}
14+
return $false
15+
})]
16+
param(
17+
# The command information. This will include the path to the file.
18+
[Parameter(Mandatory,ValueFromPipeline)]
19+
$CommandInfo
20+
)
21+
22+
begin {
23+
# We start off by declaring a number of regular expressions:
24+
$startComment = '/\*' # * Start Comments ```\*```
25+
$endComment = '\*/' # * End Comments ```/*```
26+
$Whitespace = '[\s\n\r]{0,}'
27+
# * StartRegex ```$IgnoredContext + $StartComment + '{' + $Whitespace```
28+
$startRegex = "(?<PSStart>${startComment}\{$Whitespace)"
29+
# * EndRegex ```$whitespace + '}' + $EndComment + $ignoredContext```
30+
$endRegex = "(?<PSEnd>$Whitespace\}${endComment})"
31+
32+
$sourcePattern = [Regex]::New("(?>$(
33+
$startRegex, $endRegex -join ([Environment]::NewLine + '|' + [Environment]::NewLine)
34+
))", "IgnoreCase, IgnorePatternWhitespace", "00:00:05")
35+
}
36+
37+
process {
38+
$fileInfo = $commandInfo.Source -as [IO.FileInfo]
39+
$fileText = [IO.File]::ReadAllText($fileInfo.Fullname)
40+
41+
.>PipeScript.Inline -SourceFile $CommandInfo.Source -SourceText $fileText -SourcePattern $sourcePattern
42+
}
43+

0 commit comments

Comments
 (0)