|
| 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