Browse Source

parser/lexical.c, #10/10, add some comments

pre-master-46
h_vogt 10 years ago
committed by rlar
parent
commit
c332b33d23
  1. 21
      src/frontend/parser/lexical.c

21
src/frontend/parser/lexical.c

@ -63,7 +63,7 @@ static int numeofs = 0;
/* Return a list of words, with backslash quoting and '' quoting done. /* 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 * 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, * 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 * and stripped off once all processing is done. We also have to deal with
@ -169,6 +169,7 @@ nloop:
for (;;) { for (;;) {
/* if string, read from string, else read from stdin */
c = cp_readchar(&string, cp_inp_cur); c = cp_readchar(&string, cp_inp_cur);
gotchar: gotchar:
@ -185,17 +186,21 @@ nloop:
if (c != EOF) /* Don't need to do this really. */ if (c != EOF) /* Don't need to do this really. */
c = strip(c); c = strip(c);
/* if '\' or '^', add following character to linebuf */
if ((c == '\\' && DIR_TERM != '\\') || (c == '\026') /* ^V */ ) { if ((c == '\\' && DIR_TERM != '\\') || (c == '\026') /* ^V */ ) {
c = quote(cp_readchar(&string, cp_inp_cur)); c = quote(cp_readchar(&string, cp_inp_cur));
push(&linebuf, strip(c)); push(&linebuf, strip(c));
} }
/* if reading from fcn backeval() for backquote subst. */
if ((c == '\n') && cp_bqflag) if ((c == '\n') && cp_bqflag)
c = ' '; c = ' ';
if ((c == EOF) && cp_bqflag) if ((c == EOF) && cp_bqflag)
c = '\n'; 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 ((c == cp_hash) && !cp_interactive && (linebuf.i == 1)) {
if (string) { if (string) {
wl_free(wlist); wl_free(wlist);
@ -208,19 +213,24 @@ nloop:
goto 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++; paren++;
else if ((c == ')') || (c == ']')) else if ((c == ')') || (c == ']'))
paren--; paren--;
/* What else has to be decided, depending on c ? */
switch (c) { switch (c) {
/* new word to wordlist, when space or tab follow */
case ' ': case ' ':
case '\t': case '\t':
if (buf.i > 0) if (buf.i > 0)
newword; newword;
break; break;
/* new word to wordlist, when \n follows */
case '\n': case '\n':
if (buf.i) if (buf.i)
newword; newword;
@ -228,6 +238,8 @@ nloop:
append(NULL); append(NULL);
goto done; goto done;
/* if ' read until next ' is hit, will form a new word,
but without the ' */
case '\'': case '\'':
while ((c = cp_readchar(&string, cp_inp_cur)) != '\'') while ((c = cp_readchar(&string, cp_inp_cur)) != '\'')
{ {
@ -239,6 +251,9 @@ nloop:
push(&linebuf, '\''); push(&linebuf, '\'');
break; 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 '"':
case '`': case '`':
d = c; d = c;
@ -263,6 +278,7 @@ nloop:
case '\004': case '\004':
case EOF: case EOF:
/* upon command completion, not used actually */
if (cp_interactive && !cp_nocc && !string) { if (cp_interactive && !cp_nocc && !string) {
if (linebuf.i == 0) { if (linebuf.i == 0) {
@ -306,6 +322,7 @@ nloop:
return NULL; return NULL;
case ESCAPE: case ESCAPE:
/* upon command completion, not used actually */
if (cp_interactive && !cp_nocc) { if (cp_interactive && !cp_nocc) {
push(&buf, '\0'); push(&buf, '\0');
push(&linebuf, '\0'); push(&linebuf, '\0');

Loading…
Cancel
Save