Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor function in Perl 6 parser for readability #3738

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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