Skip to content

Commit 9b84a81

Browse files
author
James Brundage
committed
Adding Inline HAXE transpiler (Fixes #259)
1 parent 50af1bd commit 9b84a81

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<#
2+
.SYNOPSIS
3+
Haxe PipeScript Transpiler.
4+
.DESCRIPTION
5+
Transpiles Haxe with Inline PipeScript into Haxe.
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 Haxe syntax.
12+
13+
The Haxe Inline Transpiler will consider the following syntax to be empty:
14+
15+
* ```null```
16+
* ```""```
17+
* ```''```
18+
#>
19+
[ValidatePattern('\.hx$')]
20+
param(
21+
# The command information. This will include the path to the file.
22+
[Parameter(Mandatory,ValueFromPipeline)]
23+
[Management.Automation.CommandInfo]
24+
$CommandInfo,
25+
26+
# A dictionary of parameters.
27+
[Collections.IDictionary]
28+
$Parameter,
29+
30+
# A list of arguments.
31+
[PSObject[]]
32+
$ArgumentList
33+
)
34+
35+
begin {
36+
# We start off by declaring a number of regular expressions:
37+
$startComment = '/\*' # * Start Comments ```\*```
38+
$endComment = '\*/' # * End Comments ```/*```
39+
$Whitespace = '[\s\n\r]{0,}'
40+
# * IgnoredContext ```String.empty```, ```null```, blank strings and characters
41+
$IgnoredContext = "(?<ignore>(?>$("null", '""', "''" -join '|'))\s{0,}){0,1}"
42+
# * StartRegex ```$IgnoredContext + $StartComment + '{' + $Whitespace```
43+
$startRegex = "(?<PSStart>${IgnoredContext}${startComment}\{$Whitespace)"
44+
# * EndRegex ```$whitespace + '}' + $EndComment + $ignoredContext```
45+
$endRegex = "(?<PSEnd>$Whitespace\}${endComment}\s{0,}${IgnoredContext})"
46+
47+
# Create a splat containing arguments to the core inline transpiler
48+
$Splat = [Ordered]@{
49+
StartPattern = $startRegex
50+
EndPattern = $endRegex
51+
}
52+
}
53+
54+
process {
55+
# Add parameters related to the file
56+
$Splat.SourceFile = $commandInfo.Source -as [IO.FileInfo]
57+
$Splat.SourceText = [IO.File]::ReadAllText($commandInfo.Source)
58+
if ($Parameter) { $splat.Parameter = $Parameter }
59+
if ($ArgumentList) { $splat.ArgumentList = $ArgumentList }
60+
61+
# Call the core inline transpiler.
62+
.>PipeScript.Inline @Splat
63+
}

0 commit comments

Comments
 (0)