Skip to content

Commit 4b82c4d

Browse files
author
James Brundage
committed
Adding Inline Racket Transpiler (Fixes #262)
1 parent 7ff3268 commit 4b82c4d

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<#
2+
.SYNOPSIS
3+
Racket Inline PipeScript Transpiler.
4+
.DESCRIPTION
5+
Transpiles Racket with Inline PipeScript into Racket.
6+
7+
Multiline comments blocks enclosed with {} will be treated as Blocks of PipeScript.
8+
9+
Multiline comments can be preceeded or followed by single-quoted strings, which will be ignored.
10+
11+
* ```''```
12+
* ```{}```
13+
#>
14+
[ValidatePattern('\.rkt$')]
15+
param(
16+
# The command information. This will include the path to the file.
17+
[Parameter(Mandatory,ValueFromPipeline)]
18+
[Management.Automation.CommandInfo]
19+
$CommandInfo,
20+
21+
# A dictionary of parameters.
22+
[Collections.IDictionary]
23+
$Parameter,
24+
25+
# A list of arguments.
26+
[PSObject[]]
27+
$ArgumentList
28+
)
29+
30+
begin {
31+
# We start off by declaring a number of regular expressions:
32+
$startComment = '\#\|' # * Start Comments ```#|```
33+
$endComment = '\|\#' # * End Comments ```|#```
34+
$Whitespace = '[\s\n\r]{0,}'
35+
# * IgnoredContext (single-quoted strings)
36+
# * StartRegex ```$IgnoredContext + $StartComment + '{' + $Whitespace```
37+
$startRegex = [Regex]::New("(?<PSStart>${startComment}\{$Whitespace)", 'IgnorePatternWhitespace')
38+
# * EndRegex ```$whitespace + '}' + $EndComment + $ignoredContext```
39+
$endRegex = "(?<PSEnd>$Whitespace\}${endComment}[\s-[\r\n]]{0,})"
40+
41+
# Create a splat containing arguments to the core inline transpiler
42+
$Splat = [Ordered]@{
43+
StartPattern = $startRegex
44+
EndPattern = $endRegex
45+
}
46+
}
47+
48+
process {
49+
# Add parameters related to the file
50+
$Splat.SourceFile = $commandInfo.Source -as [IO.FileInfo]
51+
$Splat.SourceText = [IO.File]::ReadAllText($commandInfo.Source)
52+
if ($Parameter) { $splat.Parameter = $Parameter }
53+
if ($ArgumentList) { $splat.ArgumentList = $ArgumentList }
54+
55+
# Call the core inline transpiler.
56+
.>PipeScript.Inline @Splat
57+
}

0 commit comments

Comments
 (0)