1 /* $OpenBSD: lex.h,v 1.11 2006/05/29 18:22:24 otto 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 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 */ 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 51 /* 52 * states while lexing word 53 */ 54 #define SBASE 0 /* outside any lexical constructs */ 55 #define SWORD 1 /* implicit quoting for substitute() */ 56 #define SLETPAREN 2 /* inside (( )), implicit quoting */ 57 #define SSQUOTE 3 /* inside '' */ 58 #define SDQUOTE 4 /* inside "" */ 59 #define SBRACE 5 /* inside ${} */ 60 #define SCSPAREN 6 /* inside $() */ 61 #define SBQUOTE 7 /* inside `` */ 62 #define SASPAREN 8 /* inside $(( )) */ 63 #define SHEREDELIM 9 /* parsing <<,<<- delimiter */ 64 #define SHEREDQUOTE 10 /* parsing " in <<,<<- delimiter */ 65 #define SPATTERN 11 /* parsing *(...|...) pattern (*+?@!) */ 66 #define STBRACE 12 /* parsing ${..[#%]..} */ 67 68 typedef union { 69 int i; 70 char *cp; 71 char **wp; 72 struct op *o; 73 struct ioword *iop; 74 } YYSTYPE; 75 76 /* If something is added here, add it to tokentab[] in syn.c as well */ 77 #define LWORD 256 78 #define LOGAND 257 /* && */ 79 #define LOGOR 258 /* || */ 80 #define BREAK 259 /* ;; */ 81 #define IF 260 82 #define THEN 261 83 #define ELSE 262 84 #define ELIF 263 85 #define FI 264 86 #define CASE 265 87 #define ESAC 266 88 #define FOR 267 89 #define SELECT 268 90 #define WHILE 269 91 #define UNTIL 270 92 #define DO 271 93 #define DONE 272 94 #define IN 273 95 #define FUNCTION 274 96 #define TIME 275 97 #define REDIR 276 98 #define MDPAREN 277 /* (( )) */ 99 #define BANG 278 /* ! */ 100 #define DBRACKET 279 /* [[ .. ]] */ 101 #define COPROC 280 /* |& */ 102 #define YYERRCODE 300 103 104 /* flags to yylex */ 105 #define CONTIN BIT(0) /* skip new lines to complete command */ 106 #define ONEWORD BIT(1) /* single word for substitute() */ 107 #define ALIAS BIT(2) /* recognize alias */ 108 #define KEYWORD BIT(3) /* recognize keywords */ 109 #define LETEXPR BIT(4) /* get expression inside (( )) */ 110 #define VARASN BIT(5) /* check for var=word */ 111 #define ARRAYVAR BIT(6) /* parse x[1 & 2] as one word */ 112 #define ESACONLY BIT(7) /* only accept esac keyword */ 113 #define CMDWORD BIT(8) /* parsing simple command (alias related) */ 114 #define HEREDELIM BIT(9) /* parsing <<,<<- delimiter */ 115 #define HEREDOC BIT(10) /* parsing heredoc */ 116 117 #define HERES 10 /* max << in line */ 118 119 EXTERN Source *source; /* yyparse/yylex source */ 120 EXTERN YYSTYPE yylval; /* result from yylex */ 121 EXTERN struct ioword *heres [HERES], **herep; 122 EXTERN char ident [IDENT+1]; 123 124 #ifdef HISTORY 125 # define HISTORYSIZE 500 /* size of saved history */ 126 127 EXTERN char **history; /* saved commands */ 128 EXTERN char **histptr; /* last history item */ 129 EXTERN int histsize; /* history size */ 130 #endif /* HISTORY */ 131