These rules are all the same, except the "digit" part: for binary numbers I'm using $bin_digit regex for the digits, for hex I'm using $hex_digit, and similar for other rules.
If we could implement "rule templates" that take regex as arguments, we could do have one template with a "digit" parameter, and pass $hex_digit, $oct_digit, etc. to it and avoid duplication.
Here are rules I'm using to lex Rust decimal, binary, octal, and hexadecimal numbers:
These rules are all the same, except the "digit" part: for binary numbers I'm using
$bin_digit
regex for the digits, for hex I'm using$hex_digit
, and similar for other rules.If we could implement "rule templates" that take regex as arguments, we could do have one template with a "digit" parameter, and pass
$hex_digit
,$oct_digit
, etc. to it and avoid duplication.