* syntax.c: Give names to numeric tokens.
Этот коммит содержится в:
родитель
1b8b5509f5
Коммит
fce42c9316
@ -1,5 +1,7 @@
|
|||||||
2003-09-22 Pavel Roskin <proski@gnu.org>
|
2003-09-22 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
|
* syntax.c: Give names to numeric tokens.
|
||||||
|
|
||||||
* syntax.c (compare_word_to_right): Add checks that we don't go
|
* syntax.c (compare_word_to_right): Add checks that we don't go
|
||||||
beyond text length for certain invalid rules.
|
beyond text length for certain invalid rules.
|
||||||
Reported by Juan C. Olivares <juancri@TAGnet.org>
|
Reported by Juan C. Olivares <juancri@TAGnet.org>
|
||||||
|
@ -48,6 +48,11 @@
|
|||||||
#define RULE_ON_LEFT_BORDER 1
|
#define RULE_ON_LEFT_BORDER 1
|
||||||
#define RULE_ON_RIGHT_BORDER 2
|
#define RULE_ON_RIGHT_BORDER 2
|
||||||
|
|
||||||
|
#define SYNTAX_TOKEN_STAR '\001'
|
||||||
|
#define SYNTAX_TOKEN_PLUS '\002'
|
||||||
|
#define SYNTAX_TOKEN_BRACKET '\003'
|
||||||
|
#define SYNTAX_TOKEN_BRACE '\004'
|
||||||
|
|
||||||
struct key_word {
|
struct key_word {
|
||||||
char *keyword;
|
char *keyword;
|
||||||
unsigned char first;
|
unsigned char first;
|
||||||
@ -155,7 +160,7 @@ compare_word_to_right (WEdit *edit, long i, const char *text,
|
|||||||
return -1;
|
return -1;
|
||||||
for (p = (unsigned char *) text, q = p + strlen ((char *) p); p < q; p++, i++) {
|
for (p = (unsigned char *) text, q = p + strlen ((char *) p); p < q; p++, i++) {
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case '\001':
|
case SYNTAX_TOKEN_STAR:
|
||||||
if (++p >= q)
|
if (++p >= q)
|
||||||
return -1;
|
return -1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -171,7 +176,7 @@ compare_word_to_right (WEdit *edit, long i, const char *text,
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\002':
|
case SYNTAX_TOKEN_PLUS:
|
||||||
if (++p >= q)
|
if (++p >= q)
|
||||||
return -1;
|
return -1;
|
||||||
j = 0;
|
j = 0;
|
||||||
@ -208,14 +213,14 @@ compare_word_to_right (WEdit *edit, long i, const char *text,
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\003':
|
case SYNTAX_TOKEN_BRACKET:
|
||||||
if (++p >= q)
|
if (++p >= q)
|
||||||
return -1;
|
return -1;
|
||||||
c = -1;
|
c = -1;
|
||||||
for (;; i++) {
|
for (;; i++) {
|
||||||
d = c;
|
d = c;
|
||||||
c = edit_get_byte (edit, i);
|
c = edit_get_byte (edit, i);
|
||||||
for (j = 0; p[j] != '\003'; j++)
|
for (j = 0; p[j] != SYNTAX_TOKEN_BRACKET; j++)
|
||||||
if (c == p[j])
|
if (c == p[j])
|
||||||
goto found_char2;
|
goto found_char2;
|
||||||
break;
|
break;
|
||||||
@ -223,23 +228,23 @@ compare_word_to_right (WEdit *edit, long i, const char *text,
|
|||||||
j = c; /* dummy command */
|
j = c; /* dummy command */
|
||||||
}
|
}
|
||||||
i--;
|
i--;
|
||||||
while (*p != '\003' && p < q)
|
while (*p != SYNTAX_TOKEN_BRACKET && p < q)
|
||||||
p++;
|
p++;
|
||||||
if (p >= q)
|
if (p >= q)
|
||||||
return -1;
|
return -1;
|
||||||
if (p[1] == d)
|
if (p[1] == d)
|
||||||
i--;
|
i--;
|
||||||
break;
|
break;
|
||||||
case '\004':
|
case SYNTAX_TOKEN_BRACE:
|
||||||
if (++p >= q)
|
if (++p >= q)
|
||||||
return -1;
|
return -1;
|
||||||
c = edit_get_byte (edit, i);
|
c = edit_get_byte (edit, i);
|
||||||
for (; *p != '\004'; p++)
|
for (; *p != SYNTAX_TOKEN_BRACE; p++)
|
||||||
if (c == *p)
|
if (c == *p)
|
||||||
goto found_char3;
|
goto found_char3;
|
||||||
return -1;
|
return -1;
|
||||||
found_char3:
|
found_char3:
|
||||||
for (; *p != '\004' && p < q; p++);
|
for (; *p != SYNTAX_TOKEN_BRACE && p < q; p++);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (*p != edit_get_byte (edit, i))
|
if (*p != edit_get_byte (edit, i))
|
||||||
@ -529,11 +534,11 @@ static char *convert (char *s)
|
|||||||
break;
|
break;
|
||||||
case '[':
|
case '[':
|
||||||
case ']':
|
case ']':
|
||||||
*p = '\003';
|
*p = SYNTAX_TOKEN_BRACKET;
|
||||||
break;
|
break;
|
||||||
case '{':
|
case '{':
|
||||||
case '}':
|
case '}':
|
||||||
*p = '\004';
|
*p = SYNTAX_TOKEN_BRACE;
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
*p = *s;
|
*p = *s;
|
||||||
@ -544,10 +549,10 @@ static char *convert (char *s)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '*':
|
case '*':
|
||||||
*p = '\001';
|
*p = SYNTAX_TOKEN_STAR;
|
||||||
break;
|
break;
|
||||||
case '+':
|
case '+':
|
||||||
*p = '\002';
|
*p = SYNTAX_TOKEN_PLUS;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
*p = *s;
|
*p = *s;
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user