File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ <#
2+ . SYNOPSIS
3+ PHP PipeScript Transpiler.
4+ . DESCRIPTION
5+ Transpiles PHP with Inline PipeScript into PHP.
6+
7+ Multiline comments blocks like this ```<!--{}-->``` will be treated as blocks of PipeScript.
8+
9+ JavaScript/CSS/PHP comment blocks like ```/*{}*/``` will also be treated as blocks of PipeScript.
10+ #>
11+ [ValidateScript ({
12+ $cmdInfo = $_
13+ if ($cmdInfo.Source -match ' \.php$' ) {
14+ return $true
15+ }
16+ return $false
17+ })]
18+ param (
19+ # The command information. This will include the path to the file.
20+ [Parameter (Mandatory , ValueFromPipeline )]
21+ $CommandInfo
22+ )
23+
24+ begin {
25+ # We start off by declaring a number of regular expressions:
26+ $startComment = ' (?><\!--|/\*)' # * Start Comments ```<!--```
27+ $endComment = ' (?>-->|\*/)' # * End Comments ```-->```
28+ $Whitespace = ' [\s\n\r]{0,}'
29+ # * StartRegex ```$StartComment + '{' + $Whitespace```
30+ $startRegex = " (?<PSStart>${startComment} \{$Whitespace )"
31+ # * EndRegex ```$whitespace + '}' + $EndComment```
32+ $endRegex = " (?<PSEnd>$Whitespace \}${endComment} \s{0,})"
33+
34+ $sourcePattern = [Regex ]::New(" (?>$ (
35+ $startRegex , $endRegex -join ([Environment ]::NewLine + ' |' + [Environment ]::NewLine)
36+ ) )" , " IgnoreCase, IgnorePatternWhitespace" , " 00:00:05" )
37+ }
38+
39+ process {
40+
41+ $fileInfo = $commandInfo.Source -as [IO.FileInfo ]
42+ $fileText = [IO.File ]::ReadAllText($fileInfo.Fullname )
43+
44+ .> PipeScript.Inline - SourceFile $CommandInfo.Source - SourceText $fileText - SourcePattern $sourcePattern
45+ }
You can’t perform that action at this time.
0 commit comments