Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Fri, 26 Apr 2024 21:47:52 UTC Commit: 7b14e1a8a31a6b52700c33c5880093e6e9a28d28 https://github.com/geany/geany/commit/7b14e1a8a31a6b52700c33c5880093e6e9a28d...
Log Message: ----------- Update perl6.c to raku.c parser
The file name has been changed and we cannot use the script for the update.
Modified Paths: -------------- ctags/Makefile.am ctags/parsers/raku.c meson.build
Modified: ctags/Makefile.am 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -86,12 +86,12 @@ parsers = \ parsers/pascal.c \ parsers/perl.c \ parsers/perl.h \ - parsers/perl6.c \ parsers/php.c \ parsers/powershell.c \ parsers/python.c \ parsers/r.c \ parsers/r.h \ + parsers/raku.c \ parsers/rst.c \ parsers/ruby.c \ parsers/rust.c \
Modified: ctags/parsers/raku.c 105 lines changed, 67 insertions(+), 38 deletions(-) =================================================================== @@ -1,6 +1,7 @@ /* - * perl6.c -- Perl6 parser. + * raku.c -- Raku parser. * Author: Dmitri Tikhonov dmitri@cpan.org + * Author: Will Coleda will@coleda.com * * This is a very basic Perl 6 parser. It does not know how to: * - skip POD; @@ -22,10 +23,9 @@ #include "parse.h" #include "read.h" #include "routines.h" -#include "selectors.h" #include "vstring.h"
-enum perl6Kind { +enum rakuKind { K_NONE = -1, K_CLASS, K_GRAMMAR, @@ -39,7 +39,7 @@ enum perl6Kind { K_TOKEN, };
-static kindDefinition perl6Kinds[] = { +static kindDefinition rakuKinds[] = { [K_CLASS] = { true, 'c', "class", "classes" }, [K_GRAMMAR] = { true, 'g', "grammar", "grammars" }, [K_METHOD] = { true, 'm', "method", "methods" }, @@ -70,7 +70,7 @@ enum token { T_TOKEN, };
-static const enum perl6Kind token2kind[] = { +static const enum rakuKind token2kind[] = { [T_CLASS] = K_CLASS, [T_GRAMMAR] = K_GRAMMAR, [T_METHOD] = K_METHOD, @@ -164,7 +164,7 @@ matchToken (const char *s, int len) return -1; }
-static const int validPerl6Identifier[0x100] = { +static const int validRakuIdentifier[0x100] = { /* r!perl -e "print qq([(int)'$_'] = 1,\n)for a..z,A..Z,0..9,':','-','_'"|fmt */ [(int)'a'] = 1, [(int)'b'] = 1, [(int)'c'] = 1, [(int)'d'] = 1, @@ -198,7 +198,7 @@ static const int kindMayHaveMethodPrefix = (1 << K_SUBMETHOD) | * identifier is invalid. */ static int -trimIdentifier (enum perl6Kind kind, const char **ps, int len) +trimIdentifier (enum rakuKind kind, const char **ps, int len) { Assert(len > 0); const char *const end = *ps + len; @@ -209,7 +209,7 @@ trimIdentifier (enum perl6Kind kind, const char **ps, int len) /* Record the start of identifier: */ *ps = s; /* Continuous string of valid characters: */ - while (s < end && validPerl6Identifier[(int)*s]) + while (s < end && validRakuIdentifier[(int)*s]) ++s; /* sub multi infix:<...> -- we want the "infix" only */ while (s - *ps > 0 && ':' == s[-1]) @@ -218,15 +218,15 @@ trimIdentifier (enum perl6Kind kind, const char **ps, int len) return s - *ps; }
-struct p6Ctx { +struct rakuCtx { enum token tokens[128 /* unlikely to need more than this */]; unsigned int n_tokens; vString *name; const char *line; /* Saved from readLineFromInputFile() */ };
static void -makeTag (struct p6Ctx *ctx, int kind, const char *name, int len) +makeTag (struct rakuCtx *ctx, int kind, const char *name, int len) { tagEntryInfo entry; vStringNCopyS(ctx->name, name, len); @@ -235,25 +235,25 @@ makeTag (struct p6Ctx *ctx, int kind, const char *name, int len) }
static void -possiblyMakeTag (struct p6Ctx *ctx, const char *s, int len) +possiblyMakeTag (struct rakuCtx *ctx, const char *s, int len) { Assert(ctx->n_tokens > 0); - enum perl6Kind kind = token2kind[ ctx->tokens[ctx->n_tokens - 1] ]; - if (K_NONE != kind && perl6Kinds[kind].enabled + enum rakuKind kind = token2kind[ ctx->tokens[ctx->n_tokens - 1] ]; + if (K_NONE != kind && rakuKinds[kind].enabled && (len = trimIdentifier(kind, &s, len)) > 0) makeTag(ctx, kind, s, len); }
static void -initP6Ctx (struct p6Ctx *ctx) +initRakuCtx (struct rakuCtx *ctx) { ctx->n_tokens = 0; ctx->name = vStringNew(); ctx->line = NULL; }
static void -deinitP6Ctx (struct p6Ctx *ctx) +deinitRakuCtx (struct rakuCtx *ctx) { vStringDelete(ctx->name); } @@ -265,32 +265,33 @@ deinitP6Ctx (struct p6Ctx *ctx) * TODO: Currently, POD and multi-line comments are not handled. */ static int -getNonSpaceStr (struct p6Ctx *ctx, const char **ptok) +getNonSpaceStr (struct rakuCtx *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(*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 -findPerl6Tags (void) +findRakuTags (void) { - struct p6Ctx ctx; + struct rakuCtx ctx;
#define RESET_TOKENS() do { ctx.n_tokens = 0; } while (0)
@@ -304,11 +305,12 @@ findPerl6Tags (void) } \ } while (0)
- initP6Ctx(&ctx); + initRakuCtx(&ctx);
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) { @@ -319,13 +321,40 @@ findPerl6Tags (void) } }
- deinitP6Ctx(&ctx); + deinitRakuCtx(&ctx); }
+parserDefinition * +RakuParser (void) +{ + static const char *const extensions[] = { "raku", "rakumod", "rakutest", "rakudoc", NULL }; + parserDefinition* def = parserNew("Raku"); + def->kindTable = rakuKinds; + def->kindCount = ARRAY_SIZE(rakuKinds); + def->extensions = extensions; + def->parser = findRakuTags; + return def; +} + + +/* + * Perl6 for keeping backward compatibility of the CLI. + */ +#include "selectors.h" +/* TODO: sharing a kind array within two parsers are bad idea. + * e.g. The combination of --kinds-Perl6=+c and --kinds-Raku=-c + * doesn't work. + */ +#define perl6Kinds rakuKinds +/* NOTE: We assume the grammer of Raku is upper compatible with + * Perl6. When this assumption is no longer true, we may have to + * copy the function, or this file. Don't waste your time to + * make one function support two languages; Copying may be enough. */ +#define findPerl6Tags findRakuTags parserDefinition * Perl6Parser (void) { - static const char *const extensions[] = { "p6", "pm6", "pm", "pl6", NULL }; + static const char *const extensions[] = { "p6", "pm6", "pm", "pl6", "t6", NULL }; static selectLanguage selectors [] = { selectByPickingPerlVersion, NULL }; parserDefinition* def = parserNew("Perl6");
Modified: meson.build 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -664,12 +664,12 @@ ctags = static_library('ctags', 'ctags/parsers/pascal.c', 'ctags/parsers/perl.c', 'ctags/parsers/perl.h', - 'ctags/parsers/perl6.c', 'ctags/parsers/php.c', 'ctags/parsers/powershell.c', 'ctags/parsers/python.c', 'ctags/parsers/r.c', 'ctags/parsers/r.h', + 'ctags/parsers/raku.c', 'ctags/parsers/rst.c', 'ctags/parsers/ruby.c', 'ctags/parsers/rust.c',
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).