-
-
Save ay0ks/e567e9906f7b47939515dbeecbf90fe4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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