From: Herbert Xu <herbert@gondor.apana.org.au>
To: dash@vger.kernel.org
Subject: [PATCH 2/3] [PARSER] Simplify EOF/newline handling in list parser
Date: Wed, 05 Nov 2014 16:48:25 +0800 [thread overview]
Message-ID: <E1XlwGP-0005Xd-4f@gondolin.me.apana.org.au> (raw)
In-Reply-To: 20141105084749.GA21242@gondor.apana.org.au
This patch simplifies the EOF and new handling in the list parser.
In particular, it eliminates a case where we may leave here-documents
unfinished upon EOF.
It also removes special EOF/newline handling from parsecmd.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
ChangeLog | 1
src/parser.c | 60 +++++++++++++++++++++++++----------------------------------
2 files changed, 27 insertions(+), 34 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 70ccfed..8e0d276 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
2014-10-28 Herbert Xu <herbert@gondor.apana.org.au>
* Removed unnecessary pungetc on EOF from parser.
+ * Simplify EOF/newline handling in list parser.
2014-10-27 Herbert Xu <herbert@gondor.apana.org.au>
diff --git a/src/parser.c b/src/parser.c
index f0c919d..382ddf2 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -135,19 +135,13 @@ static inline int realeofmark(const char *eofmark)
union node *
parsecmd(int interact)
{
- int t;
-
tokpushback = 0;
+ checkkwd = 0;
+ heredoclist = 0;
doprompt = interact;
if (doprompt)
setprompt(doprompt);
needprompt = 0;
- t = readtoken();
- if (t == TEOF)
- return NEOF;
- if (t == TNL)
- return NULL;
- tokpushback++;
return list(1);
}
@@ -158,11 +152,27 @@ list(int nlflag)
union node *n1, *n2, *n3;
int tok;
- checkkwd = CHKNL | CHKKWD | CHKALIAS;
- if (nlflag == 2 && tokendlist[peektoken()])
- return NULL;
n1 = NULL;
for (;;) {
+ switch (peektoken()) {
+ case TNL:
+ if (!(nlflag & 1))
+ break;
+ parseheredoc();
+ return n1;
+
+ case TEOF:
+ if (!n1 && (nlflag & 1))
+ n1 = NEOF;
+ parseheredoc();
+ return n1;
+ }
+
+ checkkwd = CHKNL | CHKKWD | CHKALIAS;
+ if (nlflag == 2 && tokendlist[peektoken()])
+ return n1;
+ nlflag |= 2;
+
n2 = andor();
tok = readtoken();
if (tok == TBACKGND) {
@@ -189,29 +199,15 @@ list(int nlflag)
n1 = n3;
}
switch (tok) {
- case TBACKGND:
- case TSEMI:
- tok = readtoken();
- /* fall through */
case TNL:
- if (tok == TNL) {
- parseheredoc();
- if (nlflag == 1)
- return n1;
- } else {
- tokpushback++;
- }
- checkkwd = CHKNL | CHKKWD | CHKALIAS;
- if (tokendlist[peektoken()])
- return n1;
- break;
case TEOF:
- if (heredoclist)
- parseheredoc();
tokpushback++;
- return n1;
+ /* fall through */
+ case TBACKGND:
+ case TSEMI:
+ break;
default:
- if (nlflag == 1)
+ if ((nlflag & 1))
synexpect(-1);
tokpushback++;
return n1;
@@ -1443,10 +1439,6 @@ parsearith: {
#ifdef mkinit
INCLUDE "parser.h"
-RESET {
- tokpushback = 0;
- checkkwd = 0;
-}
#endif
next prev parent reply other threads:[~2014-11-05 8:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-05 8:47 [0/3] Minor parser fixes/cleanups Herbert Xu
2014-11-05 8:48 ` [PATCH 1/3] [PARSER] Removed unnecessary pungetc on EOF from parser Herbert Xu
2014-11-05 8:48 ` Herbert Xu [this message]
2014-11-05 8:48 ` [PATCH 3/3] [PARSER] Catch variable length expansions on non-existant specials Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1XlwGP-0005Xd-4f@gondolin.me.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=dash@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).