xref: /titanic_52/usr/src/contrib/ast/src/cmd/ksh93/include/lexstates.h (revision 906afcb89d0412cc073b95c2d701a804a8cdb62c)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1982-2011 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                  David Korn <dgk@research.att.com>                   *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 #ifndef S_BREAK
22 #define S_BREAK	1	/* end of token */
23 #define S_EOF	2	/* end of buffer */
24 #define S_NL	3	/* new-line when not a token */
25 #define S_RES	4	/* first character of reserved word */
26 #define S_NAME	5	/* other identifier characters */
27 #define S_REG	6	/* non-special characters */
28 #define S_TILDE	7	/* first char is tilde */
29 #define S_PUSH	8
30 #define S_POP	9
31 #define S_BRACT	10
32 #define S_LIT	11	/* literal quote character */
33 #define S_NLTOK	12	/* new-line token */
34 #define S_OP	13	/* operator character */
35 #define S_PAT	14	/* pattern characters * and ? */
36 #define S_EPAT	15	/* pattern char when followed by ( */
37 #define S_EQ	16	/* assignment character */
38 #define S_COM	17	/* comment character */
39 #define S_MOD1	18	/* ${...} modifier character - old quoting */
40 #define S_MOD2	19	/* ${...} modifier character - new quoting */
41 #define S_ERR	20	/* invalid character in ${...} */
42 #define S_SPC1	21	/* special prefix characters after $ */
43 #define S_SPC2	22	/* special characters after $ */
44 #define S_DIG	23	/* digit character after $*/
45 #define S_ALP	24	/* alpahbetic character after $ */
46 #define S_LBRA	25	/* left brace after $ */
47 #define S_RBRA	26	/* right brace after $ */
48 #define S_PAR	27	/* set for $( */
49 #define S_ENDCH	28	/* macro expansion terminator */
50 #define S_SLASH	29	/* / character terminates ~ expansion  */
51 #define S_COLON	30	/* for character : */
52 #define S_LABEL	31	/* for goto label */
53 #define S_EDOL	32	/* ends $identifier */
54 #define S_BRACE	33	/* left brace */
55 #define S_DOT	34	/* . char */
56 #define S_META	35	/* | & ; < > inside ${...} reserved for future use */
57 #define S_SPACE	S_BREAK	/* IFS space characters */
58 #define S_DELIM	S_RES	/* IFS delimter characters */
59 #define S_MBYTE S_NAME	/* IFS first byte of multi-byte char */
60 #define S_BLNK	36	/* space or tab */
61 /* The following must be the highest numbered states */
62 #define S_QUOTE	37	/* double quote character */
63 #define S_GRAVE	38	/* old comsub character */
64 #define S_ESC	39	/* escape character */
65 #define S_DOL	40	/* $ subsitution character */
66 #define S_ESC2	41	/* escape character inside '...' */
67 
68 /* These are the lexical state table names */
69 #define ST_BEGIN	0
70 #define ST_NAME		1
71 #define ST_NORM		2
72 #define ST_LIT		3
73 #define ST_QUOTE	4
74 #define ST_NESTED	5
75 #define ST_DOL		6
76 #define ST_BRACE	7
77 #define ST_DOLNAME	8
78 #define ST_MACRO	9
79 #define ST_QNEST	10
80 #define ST_NONE		11
81 
82 #include "FEATURE/locale"
83 
84 #if _hdr_wchar
85 #   include <wchar.h>
86 #   if _hdr_wctype
87 #       include <wctype.h>
88 #       undef  isalpha
89 #       define isalpha(x)      iswalpha(x)
90 #       if defined(iswblank) || _lib_iswblank
91 #           undef  isblank
92 #           define isblank(x)      iswblank(x)
93 #       else
94 #           if _lib_wctype && _lib_iswctype
95 #               define _lib_iswblank	-1
96 #               undef  isblank
97 #	        define isblank(x)	local_iswblank(x)
98 	        extern int		local_iswblank(wchar_t);
99 #           endif
100 #       endif
101 #   endif
102 #endif
103 #ifndef isblank
104 #   define isblank(x)      ((x)==' '||(x)=='\t')
105 #endif
106 
107 #undef LEN
108 #if SHOPT_MULTIBYTE
109 #   define LEN		_Fcin.fclen
110 #   define isaname(c)	((c)>0x7f?isalpha(c): sh_lexstates[ST_NAME][(c)]==0)
111 #   define isaletter(c)	((c)>0x7f?isalpha(c): sh_lexstates[ST_DOL][(c)]==S_ALP && (c)!='.')
112 #else
113 #   undef mbwide
114 #   define mbwide()	(0)
115 #   define LEN		1
116 #   define isaname(c)	(sh_lexstates[ST_NAME][c]==0)
117 #   define isaletter(c)	(sh_lexstates[ST_DOL][c]==S_ALP && (c)!='.')
118 #endif
119 #define STATE(s,c)	(s[mbwide()?((c=fcmbget(&LEN)),LEN>1?'a':c):(c=fcget())])
120 #define isadigit(c)	(sh_lexstates[ST_DOL][c]==S_DIG)
121 #define isastchar(c)	((c)=='@' || (c)=='*')
122 #define isexp(c)	(sh_lexstates[ST_MACRO][c]==S_PAT||(c)=='$'||(c)=='`')
123 #define ismeta(c)	(sh_lexstates[ST_NAME][c]==S_BREAK)
124 
125 extern char *sh_lexstates[ST_NONE];
126 extern const char *sh_lexrstates[ST_NONE];
127 extern const char e_lexversion[];
128 extern const char e_lexspace[];
129 extern const char e_lexslash[];
130 extern const char e_lexlabignore[];
131 extern const char e_lexlabunknown[];
132 extern const char e_lexsyntax1[];
133 extern const char e_lexsyntax2[];
134 extern const char e_lexsyntax3[];
135 extern const char e_lexsyntax4[];
136 extern const char e_lexsyntax5[];
137 extern const char e_lexwarnvar[];
138 extern const char e_lexobsolete1[];
139 extern const char e_lexobsolete2[];
140 extern const char e_lexobsolete3[];
141 extern const char e_lexobsolete4[];
142 extern const char e_lexobsolete5[];
143 extern const char e_lexobsolete6[];
144 extern const char e_lexnonstandard[];
145 extern const char e_lexusebrace[];
146 extern const char e_lexusequote[];
147 extern const char e_lexescape[];
148 extern const char e_lexquote[];
149 extern const char e_lexnested[];
150 extern const char e_lexbadchar[];
151 extern const char e_lexlongquote[];
152 extern const char e_lexfuture[];
153 extern const char e_lexzerobyte[];
154 extern const char e_lexemptyfor[];
155 extern const char e_lextypeset[];
156 extern const char e_lexcharclass[];
157 #endif
158