From c9f0949631a80da374424266683380b36b007337 Mon Sep 17 00:00:00 2001 From: Dmitri Tikhonov Date: Mon, 29 May 2023 13:22:00 -0400 Subject: [PATCH] Refactor function in Perl 6 parser for readability --- parsers/perl6.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/parsers/perl6.c b/parsers/perl6.c index 7672c24dab..e455642e56 100644 --- a/parsers/perl6.c +++ b/parsers/perl6.c @@ -267,24 +267,25 @@ deinitP6Ctx (struct p6Ctx *ctx) static int getNonSpaceStr (struct p6Ctx *ctx, const char **ptok) { - const char *s = ctx->line; - if (!s) { -next_line: - s = (const char *) readLineFromInputFile(); - if (!s) - return 0; /* EOF */ + size_t non_white_len; + const char *s; + + while (ctx->line) + { + s = ctx->line; + while (*s && isspace((unsigned char) *s)) /* Skip whitespace */ + ++s; + if ('#' != *s /* Skip comments */ + && (non_white_len = strcspn(s, ",; \t"), non_white_len > 0)) + { + ctx->line = s + non_white_len; /* Save state */ + *ptok = s; + return non_white_len; + } + ctx->line = (const char *) readLineFromInputFile(); } - while (*s && isspace((unsigned char) *s)) /* Skip whitespace */ - ++s; - if ('#' == *s) - goto next_line; - int non_white_len = strcspn(s, ",; \t"); - if (non_white_len) { - ctx->line = s + non_white_len; /* Save state */ - *ptok = s; - return non_white_len; - } else - goto next_line; + + return 0; } static void @@ -309,6 +310,7 @@ findPerl6Tags (void) const char *s; int len; + ctx.line = (const char *) readLineFromInputFile(); while ((len = getNonSpaceStr(&ctx, &s)) > 0) { enum token token = matchToken(s, len); if ((int) token >= 0) {