Merge commit 'db1c88f6dab43484b6c33636600ac4596ff4c354'
[unleashed.git] / bin / ksh / lex.h
blobbf9072cdf89439def25eac45ad1f8edeea352673
1 /* $OpenBSD: lex.h,v 1.21 2018/01/15 14:58:05 jca Exp $ */
3 /*
4 * Source input, lexer and parser
5 */
7 /* $From: lex.h,v 1.4 1994/05/31 13:34:34 michael Exp $ */
9 #define IDENT 64
11 typedef struct source Source;
12 struct source {
13 const char *str; /* input pointer */
14 int type; /* input type */
15 const char *start; /* start of current buffer */
16 union {
17 char **strv; /* string [] */
18 struct shf *shf; /* shell file */
19 struct tbl *tblp; /* alias (SALIAS) */
20 char *freeme; /* also for SREREAD */
21 } u;
22 char ugbuf[2]; /* buffer for ungetsc() (SREREAD) and
23 * alias (SALIAS) */
24 int line; /* line number */
25 int cmd_offset; /* line number - command number */
26 int errline; /* line the error occurred on (0 if not set) */
27 const char *file; /* input file name */
28 int flags; /* SF_* */
29 Area *areap;
30 XString xs; /* input buffer */
31 Source *next; /* stacked source */
34 /* Source.type values */
35 #define SEOF 0 /* input EOF */
36 #define SFILE 1 /* file input */
37 #define SSTDIN 2 /* read stdin */
38 #define SSTRING 3 /* string */
39 #define SWSTR 4 /* string without \n */
40 #define SWORDS 5 /* string[] */
41 #define SWORDSEP 6 /* string[] separator */
42 #define SALIAS 7 /* alias expansion */
43 #define SREREAD 8 /* read ahead to be re-scanned */
45 /* Source.flags values */
46 #define SF_ECHO BIT(0) /* echo input to shlout */
47 #define SF_ALIAS BIT(1) /* faking space at end of alias */
48 #define SF_ALIASEND BIT(2) /* faking space at end of alias */
49 #define SF_TTY BIT(3) /* type == SSTDIN & it is a tty */
51 typedef union {
52 int i;
53 char *cp;
54 char **wp;
55 struct op *o;
56 struct ioword *iop;
57 } YYSTYPE;
59 /* If something is added here, add it to tokentab[] in syn.c as well */
60 #define LWORD 256
61 #define LOGAND 257 /* && */
62 #define LOGOR 258 /* || */
63 #define BREAK 259 /* ;; */
64 #define IF 260
65 #define THEN 261
66 #define ELSE 262
67 #define ELIF 263
68 #define FI 264
69 #define CASE 265
70 #define ESAC 266
71 #define FOR 267
72 #define SELECT 268
73 #define WHILE 269
74 #define UNTIL 270
75 #define DO 271
76 #define DONE 272
77 #define IN 273
78 #define FUNCTION 274
79 #define TIME 275
80 #define REDIR 276
81 #define MDPAREN 277 /* (( )) */
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 */
99 #define UNESCAPE BIT(11) /* remove backslashes */
101 #define HERES 10 /* max << in line */
103 extern Source *source; /* yyparse/yylex source */
104 extern YYSTYPE yylval; /* result from yylex */
105 extern struct ioword *heres[HERES], **herep;
106 extern char ident[IDENT+1];
108 #define HISTORYSIZE 500 /* size of saved history */
110 extern char **history; /* saved commands */
111 extern char **histptr; /* last history item */
112 extern uint32_t histsize; /* history size */
114 int yylex(int);
115 void yyerror(const char *, ...)
116 __attribute__((__noreturn__, __format__ (printf, 1, 2)));
117 Source * pushs(int, Area *);
118 void set_prompt(int);
119 void pprompt(const char *, int);