parser/lexical.c, #10/10, add some comments
This commit is contained in:
parent
a551f87652
commit
c332b33d23
|
|
@ -63,7 +63,7 @@ static int numeofs = 0;
|
|||
|
||||
|
||||
/* Return a list of words, with backslash quoting and '' quoting done.
|
||||
* Strings en(void) closed in "" or `` are made single words and returned,
|
||||
* Strings enclosed in "" or `` are made single words and returned,
|
||||
* but with the "" or `` still present. For the \ and '' cases, the
|
||||
* 8th bit is turned on (as in csh) to prevent them from being recognized,
|
||||
* and stripped off once all processing is done. We also have to deal with
|
||||
|
|
@ -169,6 +169,7 @@ nloop:
|
|||
|
||||
for (;;) {
|
||||
|
||||
/* if string, read from string, else read from stdin */
|
||||
c = cp_readchar(&string, cp_inp_cur);
|
||||
|
||||
gotchar:
|
||||
|
|
@ -185,17 +186,21 @@ nloop:
|
|||
if (c != EOF) /* Don't need to do this really. */
|
||||
c = strip(c);
|
||||
|
||||
/* if '\' or '^', add following character to linebuf */
|
||||
if ((c == '\\' && DIR_TERM != '\\') || (c == '\026') /* ^V */ ) {
|
||||
c = quote(cp_readchar(&string, cp_inp_cur));
|
||||
push(&linebuf, strip(c));
|
||||
}
|
||||
|
||||
/* if reading from fcn backeval() for backquote subst. */
|
||||
if ((c == '\n') && cp_bqflag)
|
||||
c = ' ';
|
||||
|
||||
if ((c == EOF) && cp_bqflag)
|
||||
c = '\n';
|
||||
|
||||
/* '#' as the first character in a line,
|
||||
starts a comment line, drop it */
|
||||
if ((c == cp_hash) && !cp_interactive && (linebuf.i == 1)) {
|
||||
if (string) {
|
||||
wl_free(wlist);
|
||||
|
|
@ -208,19 +213,24 @@ nloop:
|
|||
goto nloop;
|
||||
}
|
||||
|
||||
if ((c == '(') || (c == '[')) /* MW. Nedded by parse() */
|
||||
/* check if we are inside of parens during reading:
|
||||
if we are and ',' or ';' occur: no new line */
|
||||
if ((c == '(') || (c == '['))
|
||||
paren++;
|
||||
else if ((c == ')') || (c == ']'))
|
||||
paren--;
|
||||
|
||||
/* What else has to be decided, depending on c ? */
|
||||
switch (c) {
|
||||
|
||||
/* new word to wordlist, when space or tab follow */
|
||||
case ' ':
|
||||
case '\t':
|
||||
if (buf.i > 0)
|
||||
newword;
|
||||
break;
|
||||
|
||||
/* new word to wordlist, when \n follows */
|
||||
case '\n':
|
||||
if (buf.i)
|
||||
newword;
|
||||
|
|
@ -228,6 +238,8 @@ nloop:
|
|||
append(NULL);
|
||||
goto done;
|
||||
|
||||
/* if ' read until next ' is hit, will form a new word,
|
||||
but without the ' */
|
||||
case '\'':
|
||||
while ((c = cp_readchar(&string, cp_inp_cur)) != '\'')
|
||||
{
|
||||
|
|
@ -239,6 +251,9 @@ nloop:
|
|||
push(&linebuf, '\'');
|
||||
break;
|
||||
|
||||
/* if " or `, read until next " or ` is hit, will form a new word,
|
||||
including the quotes.
|
||||
In case of \, the next character gets the eights bit set. */
|
||||
case '"':
|
||||
case '`':
|
||||
d = c;
|
||||
|
|
@ -263,6 +278,7 @@ nloop:
|
|||
|
||||
case '\004':
|
||||
case EOF:
|
||||
/* upon command completion, not used actually */
|
||||
if (cp_interactive && !cp_nocc && !string) {
|
||||
|
||||
if (linebuf.i == 0) {
|
||||
|
|
@ -306,6 +322,7 @@ nloop:
|
|||
return NULL;
|
||||
|
||||
case ESCAPE:
|
||||
/* upon command completion, not used actually */
|
||||
if (cp_interactive && !cp_nocc) {
|
||||
push(&buf, '\0');
|
||||
push(&linebuf, '\0');
|
||||
|
|
|
|||
Loading…
Reference in New Issue