loksh-noxz

[fork] a Linux port of OpenBSD's ksh
git clone https://noxz.tech/git/loksh-noxz.git
Log | Files | README

lex.h
1/*	$OpenBSD: lex.h,v 1.21 2018/01/15 14:58:05 jca Exp $	*/
2
3/*
4 * Source input, lexer and parser
5 */
6
7/* $From: lex.h,v 1.4 1994/05/31 13:34:34 michael Exp $ */
8
9#define	IDENT	64
10
11typedef struct source Source;
12struct 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 */
32};
33
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 */
44
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 */
50
51typedef union {
52	int	i;
53	char   *cp;
54	char  **wp;
55	struct op *o;
56	struct ioword *iop;
57} YYSTYPE;
58
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
86
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 */
100
101#define	HERES	10		/* max << in line */
102
103extern Source  *source;		/* yyparse/yylex source */
104extern YYSTYPE	yylval;		/* result from yylex */
105extern struct ioword *heres[HERES], **herep;
106extern char	ident[IDENT+1];
107
108#define HISTORYSIZE	500	/* size of saved history */
109
110extern char   **history;	/* saved commands */
111extern char   **histptr;	/* last history item */
112extern uint32_t	histsize;	/* history size */
113
114int	yylex(int);
115void	yyerror(const char *, ...)
116	    __attribute__((__noreturn__, __format__ (printf, 1, 2)));
117Source * pushs(int, Area *);
118void	set_prompt(int);
119void	pprompt(const char *, int);