Skip to content

Instantly share code, notes, and snippets.

@ay0ks
Last active May 13, 2024 21:36
Show Gist options
  • Save ay0ks/e567e9906f7b47939515dbeecbf90fe4 to your computer and use it in GitHub Desktop.
Save ay0ks/e567e9906f7b47939515dbeecbf90fe4 to your computer and use it in GitHub Desktop.
my role Debug::Grammar {
rule package_declarator:sym<LOGGER> {
<sym> <block>
}
}
my role Debug::Actions {
method package_declarator:sym<LOGGER>(Mu $/) {
# Declare $*LOGGER globally (or in the callee's context).
use Pretty::Debug; # Logger class is defined here
# Gives an error:
# EVAL q {
# use Pretty::Debug;
# our $*LOGGER = Logger.new();
# }
}
}
use Slangify Debug::Grammar, Debug::Actions;
LOGGER {};
# $*LOGGER is defined now.
$*LOGGER.info("abcdef");
# Or the another thing I'm trying to achieve, which is
# easier but is stalled since I couldn't create a global variable
# from the slang action.
INFO "abcdef"; # => $*LOGGER.info("abcdef");
INFO {
"First line.";
"Second line.";
}
# => $*LOGGER.info("First line", "Second line");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment