2 * Source input, lexer and parser
9 typedef struct source Source
;
11 const char *str
; /* input pointer */
12 int type
; /* input type */
13 const char *start
; /* start of current buffer */
15 char **strv
; /* string [] */
16 struct shf
*shf
; /* shell file */
17 struct tbl
*tblp
; /* alias (SALIAS) */
18 char *freeme
; /* also for SREREAD */
20 char ugbuf
[2]; /* buffer for ungetsc() (SREREAD) and
22 int line
; /* line number */
23 int cmd_offset
; /* line number - command number */
24 int errline
; /* line the error occured on (0 if not set) */
25 const char *file
; /* input file name */
28 XString xs
; /* input buffer */
29 Source
*next
; /* stacked source */
32 /* Source.type values */
33 #define SEOF 0 /* input EOF */
34 #define SFILE 1 /* file input */
35 #define SSTDIN 2 /* read stdin */
36 #define SSTRING 3 /* string */
37 #define SWSTR 4 /* string without \n */
38 #define SWORDS 5 /* string[] */
39 #define SWORDSEP 6 /* string[] separator */
40 #define SALIAS 7 /* alias expansion */
41 #define SREREAD 8 /* read ahead to be re-scanned */
43 /* Source.flags values */
44 #define SF_ECHO BIT(0) /* echo input to shlout */
45 #define SF_ALIAS BIT(1) /* faking space at end of alias */
46 #define SF_ALIASEND BIT(2) /* faking space at end of alias */
47 #define SF_TTY BIT(3) /* type == SSTDIN & it is a tty */
50 * states while lexing word
52 #define SBASE 0 /* outside any lexical constructs */
53 #define SWORD 1 /* implicit quoting for substitute() */
54 #define SLETPAREN 2 /* inside (( )), implicit quoting */
55 #define SSQUOTE 3 /* inside '' */
56 #define SDQUOTE 4 /* inside "" */
57 #define SBRACE 5 /* inside ${} */
58 #define SCSPAREN 6 /* inside $() */
59 #define SBQUOTE 7 /* inside `` */
60 #define SASPAREN 8 /* inside $(( )) */
61 #define SHEREDELIM 9 /* parsing <<,<<- delimiter */
62 #define SHEREDQUOTE 10 /* parsing " in <<,<<- delimiter */
63 #define SPATTERN 11 /* parsing *(...|...) pattern (*+?@!) */
64 #define STBRACE 12 /* parsing ${..[#%]..} */
74 /* If something is added here, add it to tokentab[] in syn.c as well */
76 #define LOGAND 257 /* && */
77 #define LOGOR 258 /* || */
78 #define BREAK 259 /* ;; */
96 #define MDPAREN 277 /* (( )) */
97 #define BANG 278 /* ! */
98 #define DBRACKET 279 /* [[ .. ]] */
99 #define COPROC 280 /* |& */
100 #define YYERRCODE 300
103 #define CONTIN BIT(0) /* skip new lines to complete command */
104 #define ONEWORD BIT(1) /* single word for substitute() */
105 #define ALIAS BIT(2) /* recognize alias */
106 #define KEYWORD BIT(3) /* recognize keywords */
107 #define LETEXPR BIT(4) /* get expression inside (( )) */
108 #define VARASN BIT(5) /* check for var=word */
109 #define ARRAYVAR BIT(6) /* parse x[1 & 2] as one word */
110 #define ESACONLY BIT(7) /* only accept esac keyword */
111 #define CMDWORD BIT(8) /* parsing simple command (alias related) */
112 #define HEREDELIM BIT(9) /* parsing <<,<<- delimiter */
113 #define HEREDOC BIT(10) /* parsing heredoc */
115 #define HERES 10 /* max << in line */
117 EXTERN Source
*source
; /* yyparse/yylex source */
118 EXTERN YYSTYPE yylval
; /* result from yylex */
119 EXTERN
struct ioword
*heres
[HERES
], **herep
;
120 EXTERN
char ident
[IDENT
+1];
123 # define HISTORYSIZE 500 /* size of saved history */
125 EXTERN
char **history
; /* saved commands */
126 EXTERN
char **histptr
; /* last history item */
127 EXTERN
int histsize
; /* history size */