changelog for 0.9.1
[posh.git] / lex.h
blobc586c2aa93b0205c516c426e8955c6d203f36c50
1 /*
2 * Source input, lexer and parser
3 */
5 /* $Id: lex.h,v 1.4 1994/05/31 13:34:34 michael Exp $ */
7 #define IDENT 64
9 typedef struct source Source;
10 struct source {
11 const char *str; /* input pointer */
12 int type; /* input type */
13 const char *start; /* start of current buffer */
14 union {
15 char **strv; /* string [] */
16 struct shf *shf; /* shell file */
17 struct tbl *tblp; /* alias (SALIAS) */
18 char *freeme; /* also for SREREAD */
19 } u;
20 char ugbuf[2]; /* buffer for ungetsc() (SREREAD) and
21 * alias (SALIAS) */
22 int line; /* line number */
23 int errline; /* line the error occured on (0 if not set) */
24 const char *file; /* input file name */
25 int flags; /* SF_* */
26 Area *areap;
27 XString xs; /* input buffer */
28 Source *next; /* stacked source */
31 /* Source.type values */
32 #define SEOF 0 /* input EOF */
33 #define SFILE 1 /* file input */
34 #define SSTDIN 2 /* read stdin */
35 #define SSTRING 3 /* string */
36 #define SWSTR 4 /* string without \n */
37 #define SWORDS 5 /* string[] */
38 #define SWORDSEP 6 /* string[] seperator */
39 #define SALIAS 7 /* alias expansion */
40 #define SREREAD 8 /* read ahead to be re-scanned */
42 /* Source.flags values */
43 #define SF_ECHO BIT(0) /* echo input to shlout */
44 #define SF_ALIAS BIT(1) /* faking space at end of alias */
45 #define SF_ALIASEND BIT(2) /* faking space at end of alias */
46 #define SF_TTY BIT(3) /* type == SSTDIN & it is a tty */
47 #define SF_FIRST BIT(4) /* initial state (to ignore UTF-8 BOM) */
49 typedef union {
50 int i;
51 char *cp;
52 char **wp;
53 struct op *o;
54 struct ioword *iop;
55 } YYSTYPE;
57 /* If something is added here, add it to tokentab[] in syn.c as well */
58 #define LWORD 256
59 #define LOGAND 257 /* && */
60 #define LOGOR 258 /* || */
61 #define BREAK 259 /* ;; */
62 #define IF 260
63 #define THEN 261
64 #define ELSE 262
65 #define ELIF 263
66 #define FI 264
67 #define CASE 265
68 #define ESAC 266
69 #define FOR 267
70 #define SELECT 268
71 #define WHILE 269
72 #define UNTIL 270
73 #define DO 271
74 #define DONE 272
75 #define IN 273
76 #define FUNCTION 274
77 #define TIME 275
78 #define REDIR 276
79 #ifdef KSH
80 #define MDPAREN 277 /* (( )) */
81 #endif /* KSH */
82 #define BANG 278 /* ! */
83 #define DBRACKET 279 /* [[ .. ]] */
84 #define COPROC 280 /* |& */
85 #define YYERRCODE 300
87 /* flags to yylex */
88 #define CONTIN BIT(0) /* skip new lines to complete command */
89 #define ONEWORD BIT(1) /* single word for substitute() */
90 #define ALIAS BIT(2) /* recognize alias */
91 #define KEYWORD BIT(3) /* recognize keywords */
92 #define LETEXPR BIT(4) /* get expression inside (( )) */
93 #define VARASN BIT(5) /* check for var=word */
94 #define ARRAYVAR BIT(6) /* parse x[1 & 2] as one word */
95 #define ESACONLY BIT(7) /* only accept esac keyword */
96 #define CMDWORD BIT(8) /* parsing simple command (alias related) */
97 #define HEREDELIM BIT(9) /* parsing <<,<<- delimiter */
98 #define HEREDOC BIT(10) /* parsing heredoc */
100 #define HERES 10 /* max << in line */
102 EXTERN Source *source; /* yyparse/yylex source */
103 EXTERN YYSTYPE yylval; /* result from yylex */
104 EXTERN struct ioword *heres [HERES], **herep;
105 EXTERN char ident [IDENT+1];
107 #ifdef HISTORY
108 # define HISTORYSIZE 128 /* size of saved history */
110 EXTERN char **history; /* saved commands */
111 EXTERN char **histptr; /* last history item */
112 EXTERN int histsize; /* history size */
113 #endif /* HISTORY */