Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created September 14, 2023 13:04
Show Gist options
  • Select an option

  • Save gfldex/10c78c784822bf4e673cb2f15326279d to your computer and use it in GitHub Desktop.

Select an option

Save gfldex/10c78c784822bf4e673cb2f15326279d to your computer and use it in GitHub Desktop.
constant &auto-enum = BEGIN (Q:to /◻/).EVAL;
proto sub quasi-enum($str, |opts ( :$DEFAULT, :$SOURCEPOS, :$HARDBREAKS, :$UNSAFE, :$NOBREAKS, :$NORMALIZE, :$VALIDATE_UTF8, :$SMART, :$GITHUB_PRE_LANG, :$LIBERAL_HTML_TAG, :$FOOTNOTES, :$STRIKETHROUGH_DOUBLE_TILDE, :$TABLE_PREFER_STYLE_ATTRIBUTES, :$FULL_INFO_STRING )) {
constant %CMARK_OPTIONS =
DEFAULT => 0,
SOURCEPOS => 1 +< 1,
HARDBREAKS => 1 +< 2,
UNSAFE => 1 +< 17,
NOBREAKS => 1 +< 4,
NORMALIZE => 1 +< 8,
VALIDATE_UTF8 => 1 +< 9 ,
SMART => 1 +< 10,
GITHUB_PRE_LANG => 1 +< 11,
LIBERAL_HTML_TAG => 1 +< 12,
FOOTNOTES => 1 +< 13,
STRIKETHROUGH_DOUBLE_TILDE => 1 +< 14,
TABLE_PREFER_STYLE_ATTRIBUTES => 1 +< 15,
FULL_INFO_STRING => 1 +< 16
;
my $opts = [+|] %CMARK_OPTIONS{opts.hash.keys};
nextwith($str, $opts)
}
multi sub auto-enum($str, int $opt) {
# codes goes here
}
dd auto-enum('foo', :SMART);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment