|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + HCL PipeScript Transpiler. |
| 4 | +.DESCRIPTION |
| 5 | + Transpiles HCL with Inline PipeScript into HCL. |
| 6 | +
|
| 7 | + Multiline comments blocks like ```/*{}*/``` 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 | + * ```null``` |
| 12 | + * ```""``` |
| 13 | + * ```{}``` |
| 14 | + * ```[]``` |
| 15 | +#> |
| 16 | +[ValidatePattern('\.hcl$')] |
| 17 | +param( |
| 18 | +# The command information. This will include the path to the file. |
| 19 | +[Parameter(Mandatory,ValueFromPipeline)] |
| 20 | +[Management.Automation.CommandInfo] |
| 21 | +$CommandInfo, |
| 22 | + |
| 23 | +# A dictionary of parameters. |
| 24 | +[Collections.IDictionary] |
| 25 | +$Parameter, |
| 26 | + |
| 27 | +# A list of arguments. |
| 28 | +[PSObject[]] |
| 29 | +$ArgumentList |
| 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 | + # Create a splat containing arguments to the core inline transpiler |
| 45 | + $Splat = [Ordered]@{ |
| 46 | + StartPattern = $startRegex |
| 47 | + EndPattern = $endRegex |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +process { |
| 52 | + # Add parameters related to the file |
| 53 | + $Splat.SourceFile = $commandInfo.Source -as [IO.FileInfo] |
| 54 | + $Splat.SourceText = [IO.File]::ReadAllText($commandInfo.Source) |
| 55 | + if ($Parameter) { $splat.Parameter = $Parameter } |
| 56 | + if ($ArgumentList) { $splat.ArgumentList = $ArgumentList } |
| 57 | + |
| 58 | + # Call the core inline transpiler. |
| 59 | + .>PipeScript.Inline @Splat |
| 60 | +} |
0 commit comments