-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSQL-Language.ps1
More file actions
88 lines (69 loc) · 2.2 KB
/
SQL-Language.ps1
File metadata and controls
88 lines (69 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
[ValidatePattern("(?>SQL|Language)[\s\p{P}]")]
param()
function Language.SQL {
<#
.SYNOPSIS
SQL PipeScript Language Definition.
.DESCRIPTION
Allows PipeScript to generate SQL.
PipeScript can be embedded in multiline or singleline format
In multiline format, PipeScript will be embedded within: `/*{...}*/`
In single line format
-- { or -- PipeScript{ begins a PipeScript block
-- } or -- }PipeScript ends a PipeScript block
```SQL
-- {
Uncommented lines between these two points will be ignored
-- # Commented lines will become PipeScript / PowerShell.
-- param($message = 'hello world')
-- "-- $message"
-- }
```
.EXAMPLE
Invoke-PipeScript {
$SQLScript = '
-- {
Uncommented lines between these two points will be ignored
-- # Commented lines will become PipeScript / PowerShell.
-- param($message = "hello world")
-- "-- $message"
-- }
'
[OutputFile('.\HelloWorld.ps1.sql')]$SQLScript
}
Invoke-PipeScript .\HelloWorld.ps1.sql
#>
[ValidatePattern('\.sql$')]
param()
$this = $myInvocation.MyCommand
if (-not $this.Self) {
$languageDefinition = New-Module {
param()
$FilePattern = '\.sql$'
# We start off by declaring a number of regular expressions:
$startComment = '(?>
(?>
(?<IsSingleLine>--)|
/\*
)\s{0,}(?:PipeScript)?\s{0,}\{)'
$endComment = '(?>
--\s{0,}\}\s{0,}(?:PipeScript)?
|
\}\*/(?:PipeScript)?\s{0,}
)
'
$startPattern = "(?<PSStart>${startComment})"
$endPattern = [Regex]::new("(?<PSEnd>${endComment})",'IgnoreCase,IgnorePatternWhitespace')
# Create a splat containing arguments to the core inline transpiler
# Using -LinePattern will skip any inline code not starting with --
$LinePattern = "^\s{0,}--\s{0,}"
$LanguageName = 'SQL'
Export-ModuleMember -Variable * -Function * -Alias *
} -AsCustomObject
$languageDefinition.pstypenames.clear()
$languageDefinition.pstypenames.add("Language")
$languageDefinition.pstypenames.add("Language.SQL")
$this.psobject.properties.add([PSNoteProperty]::new('Self',$languageDefinition))
}
$this.Self
}