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