|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Objective C PipeScript Transpiler. |
| 4 | +.DESCRIPTION |
| 5 | + Transpiles Objective C/C++ with Inline PipeScript into Objective C/C++. |
| 6 | +
|
| 7 | + Multiline comments with /*{}*/ 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 | + This for Inline PipeScript to be used with operators, and still be valid C/C++ syntax. |
| 12 | +
|
| 13 | + The Objective C Inline Transpiler will consider the following syntax to be empty: |
| 14 | +
|
| 15 | + * ```null``` |
| 16 | + * ```nil``` |
| 17 | + * ```""``` |
| 18 | + * ```''``` |
| 19 | +#> |
| 20 | +[ValidateScript({ |
| 21 | + $cmdInfo = $_ |
| 22 | + if ($cmdInfo.Source -match '\.(?>m|mm)$') { |
| 23 | + return $true |
| 24 | + } |
| 25 | + return $false |
| 26 | +})] |
| 27 | +param( |
| 28 | +# The command information. This will include the path to the file. |
| 29 | +[Parameter(Mandatory,ValueFromPipeline)] |
| 30 | +$CommandInfo |
| 31 | +) |
| 32 | + |
| 33 | +begin { |
| 34 | + # We start off by declaring a number of regular expressions: |
| 35 | + $startComment = '/\*' # * Start Comments ```\*``` |
| 36 | + $endComment = '\*/' # * End Comments ```/*``` |
| 37 | + $Whitespace = '[\s\n\r]{0,}' |
| 38 | + # * IgnoredContext ```String.empty```, ```null```, blank strings and characters |
| 39 | + $IgnoredContext = "(?<ignore>(?>$("null", "nil", '""', "''" -join '|'))\s{0,}){0,1}" |
| 40 | + # * StartRegex ```$IgnoredContext + $StartComment + '{' + $Whitespace``` |
| 41 | + $startRegex = "(?<PSStart>${IgnoredContext}${startComment}\{$Whitespace)" |
| 42 | + # * EndRegex ```$whitespace + '}' + $EndComment + $ignoredContext``` |
| 43 | + $endRegex = "(?<PSEnd>$Whitespace\}${endComment}\s{0,}${IgnoredContext})" |
| 44 | + |
| 45 | + $sourcePattern = [Regex]::New("(?>$( |
| 46 | + $startRegex, $endRegex -join ([Environment]::NewLine + '|' + [Environment]::NewLine) |
| 47 | + ))", "IgnoreCase, IgnorePatternWhitespace", "00:00:05") |
| 48 | +} |
| 49 | + |
| 50 | +process { |
| 51 | + $fileInfo = $commandInfo.Source -as [IO.FileInfo] |
| 52 | + $fileText = [IO.File]::ReadAllText($fileInfo.Fullname) |
| 53 | + |
| 54 | + .>PipeScript.Inline -SourceFile $CommandInfo.Source -SourceText $fileText -SourcePattern $sourcePattern |
| 55 | +} |
0 commit comments