| 1 |
#! /usr/local/bin/perl -w |
| 2 |
# |
| 3 |
# naive - generate a regular expression that will lex regular expressions |
| 4 |
# it is naive in the sense that it can't lex certain patterns, such as a |
| 5 |
# pattern that contains nested parentheses (e.g. /ab(?:cd(?ef)?gh)+ij/ ) |
| 6 |
# |
| 7 |
# The emitted regular expression is the default pattern that Regexp::Assemble |
| 8 |
# uses to pick apart a string into tokens suitable for being assembled. If it |
| 9 |
# isn't sufficiently sophisticated, you will have to supply your own lexer. |
| 10 |
# |
| 11 |
# Copyright (C) David Landgren 2004-2005 |
| 12 |
|
| 13 |
use strict; |
| 14 |
|
| 15 |
my $directive = q{[bABCEGLQUXZ]}; |
| 16 |
|
| 17 |
my $punct = q{[^\\w]}; |
| 18 |
|
| 19 |
my $meta = q{[aefnrtdDwWsS]}; |
| 20 |
my $ctrl = q{c.}; |
| 21 |
my $octal = q{0\\d{2}}; |
| 22 |
my $hex = q{x(?:[\\da-fA-F]{2}|{[\\da-fA-F]{4}})}; |
| 23 |
my $named = q{N\\{\w+\\}}; |
| 24 |
my $prop = q{[Pp](?:\\{\w+\\}|.)}; |
| 25 |
|
| 26 |
my $single = q{[^\\w\\/{|}-]}; |
| 27 |
|
| 28 |
my $modifiable = qq{$punct|$meta|$ctrl|$octal|$hex|$named|$prop}; |
| 29 |
|
| 30 |
my $modifier = q{(?:[*+?]\\??|\\{\\d+(?:,\\d*)?\\}\\??)?}; |
| 31 |
|
| 32 |
my $backslash = qq{\\\\(?:$directive|[lu].|(?:$modifiable)$modifier)}; |
| 33 |
|
| 34 |
my $class = q{\\[.*?(?<!\\\\)\\]}; |
| 35 |
my $group = q{\\(.*?(?<!\\\\)\\)}; |
| 36 |
# \$Default_Lexer = qr/(?![[(\\\\]).$modifier|$backslash|$class$modifier|$group$modifier/; |
| 37 |
|
| 38 |
print <<PATTS; |
| 39 |
# The following patterns were generated with eg/naive |
| 40 |
\$Default_Lexer = qr/(?![[(\\\\]).$modifier|$backslash|$class$modifier|$group$modifier/; |
| 41 |
|
| 42 |
\$Single_Char = qr/^(?:\\\\(?:$meta|$ctrl|$single|$octal|$hex)|[^\$^])\$/; |
| 43 |
PATTS |
| 44 |
|
| 45 |
# my brain hurts just looking at this |