Skip to content

Commit

Permalink
feat: Language.Filter(s) ( Fixes #1080 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Mar 20, 2024
1 parent db904da commit 8dcc458
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions Types/Language/Alias.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@{
Templates = 'Template'
Functions = 'Function'
Filters = 'Filter'
Aliases = 'Alias'
}
31 changes: 31 additions & 0 deletions Types/Language/get_Filter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<#
.SYNOPSIS
Gets Language Filters
.DESCRIPTION
Gets Filters related to a language.
Filters are a special type of function that are used to filter or transform data.
These are filters that either match a language's `.FilePattern` or start with a language name, followed by punctuation.
#>
if (-not $global:AllFunctionsAndAliases) {
$global:AllFunctionsAndAliases = $global:ExecutionContext.SessionState.InvokeCommand.GetCommand('*','Function',$true)
}
$FunctionsForThisLanguage = [Ordered]@{PSTypeName='Language.Functions'}
if ($this.FilePattern) {
foreach ($FunctionForLanguage in $global:AllFunctionsAndAliases -match $this.FilePattern) {
if (-not $FunctionsForThisLanguage.IsFilter) {continue }
$FunctionsForThisLanguage["$FunctionForLanguage"] = $FunctionForLanguage
}
}
if ($this.LanguageName) {
foreach ($FunctionForLanguage in $global:AllFunctionsAndAliases -match "(?<=(?>^|[\p{P}-[\\]]))$([Regex]::Escape($this.LanguageName))[\p{P}-[\\]]") {
if (-not $FunctionsForThisLanguage.IsFilter) {continue }
$FunctionsForThisLanguage["$FunctionForLanguage"] = $FunctionForLanguage
}
}

$FunctionsForThisLanguage = [PSCustomObject]$FunctionsForThisLanguage
$FunctionsForThisLanguage.pstypenames.insert(0,"$($this.LanguageName).Functions")
$FunctionsForThisLanguage

0 comments on commit 8dcc458

Please sign in to comment.