1 /* $NetBSD: lex.h,v 1.7 2005/09/11 22:16:00 christos Exp $ */
4 * Source input, lexer and parser
7 /* $Id: lex.h,v 1.7 2005/09/11 22:16:00 christos 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 errline
; /* line the error occurred on (0 if not set) */
26 const char *file
; /* input file name */
29 XString xs
; /* input buffer */
30 Source
*next
; /* stacked source */
33 /* Source.type values */
34 #define SEOF 0 /* input EOF */
35 #define SFILE 1 /* file input */
36 #define SSTDIN 2 /* read stdin */
37 #define SSTRING 3 /* string */
38 #define SWSTR 4 /* string without \n */
39 #define SWORDS 5 /* string[] */
40 #define SWORDSEP 6 /* string[] separator */
41 #define SALIAS 7 /* alias expansion */
42 #define SREREAD 8 /* read ahead to be re-scanned */
44 /* Source.flags values */
45 #define SF_ECHO BIT(0) /* echo input to shlout */
46 #define SF_ALIAS BIT(1) /* faking space at end of alias */
47 #define SF_ALIASEND BIT(2) /* faking space at end of alias */
48 #define SF_TTY BIT(3) /* type == SSTDIN & it is a tty */
51 * states while lexing word
53 #define SBASE 0 /* outside any lexical constructs */
54 #define SWORD 1 /* implicit quoting for substitute() */
56 #define SLETPAREN 2 /* inside (( )), implicit quoting */
58 #define SSQUOTE 3 /* inside '' */
59 #define SDQUOTE 4 /* inside "" */
60 #define SBRACE 5 /* inside ${} */
61 #define SCSPAREN 6 /* inside $() */
62 #define SBQUOTE 7 /* inside `` */
63 #define SASPAREN 8 /* inside $(( )) */
64 #define SHEREDELIM 9 /* parsing <<,<<- delimiter */
65 #define SHEREDQUOTE 10 /* parsing " in <<,<<- delimiter */
66 #define SPATTERN 11 /* parsing *(...|...) pattern (*+?@!) */
67 #define STBRACE 12 /* parsing ${..[#%]..} */
77 /* If something is added here, add it to tokentab[] in syn.c as well */
79 #define LOGAND 257 /* && */
80 #define LOGOR 258 /* || */
81 #define BREAK 259 /* ;; */
100 #define MDPAREN 277 /* (( )) */
102 #define BANG 278 /* ! */
103 #define DBRACKET 279 /* [[ .. ]] */
104 #define COPROC 280 /* |& */
105 #define YYERRCODE 300
108 #define CONTIN BIT(0) /* skip new lines to complete command */
109 #define ONEWORD BIT(1) /* single word for substitute() */
110 #define ALIAS BIT(2) /* recognize alias */
111 #define KEYWORD BIT(3) /* recognize keywords */
112 #define LETEXPR BIT(4) /* get expression inside (( )) */
113 #define VARASN BIT(5) /* check for var=word */
114 #define ARRAYVAR BIT(6) /* parse x[1 & 2] as one word */
115 #define ESACONLY BIT(7) /* only accept esac keyword */
116 #define CMDWORD BIT(8) /* parsing simple command (alias related) */
117 #define HEREDELIM BIT(9) /* parsing <<,<<- delimiter */
118 #define HEREDOC BIT(10) /* parsing heredoc */
120 #define HERES 10 /* max << in line */
122 EXTERN Source
*source
; /* yyparse/yylex source */
123 EXTERN YYSTYPE yylval
; /* result from yylex */
124 EXTERN
struct ioword
*heres
[HERES
], **herep
;
125 EXTERN
char ident
[IDENT
+1];
128 # define HISTORYSIZE 128 /* size of saved history */
130 EXTERN
char **histlist
; /* saved commands */
131 EXTERN
char **histptr
; /* last history item */
132 EXTERN
int histsize
; /* history size */