Simplify and improve parser.

Clarify manpage.
This commit is contained in:
ache 1996-10-16 03:12:22 +00:00
parent 0b67136d65
commit f5b4e8c2ab
3 changed files with 38 additions and 244 deletions

View File

@ -124,11 +124,7 @@ representation, and can be only one character in length.
.Pp
Symbol names cannot be specified in
.Ar substitute
fields. Symbol names also cannot be combined with
any other representation, such as, <c>h, c<h>,
<c>\ex68, or <c><h>. Symbol names can be used with
primary and secondary ordering as in the following
example.
fields.
.Pp
The
.Ar charmap
@ -153,14 +149,15 @@ statement is optional.
.Ar order order_list
.Pp
.Ar order_list
is a list of symbols, separated by semi colons, that defines the collating sequence. The
is a list of symbols, separated by semi colons, that defines the
collating sequence. The
special symbol
.Ar ...
specifies, in a short-hand
form, symbols that are sequential in machine code
order.
.Pp
A symbol can be up to two characters in length and
An order list element
can be represented in any one of the following
ways:
.Bl -bullet
@ -208,18 +205,33 @@ Symbols
.Ar \er ,
.Ar \ev
are permitted in its usual C-language meaning
.It
The symbol range (for example,
.Ar a;...;z )
.It
Comma-separated symbols, ranges and chains enclosed in parenthesis (for example
.Ar \&(
.Ar sym1 ,
.Ar sym2 ,
.Ar ...
.Ar \&) )
are assigned the
same primary ordering but different secondary
ordering.
.It
Comma-separated symbols, ranges and chains enclosed in curly brackets (for example
.Ar \&{
.Ar sym1 ,
.Ar sym2 ,
.Ar ...
.Ar \&} )
are assigned the same primary ordering only.
.El
.Pp
The backslash character
.Ar \e
is used for continuation. In this case, no characters are permitted
after the backslash character. And as a quotation mark.
.Pp
Symbols enclosed in parentheses are assigned the
same primary ordering but different secondary
ordering. Symbols enclosed in curly brackets are
assigned only the same primary ordering
and different secondary ordering.
after the backslash character.
.Sh EXIT STATUS
.Ar colldef
exits with the following values:

View File

@ -61,7 +61,6 @@ char *out_file = "LC_COLLATE";
}
%token SUBSTITUTE WITH ORDER RANGE
%token <str> STRING
%token <str> NAME
%token <str> CHAIN
%token <str> DEFN
%token <ch> CHAR
@ -116,17 +115,6 @@ item : CHAR { __collate_char_pri_table[$1].prim = prim_pri++; }
yyerror("__collate_chain_pri_table overflow");
strcpy(__collate_chain_pri_table[chain_index].str, $1);
__collate_chain_pri_table[chain_index++].prim = prim_pri++;
}
| NAME {
u_int i;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0)
goto findi;
yyerror("Name <%s> not defined", $1);
findi:
__collate_char_pri_table[i].prim = prim_pri++;
}
| CHAR RANGE CHAR {
u_int i;
@ -136,68 +124,6 @@ item : CHAR { __collate_char_pri_table[$1].prim = prim_pri++; }
for (i = $1; i <= $3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri++;
}
| NAME RANGE CHAR {
u_int i, c1;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0) {
c1 = i;
goto find1;
}
yyerror("Name <%s> not defined", $1);
find1:
if ($3 <= c1)
yyerror("Illegal range 0x%02x -- 0x%02x",
c1, $3);
for (i = c1; i <= $3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri++;
}
| CHAR RANGE NAME {
u_int i, c3;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $3) == 0) {
c3 = i;
goto find3;
}
yyerror("Name <%s> not defined", $3);
find3:
if (c3 <= $1)
yyerror("Illegal range 0x%02x -- 0x%02x",
$1, c3);
for (i = $1; i <= c3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri++;
}
| NAME RANGE NAME {
u_int i, c1, c3;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0) {
c1 = i;
goto find21;
}
yyerror("Name <%s> not defined", $1);
find21:
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $3) == 0) {
c3 = i;
goto find23;
}
yyerror("Name <%s> not defined", $3);
find23:
if (c3 <= c1)
yyerror("Illegal range 0x%02x -- 0x%02x",
c1, c3);
for (i = c1; i <= c3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri++;
}
| '{' prim_order_list '}' {
prim_pri++;
@ -225,79 +151,6 @@ prim_sub_item : CHAR {
for (i = $1; i <= $3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri;
}
| NAME RANGE CHAR {
u_int i, c1;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0) {
c1 = i;
goto findpsi1;
}
yyerror("Name <%s> not defined", $1);
findpsi1:
if ($3 <= c1)
yyerror("Illegal range 0x%02x -- 0x%02x",
c1, $3);
for (i = c1; i <= $3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri;
}
| CHAR RANGE NAME {
u_int i, c3;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $3) == 0) {
c3 = i;
goto findpsi3;
}
yyerror("Name <%s> not defined", $3);
findpsi3:
if (c3 <= $1)
yyerror("Illegal range 0x%02x -- 0x%02x",
$1, c3);
for (i = $1; i <= c3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri;
}
| NAME RANGE NAME {
u_int i, c1, c3;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0) {
c1 = i;
goto findpsi21;
}
yyerror("Name <%s> not defined", $1);
findpsi21:
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $3) == 0) {
c3 = i;
goto findpsi23;
}
yyerror("Name <%s> not defined", $3);
findpsi23:
if (c3 <= c1)
yyerror("Illegal range 0x%02x -- 0x%02x",
c1, c3);
for (i = c1; i <= c3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri;
}
| NAME {
u_int i;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0)
goto findpsi;
yyerror("Name <%s> not defined", $1);
findpsi:
__collate_char_pri_table[i].prim = prim_pri;
}
| CHAIN {
if (chain_index >= TABLE_SIZE - 1)
@ -321,86 +174,6 @@ sec_sub_item : CHAR {
__collate_char_pri_table[(u_char)i].prim = prim_pri;
__collate_char_pri_table[(u_char)i].sec = sec_pri++;
}
}
| NAME RANGE CHAR {
u_int i, c1;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0) {
c1 = i;
goto findssi1;
}
yyerror("Name <%s> not defined", $1);
findssi1:
if ($3 <= c1)
yyerror("Illegal range 0x%02x -- 0x%02x",
c1, $3);
for (i = c1; i <= $3; i++) {
__collate_char_pri_table[(u_char)i].prim = prim_pri;
__collate_char_pri_table[(u_char)i].sec = sec_pri++;
}
}
| CHAR RANGE NAME {
u_int i, c3;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $3) == 0) {
c3 = i;
goto findssi3;
}
yyerror("Name <%s> not defined", $3);
findssi3:
if (c3 <= $1)
yyerror("Illegal range 0x%02x -- 0x%02x",
$1, c3);
for (i = $1; i <= c3; i++) {
__collate_char_pri_table[(u_char)i].prim = prim_pri;
__collate_char_pri_table[(u_char)i].sec = sec_pri++;
}
}
| NAME RANGE NAME {
u_int i, c1, c3;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0) {
c1 = i;
goto findssi21;
}
yyerror("Name <%s> not defined", $1);
findssi21:
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $3) == 0) {
c3 = i;
goto findssi23;
}
yyerror("Name <%s> not defined", $3);
findssi23:
if (c3 <= c1)
yyerror("Illegal range 0x%02x -- 0x%02x",
c1, c3);
for (i = c1; i <= c3; i++) {
__collate_char_pri_table[(u_char)i].prim = prim_pri;
__collate_char_pri_table[(u_char)i].sec = sec_pri++;
}
}
| NAME {
u_int i;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0)
goto findssi;
yyerror("Name <%s> not defined", $1);
findssi:
__collate_char_pri_table[i].prim = prim_pri;
__collate_char_pri_table[i].sec = sec_pri++;
}
| CHAIN {
if (chain_index >= TABLE_SIZE - 1)

View File

@ -41,6 +41,7 @@ int line_no = 1, save_no;
u_char buf[STR_LEN], *ptr;
FILE *map_fp;
extern char map_name[];
extern u_char charmap_table[UCHAR_MAX + 1][STR_LEN];
YY_BUFFER_STATE main_buf, map_buf;
#ifdef FLEX_DEBUG
YYSTYPE yylval;
@ -137,13 +138,21 @@ YYSTYPE yylval;
*ptr++ = '"';
}
<name>\> {
u_int i;
if (ptr == buf)
errx(EX_UNAVAILABLE, "name expected near line %u",
errx(EX_UNAVAILABLE, "non-empty name expected near line %u",
line_no);
*ptr = '\0';
strcpy(yylval.str, buf);
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], buf) == 0)
goto findit;
errx(EX_UNAVAILABLE, "name <%s> not 'charmap'-defined near line %u",
buf, line_no);
findit:
yylval.ch = i;
BEGIN(INITIAL);
return NAME;
return CHAR;
}
<string>\" {
*ptr = '\0';