Check-in [62d786655f]
Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Fix PMD extraction; again. - Incorrect quoting regex for JSOL - and System.IO.File reading instead of Get-Content to fix CRCRLF files |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
62d786655fe48779a61a914a5807942d |
User & Date: | mario 2018-04-14 20:17:55 |
Context
2018-04-15
| ||
13:13 | Whitelist allowed WPF colors (DarkYellow is a console, but not a WPF color name). Readd Button for TreeView actions list. check-in: 9d39e749dd user: mario tags: trunk | |
2018-04-14
| ||
20:17 | Fix PMD extraction; again. - Incorrect quoting regex for JSOL - and System.IO.File reading instead of Get-Content to fix CRCRLF files check-in: 62d786655f user: mario tags: trunk | |
20:16 | Split out New-GuiVarInput (input widget building) from Read-GuiExtraParams. Change order of VALUE= preference (standard vars over previous values); experimental support for expression specs in `# vars: { value=$(Get-IP $machine)}` Various comment updates. check-in: 279befd338 user: mario tags: trunk | |
Changes
Changes to modules/menu.psm1.
︙ | ︙ | |||
98 99 100 101 102 103 104 | #-- config: list extraction function Extract-PluginConfig() { <# .DESCRIPTION Unpacks the JSOL-style config{} and vars{} lists. #> Param($block, $_cfg=@(), $S="'", $D='"') | | | | | | | | > | > | | | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | #-- config: list extraction function Extract-PluginConfig() { <# .DESCRIPTION Unpacks the JSOL-style config{} and vars{} lists. #> Param($block, $_cfg=@(), $S="'", $D='"') preg_match_all -rx "\{((?>\s+|[^$S$D\}]+|$S[^$S]+$S|$D[^$D]+$D)+)\}" -str $block | % { $r = @{}; # varname = literal "quoted" "single quoted" preg_match_all -rx "(?x) [$]?([\w.-]+) \s*[:=]\s* (?: ([^,;$D'}]+) | $D([^$D]+)$D | '([^']+)' ) " -str $_[1] | % { $r[$_[1]] = (($_[2..5] -ne "")[0]).trim() }; $_cfg += $r; } return $_cfg } #-- baseline plugin meta data support function Extract-PluginMeta() { <# .SYNOPSIS Reads top-comment block and plugin meta data from given filename .DESCRIPTION Plugin meta data is a cross-language documentation scheme to manage application-level feature plugins. This function reads the leading comment and converts key:value entries into a hash. .PARAMERER fn Script to read from .OUTPUTS Returns a HashTable of field: values, including the config: list/hash. .EXAMPLE In ClickyColoury it reads all "plugins" at once like this: $menu = (Get-Iten tools*/*.ps1 | % { Extract-PluginMeta $_ }) Entries than can be accessed like: $menu | % { $_.title -and $_.category -eq "network" } .NOTES Each entry contains an .id basename and .fn field, additionaly to what the plugin itself defines. Packs comment remainder as .doc field. #> Param($fn, $meta=@{}) # read file $str = [System.IO.File]::ReadAllText($fn) -replace "\r+\n","`n" # rx simplify and CRCRLF fix # look for first comment block if ($m = [regex]::match($str, '(?m)((?:^[ \t]{0,8}#+.*\r*\n)+|<#[\s\S]+?#>)')) { # remove leading #␣ from lines, then split remainder comment $str = $m.groups[1] -replace "(?m)^\s*#[ \t]{0,3}", "" $str, $doc = [regex]::split($str, '\n\n') # find all `key:value` pairs preg_match_all -rx "(?m)^([\w-]+):\s*(.*(?:$)(?:\n(?!\w+:).+$)*)" -str $str | % { $meta[$_[1]] = $_[2].trim() } # split out config: and vars: (into list of dicts) $meta.config = @(Extract-PluginConfig ($meta.config)) $meta.vars = @(Extract-PluginConfig ($meta.vars)) # merge into hashtable $meta.fn = "$fn" $meta.id = ($fn -replace "^.+[\\/]|\.\w+$","") -replace "[^\w]","_" $meta.doc = ($doc -join "`r`n") } return $meta # or return as (New-Object PSCustomObject -Prop $meta) |
︙ | ︙ |