summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-04-20 00:56:58 -0700
committerKaz Kylheku <kaz@kylheku.com>2012-04-20 00:56:58 -0700
commit0c52734b814927c3ec00ea6b9336dac0cdc9a8c0 (patch)
tree1380a694a530d0b6c9f0d53958e0ddc1c76162fe
parentc3c43fd39c715827de5cc74846ba977c5b1d2181 (diff)
downloadtxr-0c52734b814927c3ec00ea6b9336dac0cdc9a8c0.tar.gz
txr-0c52734b814927c3ec00ea6b9336dac0cdc9a8c0.tar.bz2
txr-0c52734b814927c3ec00ea6b9336dac0cdc9a8c0.zip
* regex.c (regex_space_chars): Variable removed.
(char_set_addr_str): New function. (char_set_compile): Use char_set_addr_str to add spaces to set. (init_special_char_sets): Use char_set_addr_str to add spaces to set. Bugfix: word_cs, cword_cs wrongly initialized. (regex_init): Removed reference to regex_space_chars.
-rw-r--r--ChangeLog10
-rw-r--r--regex.c38
2 files changed, 26 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index 4497be3b..9af0e5b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2012-04-20 Kaz Kylheku <kaz@kylheku.com>
+ * regex.c (regex_space_chars): Variable removed.
+ (char_set_addr_str): New function.
+ (char_set_compile): Use char_set_addr_str to
+ add spaces to set.
+ (init_special_char_sets): Use char_set_addr_str to
+ add spaces to set. Bugfix: word_cs, cword_cs wrongly initialized.
+ (regex_init): Removed reference to regex_space_chars.
+
+2012-04-20 Kaz Kylheku <kaz@kylheku.com>
+
* parser.y (regtoken): New nonterminal symbol.
(regterm): REGTOKEN production factored out to regtoken.
(regclass): Reverted prior commmit's changes.
diff --git a/regex.c b/regex.c
index 77989a98..52a42b14 100644
--- a/regex.c
+++ b/regex.c
@@ -209,7 +209,11 @@ union regex_machine {
int opt_derivative_regex = 0;
-static val regex_space_chars;
+wchar_t spaces[] = {
+ 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x0020, 0x00a0, 0x1680, 0x180e,
+ 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008,
+ 0x2009, 0x200a, 0x2028, 0x2029, 0x205f, 0x3000, 0
+};
static int L0_full(cset_L0_t *L0)
{
@@ -574,6 +578,12 @@ static void char_set_add_range(char_set_t *set, wchar_t ch0, wchar_t ch1)
}
}
+static void char_set_add_str(char_set_t *set, wchar_t *str)
+{
+ while (*str != 0)
+ char_set_add(set, *str++);
+}
+
static int char_set_contains(char_set_t *set, wchar_t ch)
{
int result = 0;
@@ -688,9 +698,7 @@ static char_set_t *char_set_compile(val args, val comp)
} else if (typeof(item) == chr_s) {
char_set_add(set, c_chr(item));
} else if (item == space_k) {
- val iter;
- for (iter = regex_space_chars; iter; iter = cdr(iter))
- char_set_add(set, c_chr(car(iter)));
+ char_set_add_str(set, spaces);
} else if (item == digit_k) {
char_set_add_range(set, '0', '9');
} else if (item == word_char_k) {
@@ -709,19 +717,11 @@ static char_set_t *char_set_compile(val args, val comp)
}
}
-wchar_t spaces[] = {
- 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x0020, 0x00a0, 0x1680, 0x180e,
- 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008,
- 0x2009, 0x200a, 0x2028, 0x2029, 0x205f, 0x3000, 0
-};
-
static char_set_t *space_cs, *digit_cs, *word_cs;
static char_set_t *cspace_cs, *cdigit_cs, *cword_cs;
static void init_special_char_sets(void)
{
- int i;
-
space_cs = char_set_create(CHSET_LARGE, 0, 1);
cspace_cs = char_set_create(CHSET_LARGE, 0, 1);
digit_cs = char_set_create(CHSET_SMALL, 0, 1);
@@ -733,20 +733,16 @@ static void init_special_char_sets(void)
char_set_compl(cdigit_cs);
char_set_compl(cword_cs);
- for (i = 0; spaces[i] != 0; i++) {
- wchar_t sp = spaces[i];
- char_set_add(space_cs, sp);
- char_set_add(cspace_cs, sp);
- push(chr(sp), &regex_space_chars);
- }
+ char_set_add_str(space_cs, spaces);
+ char_set_add_str(cspace_cs, spaces);
char_set_add_range(digit_cs, '0', '9');
char_set_add_range(cdigit_cs, '0', '9');
char_set_add_range(word_cs, 'A', 'Z');
char_set_add_range(cword_cs, 'A', 'Z');
- char_set_add_range(word_cs, 'a', 'a');
- char_set_add_range(cword_cs, 'a', 'a');
+ char_set_add_range(word_cs, 'a', 'z');
+ char_set_add_range(cword_cs, 'a', 'z');
char_set_add(word_cs, '_');
char_set_add(cword_cs, '_');
}
@@ -1892,7 +1888,5 @@ void regex_init(void)
cdigit_k = intern(lit("cdigit"), keyword_package);
cword_char_k = intern(lit("cword-char"), keyword_package);
- prot1(&regex_space_chars);
-
init_special_char_sets();
}