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