This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl #8904] Revamp [:posix:] parsing
authorKarl Williamson <khw@cpan.org>
Tue, 9 Feb 2016 18:50:04 +0000 (11:50 -0700)
committerKarl Williamson <khw@cpan.org>
Wed, 10 Feb 2016 06:30:54 +0000 (23:30 -0700)
commit46d34d0e1e7de87f74f8b2df4b32f291baf21dbb
treed1c55a71af5488e197ca31951e49f480adb1c325
parentd8fd4ea0c782a6d356681b28eb35e215d74e4ccd
PATCH: [perl #8904] Revamp [:posix:] parsing

A problem with bracketed character classes, qr/[foo]/, is that there is
very little structure about them, so almost anything is legal, and so
typos just silently compile into something unintended.  One of the
possible components are posix character classes.  There are 14 of them,
and they have a very restricted structure, which is easy to get slightly
wrong, so that instead of the intended posix class being compiled,
something else silently is created.  This commit causes the regex
compiler to look for slightly misspelled posix character classes and to
raise a warning when found.  It does not change the results of the
compilation.

To do this, it introduces fuzzy parsing into the regex compiler, using
the Damerau-Levenshtein algorithm to find out how many single character
edits it would take to transform the input into one of the 14 classes.
If it is 1 or 2 off, it considers the input to have been intended to be
that class and raises the warning.  If more edits would be needed, it
remains silent.

This is a heuristic, and someone could have made enough typos that this
thinks a class wasn't intended that was.  Conversely it could raise a
warning when no class was intended, though warnings only happen when the
input very closely resembles a posix class of one of the 14 legal ones.
The algorithm can be tweaked if experience indicates it should.  But the
bottom line is that many more cases of unintended results will now be
warned about.

Things like having blanks in the construct and having the '^' before the
colon are recognized as being intended posix classes (given that the
actual names are close to one of the 14), and raise warnings.  Again
this commit does not change what gets compiled.  This found a bug in
autodoc.pl which was fixed a few commits ago.

The [. .] and [= =] POSIX constructs cause perl to croak that they are
unimplemented.  This commit improves the parsing of these two, and fixes
some false positives.  See
http://nntp.perl.org/group/perl.perl5.porters/230975

The new code combines two functions in regcomp.c into one new one.
embed.fnc
embed.h
pod/perldelta.pod
pod/perldiag.pod
proto.h
regcomp.c
t/lib/warnings/regcomp
t/re/reg_mesg.t