• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision3876 (tree)
Time2018-09-19 00:55:20
Authormagicant

Log Message

Simplify parse_group function

Change Summary

Incremental Difference

--- yash/branches/token_based_parser/parser.c (revision 3875)
+++ yash/branches/token_based_parser/parser.c (revision 3876)
@@ -611,7 +611,7 @@
611611 __attribute__((nonnull,malloc,warn_unused_result));
612612 static command_T *parse_compound_command(parsestate_T *ps)
613613 __attribute__((nonnull,malloc,warn_unused_result));
614-static command_T *parse_group(parsestate_T *ps, commandtype_T type)
614+static command_T *parse_group(parsestate_T *ps)
615615 __attribute__((nonnull,malloc,warn_unused_result));
616616 static command_T *parse_if(parsestate_T *ps)
617617 __attribute__((nonnull,malloc,warn_unused_result));
@@ -2333,10 +2333,8 @@
23332333 command_T *result;
23342334 switch (ps->tokentype) {
23352335 case TT_LPAREN:
2336- result = parse_group(ps, CT_SUBSHELL);
2337- break;
23382336 case TT_LBRACE:
2339- result = parse_group(ps, CT_GROUP);
2337+ result = parse_group(ps);
23402338 break;
23412339 case TT_IF:
23422340 result = parse_if(ps);
@@ -2364,26 +2362,27 @@
23642362 }
23652363
23662364 /* Parses a command group.
2367- * `type' must be either CT_GROUP or CT_SUBSHELL.
23682365 * The current token must be the starting "(" or "{". Never returns NULL. */
2369-command_T *parse_group(parsestate_T *ps, commandtype_T type)
2366+command_T *parse_group(parsestate_T *ps)
23702367 {
2371- tokentype_T starttt, endtt;
2368+ commandtype_T type;
2369+ tokentype_T endtt;
23722370 const wchar_t *starts, *ends;
23732371
2374- switch (type) {
2375- case CT_GROUP:
2376- starttt = TT_LBRACE, endtt = TT_RBRACE;
2372+ switch (ps->tokentype) {
2373+ case TT_LBRACE:
2374+ type = CT_GROUP;
2375+ endtt = TT_RBRACE;
23772376 starts = L"{", ends = L"}";
23782377 break;
2379- case CT_SUBSHELL:
2380- starttt = TT_LPAREN, endtt = TT_RPAREN;
2378+ case TT_LPAREN:
2379+ type = CT_SUBSHELL;
2380+ endtt = TT_RPAREN;
23812381 starts = L"(", ends = L")";
23822382 break;
23832383 default:
23842384 assert(false);
23852385 }
2386- assert(ps->tokentype == starttt);
23872386 next_token(ps);
23882387
23892388 command_T *result = xmalloc(sizeof *result);
Show on old repository browser