I've also used it to fail a pattern that would otherwise match. It is
possible to come up with a pattern that matches the numbers between 0 and
255 but it's quite involved and part of it looks like:
dec_octet = P"25" * R"05"
+ P"2" * P"04" * P"09"
+ P"1" * ...
I found it easier to use Cmt() instead:
local dec_octet = Cmt(DIGIT^1,function(_,position,capture)
local n = tonumber(capture)
if n < 256 then
return position
end
end)
When the string of digits is greater than 255, this returns nil, which
causes the match to fail. Doing this:
dec_octet = DIGIT^1
/ function(c)
local n = tonumber(c)
if n < 256 then
return c
end
end
won't cause the match to fail---instead it will return nil as the captured
data.