Skip to content

Commit 8136ab3

Browse files
committed
update completions and changelog
1 parent 6a32f68 commit 8136ab3

File tree

4 files changed

+166
-77
lines changed

4 files changed

+166
-77
lines changed

CHANGELOG.md

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,68 +7,84 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
### New
10+
## [0.12.0] - TBD
1111

12-
- Support for the RE2 flavor
12+
### New
1313

14-
- Intersection of character sets. For example, `[Letter] & [Latin]` matches a letter that is also in the Latin script.
14+
- [RE2](https://github.com/google/re2) flavor added
1515

16-
- Character class prefixes: `gc:` (general category), `sc:` (script), `scx:` (script extension), `blk:` (blocks).
17-
For example, `[scx:Syriac]` matches all characters with the Syriac script extension.
16+
- [Intersection](https://www.regular-expressions.info/charclassintersect.html) of character sets added, using the new `&` operator:
1817

19-
- Adds support for script extensions (currently supported in PCRE, JavaScript, and Rust)
20-
- If the `blk:` prefix is used, `In` must be removed; e.g. `[InPrivate_Use]` becomes `[blk:Private_Use]`
21-
- Writing the prefix is optional, except for script extensions
18+
```pomsky
19+
[Thai] & [Nd] # equivalent to the regex [\p{Thai}&&\p{Nd}]
20+
```
2221

23-
- A `pomsky test` subcommand for running unit tests
22+
Note that subtraction can be achieved by negating the character set to be subtracted:
2423

25-
- Two supported regex engines for testing: `pcre2` and `rust`
26-
- The `--test` argument is now deprecated
24+
```pomsky
25+
[Thai] & ![Nd] # equivalent to the regex [\p{Thai}--\p{Nd}]
26+
```
2727

28-
- Many optimizations (see below)
28+
- Match [Script Extensions](https://www.unicode.org/L2/L2011/11406-script-ext.html), using the `scx:` or `script_extensions:` prefix:
2929

30-
### Changed
30+
```pomsky
31+
[scx:Syriac]
32+
```
3133

32-
- Change hygiene of `lazy` and `unicode` mode to behave as one would expect.
33-
Going forward, modes depend on the scope where an expression is defined, not where it is used:
34+
Other Unicode properties also get optional prefixes:
3435

3536
```pomsky
36-
let foo = 'foo'*; # this repetition is not lazy
37-
(enable lazy; foo)
37+
# old # new # alternative
38+
[Latin] [sc:Latin] [script:Latin]
39+
[InGreek] [blk:Greek] [block:Greek]
40+
[Letter] [gc:Letter] [general_category:Letter]
3841
```
3942

40-
- Increase the maximum length of group names from 32 to 128 characters.
41-
Group names this long are supported in PCRE2 since version 10.44.
43+
Note that for the `In` prefix of Unicode blocks is omitted when the `blk:` or `block:` prefix is used. Unicode blocks with `In` instead of `blk:` will be deprecated.
4244

43-
- Produce an error if the contents of a lookbehind assertion are not supported by the regex flavor (Java, Python, PCRE)
45+
- `pomsky test` subcommand added to compile and test all `*.pomsky` files in a directory. This command ignores files matched by a `.ignore` or `.gitignore` file. For help, run `pomsky test --help`.
4446

45-
- Produce an error if infinite recursion is detected
47+
- Unit tests can now be run with the Rust `regex` crate. To use it, specify `--flavor=rust` or `--engine=rust`.
4648

47-
- Remove the compatibility warning for lookbehind in JavaScript.
48-
Lookbehind is now widely supported in JavaScript engines.
49+
- Diagnostic to detect infinite recursion. If a recursive expression can never terminate, an error is shown.
4950

50-
- Allow all supported boolean Unicode properties in the Java flavor
51+
### Changes
5152

52-
- Deprecate the `--test` argument; use `pomsky test -p <PATH>` instead
53+
- `lazy` and `unicode` mode is no longer inherited when expanding variables.
5354

54-
### Optimizations
55+
> [!IMPORTANT]
56+
> This changes the meaning of expressions such as this:
57+
>
58+
> ```pomsky
59+
> let variable = 'test'*;
60+
> enable lazy;
61+
> variable
62+
> ```
63+
>
64+
> Before Pomsky 0.12, the repetition was lazy, but now it isn't.
5565
56-
- De-duplicate and merge character ranges: `['b' 'a'-'f' 'c'-'m']` becomes `[a-m]`
66+
The `enable` or `disable` statement has to appear before the repetition _syntactically_, it doesn't matter where the variable is used. The old behavior was too unintuitive and easy to mess up, so we fixed it.
5767
58-
- Note that this doesn't work with Unicode classes, e.g. `Alphabetic`
68+
- Optimize single-character alternatives, and merge adjacent or overlapping ranges.
5969
60-
- Merge common alternation prefixes: `'do' | 'double' | 'down'` becomes `do(?:uble|wn)??`
70+
For example, `'a' | ['bc'] | ['f'-'i']` is optimized to `[a-cf-i]`.
6171
62-
- This only works with string literals and character sets, for now
63-
- Only adjacent alternatives can be merged to ensure that precedence isn't affected
72+
> [!NOTE]
73+
> The order of character ranges in a set is no longer preserved. Currently, they are sorted in ascending order; for example, `['x' 'X' 'A'-'F' 'a'-'f']` becomes `[A-FXa-fx]`.
6474
65-
- Combine single-character alternations into a set: `'a' | 'b' | 'c' | 'f'` becomes `[a-cf]`
75+
- No longer warn about lookbehind in JavaScript. Lookbehind is now widely supported.
6676
67-
- Merge constant nested repetitions: `('a'{3}){4}` becomes `a{12}`
77+
- Update Unicode support data for properties added in Unicode 15.x
6878
69-
### Bugfixes
79+
### Fixes
80+
81+
- Allow supported Unicode binary properties in Java (previously, binary properties in Java were unsupported)
82+
83+
- Link PCRE2 statically (previously it was linked dynamically, which doesn't work if PCRE2 isn't installed on the target system)
84+
85+
- Allow Unicode blocks in Ruby, but not PCRE
7086
71-
- Do not miscompile `[r]`
87+
- Output `[r]` as `\r`, not as `\n` (this was a bug introduced by normalizing verbatim line endings in strings).
7288
7389
## [0.11.0] - 2023-11-09
7490

completions/pomsky.bash

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,53 @@
11
_complete_pomsky()
22
{
3-
local flavors="pcre python java js dotnet ruby rust"
4-
local flavors_concat="-fpcre -fpython -fjava -fjs -fdotnet -fruby -frust"
3+
local flavors="pcre python java js dotnet ruby rust re2"
4+
local flavors_concat="-fpcre -fpython -fjava -fjs -fdotnet -fruby -frust -fre2"
5+
6+
local engines="pcre2 rust"
7+
local engines_concat="-epcre2 -erust"
8+
59
local warnings="0 compat=0 deprecated=0"
610
local warnings_concat="-W0 -Wcompat=0 -Wdeprecated=0"
11+
712
local features="atomic-groups boundaries dot grapheme lazy-mode lookahead lookbehind named-groups numbered-groups ranges recursion references regexes variables"
8-
local flags="--allowed-features --flavor --help --no-new-line --path --test --version --warnings --debug --json --list"
13+
14+
local flags_and_subcommands="test --allowed-features --flavor --help --no-new-line --path --test --version --warnings --debug --json --list"
15+
local test_flags="--allowed-features --engine --flavor --help --pass-with-no-tests --path --version --warnings --debug --json"
916

1017
local cur=${COMP_WORDS[COMP_CWORD]}
1118
local prev=${COMP_WORDS[COMP_CWORD - 1]}
1219

20+
_add_space()
21+
{
22+
for ((i=0; i < ${#COMPREPLY[@]}; i++)); do
23+
COMPREPLY[$i]="${COMPREPLY[$i]} "
24+
done
25+
}
26+
27+
_add_space_or_slash()
28+
{
29+
# add '/' after directories and a space after files
30+
for ((i=0; i < ${#COMPREPLY[@]}; i++)); do
31+
if [ -d "${COMPREPLY[$i]}" ]; then
32+
COMPREPLY[$i]="${COMPREPLY[$i]}/"
33+
else
34+
COMPREPLY[$i]="${COMPREPLY[$i]} "
35+
fi
36+
done
37+
}
38+
1339
case "$prev" in
1440
-p | --path)
1541
COMPREPLY=( $( compgen -o plusdirs -f -- $cur ) )
16-
17-
# add '/' after directories and a space after files
18-
for ((i=0; i < ${#COMPREPLY[@]}; i++)); do
19-
if [ -d "${COMPREPLY[$i]}" ]; then
20-
COMPREPLY[$i]="${COMPREPLY[$i]}/"
21-
else
22-
COMPREPLY[$i]="${COMPREPLY[$i]} "
23-
fi
24-
done
42+
_add_space_or_slash
2543
return 0;
2644
;;
2745
-f | --flavor)
2846
COMPREPLY=( $( compgen -W "$flavors" -- $cur ) )
2947
;;
48+
-e | --engine)
49+
COMPREPLY=( $( compgen -W "$engines" -- $cur ) )
50+
;;
3051
--list)
3152
COMPREPLY=( $( compgen -W "shorthands" -- $cur ) )
3253
;;
@@ -37,22 +58,28 @@ _complete_pomsky()
3758
COMPREPLY=( $( compgen -W "$features" -- $cur ) )
3859
;;
3960
--test)
40-
COMPREPLY=( $( compgen -W "pcre2" -- $cur ) )
61+
COMPREPLY=( $( compgen -W "$engines" -- $cur ) )
4162
;;
4263
*)
4364
if [[ $cur = -f* ]]; then
4465
COMPREPLY=( $( compgen -W "$flavors_concat" -- $cur ) )
66+
elif [[ $cur = -e* ]]; then
67+
COMPREPLY=( $( compgen -W "$engines_concat" -- $cur ) )
4568
elif [[ $cur = -W* ]]; then
4669
COMPREPLY=( $( compgen -W "$warnings_concat" -- $cur ) )
4770
else
48-
COMPREPLY=( $( compgen -W "$flags" -- $cur ) )
71+
for ((i=1; i < $COMP_CWORD; i++)); do
72+
if [[ ${COMP_WORDS[$i]} = test ]]; then
73+
COMPREPLY=( $( compgen -W "$test_flags" -- $cur ) )
74+
_add_space
75+
return 0;
76+
fi
77+
done
78+
COMPREPLY=( $( compgen -W "$flags_and_subcommands" -- $cur ) )
4979
fi
5080
;;
5181
esac
5282

53-
# add a space after each completion
54-
for ((i=0; i < ${#COMPREPLY[@]}; i++)); do
55-
COMPREPLY[$i]="${COMPREPLY[$i]} "
56-
done
83+
_add_space
5784
}
5885
complete -o nospace -F _complete_pomsky pomsky

completions/pomsky.fish

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,49 @@
11
set -l features \
2-
'ascii-mode atomic-groups boundaries dot grapheme lazy-mode lookahead lookbehind named-groups numbered-groups ranges recursion references regexes variables'
2+
'ascii-mode atomic-groups boundaries dot grapheme intersection lazy-mode lookahead lookbehind named-groups numbered-groups ranges recursion references regexes variables'
3+
34
set -l flavors \
45
'pcre PCRE flavor
56
python Python re flavor
67
java Java flavor
78
js JavaScript (ECMAScript) flavor
89
dotnet C# (.NET) flavor
910
ruby Ruby (Oniguruma) flavor
10-
rust Rust regex flavor'
11+
rust Rust regex flavor
12+
re2 RE2 flavor'
13+
1114
set -l warnings \
1215
'0 Disable all warnings
1316
compat=0 Disable compatibility warnings
1417
deprecated=0 Disable deprecation warnings'
1518

19+
set -l engines \
20+
'pcre2 PCRE2 regex engine
21+
rust Rust crate `regex`'
22+
23+
set -l subcommands \
24+
'test Run unit test suite
25+
'
26+
27+
# subcommands
28+
complete -c pomsky -n "not __fish_seen_subcommand_from test" -fa "(echo \"$subcommands\")"
29+
# disable file completions (-f) for `pomsky test`
30+
complete -c pomsky -f -n '__fish_seen_subcommand_from test'
31+
32+
# global args
1633
complete -c pomsky -l allowed-features -d 'Allowed features, comma-separated' -xa "(__fish_append , $features)"
1734
complete -c pomsky -s f -l flavor -d 'Regex flavor' -xa "(echo \"$flavors\")"
1835
complete -c pomsky -s h -l help -d 'Show help information'
19-
complete -c pomsky -l list -d 'List shorthands' -xa "shorthands"
20-
complete -c pomsky -s n -l no-new-line -d "Don't print line break after the output"
21-
complete -c pomsky -s p -l path -d 'File to compile' -kxa "(__fish_complete_suffix .pom)"
22-
complete -c pomsky -l test -d 'Run unit tests' -xa 'pcre2'
36+
complete -c pomsky -s p -l path -d 'File or directory' -kxa "(__fish_complete_suffix .pomsky)"
2337
complete -c pomsky -s V -l version -d 'Print version information'
2438
complete -c pomsky -s W -l warnings -d 'Disable some or all warnings' -xa "(echo \"$warnings\")"
2539
complete -c pomsky -s d -l debug -d 'Show debug information'
26-
complete -c pomsky -l json -d 'Return output as JSON'
40+
complete -c pomsky -l json -d 'Return output as JSON'
41+
42+
# test args
43+
complete -c pomsky -n "__fish_seen_subcommand_from test" -s e -l engine -d 'Regex engine for unit tests' -xa "(echo \"$engines\")"
44+
complete -c pomsky -n "__fish_seen_subcommand_from test" -l pass-with-no-tests -d 'Succeed if path contains no *.pomsky files'
45+
46+
# non-test args
47+
complete -c pomsky -n "not __fish_seen_subcommand_from test" -l list -d 'List shorthands' -xa "shorthands"
48+
complete -c pomsky -n "not __fish_seen_subcommand_from test" -s n -l no-new-line -d "Don't print line break after the output"
49+
complete -c pomsky -n "not __fish_seen_subcommand_from test" -l test -d 'Run unit tests' -xa "(echo \"$engines\")"

completions/pomsky.zsh

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
11
#compdef pomsky
22

3+
_pomsky_cmds() {
4+
local commands=(
5+
'test:Run unit test suite'
6+
)
7+
_describe -t commands 'commands' commands
8+
}
9+
310
_pomsky_complete_features() {
4-
_values -s , 'features' ascii-mode atomic-groups boundaries dot grapheme lazy-mode lookahead lookbehind named-groups numbered-groups ranges recursion references regexes variables
11+
_values -s , 'features' ascii-mode atomic-groups boundaries dot grapheme intersection lazy-mode lookahead lookbehind named-groups numbered-groups ranges recursion references regexes variables
512
}
613

714
_pomsky_complete_lists() {
8-
lists=(
15+
local lists=(
916
'shorthands:Unicode properties and shorthands'
1017
)
1118
_describe -t lists 'lists' lists
1219
}
1320

1421
_pomsky_complete_engine() {
15-
engine=(
16-
'pcre2:The PCRE2 regex engine'
22+
local engine=(
23+
'pcre2:PCRE2 regex engine'
24+
'rust:Rust crate `regex`'
1725
)
1826
_describe -t engine 'engine' engine
1927
}
2028

2129
_pomsky_complete_flavor() {
22-
flavors=(
30+
local flavors=(
2331
'pcre:PCRE flavor'
2432
'python:Python re flavor'
2533
'java:Java flavor'
2634
'js:JavaScript (ECMAScript) flavor'
2735
'dotnet:C# (.NET) flavor'
2836
'ruby:Ruby (oniguruma) flavor'
2937
'rust:Rust regex flavor'
38+
're2:RE2 flavor'
3039
)
3140
_describe -t flavors 'flavors' flavors
3241
}
@@ -36,25 +45,39 @@ _pomsky_complete_path() {
3645
}
3746

3847
_pomsky_complete_warnings() {
39-
warnings=(0 compat=0 deprecated=0)
48+
local warnings=(
49+
'0:Disable all warnings'
50+
'compat=0:Disable compatibility warnings'
51+
'deprecated=0:Disable deprecation warnings'
52+
)
4053
_describe -t warnings 'warnings' warnings
4154
}
4255

4356
_pomsky() {
4457
local curcontext="$curcontext"
4558

46-
_arguments -s -w -C \
47-
'(--allowed-features)--allowed-features=[Allowed features, comma-separated]: :->features' \
48-
'(-f --flavor)'{-f+,--flavor=}'[Regex flavor]: :->flavor' \
49-
'(-h --help)'{-h+,--help=}'[Show help information]' \
50-
'(--list)--list=[List shorthands]: :->lists' \
51-
'(-n --no-new-line)'{-n,--no-new-line}"[Don't print line break after the output]" \
52-
'(-p --path)'{-p+,--path=}'[File to compile]: :->path' \
53-
'(-test)--test=[Run unit tests]: :->engine' \
54-
'(-V --version)'{-V,--version}'[Print version information]' \
55-
'(-W --warnings)'{-W+,--warnings=}'[Disable some or all warnings]: :->warnings' \
56-
'(-d --debug)'{-d,--debug}'[Show debug information]' \
59+
local global_args=(
60+
'(--allowed-features)--allowed-features=[Allowed features, comma-separated]: :->features'
61+
'(-f --flavor)'{-f+,--flavor=}'[Regex flavor]: :->flavor'
62+
'(-h --help)'{-h,--help}'[Show help information]'
63+
'(-p --path)'{-p+,--path=}'[File or directory]: :->path'
64+
'(-V --version)'{-V,--version}'[Print version information]'
65+
'(-W --warnings)'{-W+,--warnings=}'[Disable some or all warnings]: :->warnings'
66+
'(-d --debug)'{-d,--debug}'[Show debug information]'
5767
'(--json)--json[Return output as JSON]'
68+
)
69+
local test_args=(
70+
'(-e --engine)'{-e+,--engine=}'[Regex engine for unit tests]: :->engine'
71+
'(--pass-with-no-tests)--pass-with-no-tests[Succeed if path contains no *.pomsky files]'
72+
)
73+
local non_test_args=(
74+
'(--list)--list=[List shorthands]: :->lists'
75+
'(-n --no-new-line)'{-n,--no-new-line}"[Don't print line break after the output]"
76+
'(--test)--test=[Run unit tests]: :->engine'
77+
)
78+
79+
# emit everything, because I haven't figured out how to do it properly
80+
_arguments -s -w -C '1: :_pomsky_cmds' $global_args $non_test_args $test_args
5881

5982
case $state in
6083
(none) ;;

0 commit comments

Comments
 (0)