1 /* $OpenBSD: lex.h,v 1.21 2018/01/15 14:58:05 jca Exp $ */
4 * Source input, lexer and parser
7 /* $From: lex.h,v 1.4 1994/05/31 13:34:34 michael Exp $ */
11 typedef struct source Source
;
13 const char *str
; /* input pointer */
14 int type
; /* input type */
15 const char *start
; /* start of current buffer */
17 char **strv
; /* string [] */
18 struct shf
*shf
; /* shell file */
19 struct tbl
*tblp
; /* alias (SALIAS) */
20 char *freeme
; /* also for SREREAD */
22 char ugbuf
[2]; /* buffer for ungetsc() (SREREAD) and
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 */
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 */
59 /* If something is added here, add it to tokentab[] in syn.c as well */
61 #define LOGAND 257 /* && */
62 #define LOGOR 258 /* || */
63 #define BREAK 259 /* ;; */
81 #define MDPAREN 277 /* (( )) */
82 #define BANG 278 /* ! */
83 #define DBRACKET 279 /* [[ .. ]] */
84 #define COPROC 280 /* |& */
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 */
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);