-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathGCode-Language.ps1
More file actions
49 lines (39 loc) · 1.59 KB
/
GCode-Language.ps1
File metadata and controls
49 lines (39 loc) · 1.59 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
function Language.GCode {
<#
.SYNOPSIS
GCode PipeScript Language Definition
.DESCRIPTION
Allows PipeScript to generate GCode.
PipeScript can be embedded within comments of GCode.
`'{` marks the start of a PipeScript block
`'}` marks the end of a PipeScript block
#>
[ValidatePattern('\.(?>gx|gcode|nc)$')]
param()
$this = $myInvocation.MyCommand
if (-not $this.Self) {
$languageDefinition = New-Module {
param()
# GCode files end in `.gx`, `.gcode`, or `.nc`
$FilePattern = '\.(?>gx|gcode|nc)$'
# GCode supports single line comments only. They start with `;`
$SingleLineCommentStart = ";"
# Any Language can be parsed with a series of regular expresssions.
# For languages that only support single comments:
# * The capture group IsSingleLine must be defined.
# * Whitespace should not be allowed (it makes nested blocks hard to end)
$startComment = "(?>(?<IsSingleLine>$SingleLineCommentStart)(?>PipeScript|PS)?\{)"
$endComment = "(?>$SingleLineCommentStart(?:PipeScript)?\})"
# To support templates, a language has to declare `$StartPattern` and `$EndPattern`:
$StartPattern = "(?<PSStart>${startComment})"
$EndPattern = "(?<PSEnd>${endComment})"
$LanguageName = 'GCode'
Export-ModuleMember -Variable * -Function * -Alias *
} -AsCustomObject
$languageDefinition.pstypenames.clear()
$languageDefinition.pstypenames.add("Language")
$languageDefinition.pstypenames.add("Language.GCode")
$this.psobject.properties.add([PSNoteProperty]::new('Self',$languageDefinition))
}
$this.Self
}