I want to accept a decimal number between 0 and 255. This is the best I can come up with:
fragment my_token :
('0'..'9') | // 0 -> 9
('1'..'9' '0'..'9') | // 0 -> 99
('1' '0'..'9' '0'..'9') | // 100 -> 199
('2' '0'..'4' '0'..'9') | // 200 -> 249
('25' '0'..'5'); // 250 -> 255
but I am just a clueless n00b. Surelry there is a better way?
You’ll have much better results if you relax the lexer and defer the checking to a later time. Lex
NUMBER, then when you convert it later you can provide a very specific error message if the value is out of range. If you make the lexer strict and someone enters 256, the error message that results is illegible to anyone that hasn’t made a grammar before.