|
| 1 | + |
| 2 | +function Language.Conf { |
| 3 | +<# |
| 4 | + .SYNOPSIS |
| 5 | + Conf PipeScript Language Definition |
| 6 | + .DESCRIPTION |
| 7 | + Allows PipeScript to generate conf files |
| 8 | + #> |
| 9 | +[ValidatePattern('\.conf$')] |
| 10 | +param() |
| 11 | +$this = $myInvocation.MyCommand |
| 12 | +if (-not $this.Self) { |
| 13 | +$languageDefinition = New-Module { |
| 14 | + param() |
| 15 | + |
| 16 | + $FilePattern = '\.conf' |
| 17 | + |
| 18 | + # Conf supports single line comments only. They start with `;` or `#` |
| 19 | + $SingleLineCommentStart = "[;#]" |
| 20 | + |
| 21 | + # Any Language can be parsed with a series of regular expresssions. |
| 22 | + # For languages that only support single comments: |
| 23 | + # * The capture group IsSingleLine must be defined. |
| 24 | + # * Whitespace should not be allowed (it makes nested blocks hard to end) |
| 25 | + $startComment = "(?>(?<IsSingleLine>$SingleLineCommentStart)(?>PipeScript|PS)?\{)" |
| 26 | + $endComment = "(?>$SingleLineCommentStart(?:PipeScript)?\})" |
| 27 | + |
| 28 | + # To support templates, a language has to declare `$StartPattern` and `$EndPattern`: |
| 29 | + $StartPattern = "(?<PSStart>${startComment})" |
| 30 | + $EndPattern = "(?<PSEnd>${endComment})" |
| 31 | + |
| 32 | + # Conf files are a data language |
| 33 | + $DataLanguage = $true |
| 34 | + # and are generally case sensitive. |
| 35 | + $CaseSensitive = $true |
| 36 | + $LanguageName = 'Conf' |
| 37 | + Export-ModuleMember -Variable * -Function * -Alias * |
| 38 | +} -AsCustomObject |
| 39 | +$languageDefinition.pstypenames.clear() |
| 40 | +$languageDefinition.pstypenames.add("Language") |
| 41 | +$languageDefinition.pstypenames.add("Language.Conf") |
| 42 | +$this.psobject.properties.add([PSNoteProperty]::new('Self',$languageDefinition)) |
| 43 | +} |
| 44 | +$this.Self |
| 45 | +} |
| 46 | + |
| 47 | + |
0 commit comments