Rand Stats

Rainbow

zef:patrickb

NAME

Rainbow

Raku source code lexer

Synopsis

use Rainbow;

my %mapping =
    TEXT     => '#ffffff',
    KEYWORD  => "#e04c86",
    OPERATOR => "#e04c86",
    TYPE     => "#00ffff",
    ROUTINE  => "#978deb",
    STRING   => "#68f3ca",
    # ...
;

my $code = 'my $greet = "hello"; say "Oh $greet there!";';

my @tokens = Rainbow::tokenize($code);

my @fragments = @tokens.map: -> $t {
    my $color = %mapping{$t.type.key} // %mapping<TEXT>;
    say "$color: {$t.text}";
}

Description

This module can turn a piece of Raku code into a list of tokens. Assign each token a color and you have made yourself a Raku syntax highlighter.

See lib/Rainbow/Token.rakumod for the complete list of tokens.

AUTHOR

Patrick Böker patrick.boeker@posteo.de

THANKS

Thanks to Siavash Askari Nasr (CIAvash) for the Chroma Raku lexer which this module took as inspiration.

License

This module is distributed under the terms of the Artistic License 2.0.