Lexer sub-group match

I have the following code in my lexer in order to parse hex-numbers of the format '#0f'.

((:seq #\# (:+ (:or numeric (union-mixed "A" "B" "C" "D" "E" "F"))))
 (token-Hexdecimal (string->number (string-append (substring lexeme 0 1)
                                                  "x"
                                                  (substring lexeme 1)))))

The lexer joins the sequence of # and the digits into the string lexeme. After that I split the string into the # and the digits in order to be able to insert the "x" in between. This can't be efficient. Is it anyhow possible to define capturing groups in the regular expression?

(string->number (substring lexeme 1) 16)
1 Like