Skip to content

Commit

Permalink
Refactor function in Perl 6 parser for readability (#3738)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtikhonov committed May 29, 2023
1 parent b3e1ad7 commit 1765d0c
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions parsers/perl6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 1765d0c

Please sign in to comment.