# Grammar to parse the UCA collation data grammar Collation-Gram { token TOP { \s* ';' \s* + .* } token codepoints { + % \s+ } token codepoint { <:AHex>+ #[$=(<:AHex>)\s+] } token comment { \s* '#' \s* <( .* $ } token coll-key { '[' ~ ']' [ '.' '.' ] } token dot-star { <[.*]> } token primary { <:AHex>+ } token secondary { <:AHex>+ } token tertiary { <:AHex>+ } } class Collation-Gram::Action { has @!array; has $!comment; has $!dot-star; has @!codepoints; method TOP ($/) { @!codepoints = @!codepoints.chrs.ords; make %( array => @!array, comment => ~$, codepoints => @!codepoints.chrs.ords ) } method coll-key ($/) { my $a = ($, $, $).map(*.Str.parse-base(16)).Array; $a.push: ($ eq '.' ?? 0 !! $ eq '*' ?? 1 !! do { die $ }); @!array.push: $a; } method codepoints ($/) { @!codepoints.append: $.map(*.Str.parse-base(16)); } }