5 ms·
I feel like thats fine: syntactically valid, semantically not; Ideally syntax vs semantics should be decoupled in most parsing (hence the AST)
by setr 8y ago
I feel like thats fine: syntactically valid, semantically not;
Ideally syntax vs semantics should be decoupled in most parsing (hence the AST)
- samatman 8y ago256 is either 1[0-9][0-9] or 2[0-5][0-6], for the three digit case; that which can be syntactically detected, should be.
- setr 8y agoIt seems to me that validating on the AST would be a lot cleaner/saner (if int(ipv4addr) > 256: err), and generally allow for much better error messages; especially since you'll be doing almost all your validations on the AST anyways. It would ofc also be more useful in future parsing too (similar structure, but not ipv4), but thats a much more minor and rarer benefit
- diggernet 8y agoExcept you've missed 2x7-2x9...
- samatman 8y agoAh, you're right, that was careless of me here's the real deal courtesy of the URI spec: IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet dec-octet = DIGIT ; 0-9 / %x31-39 DIGIT ; 10-99 / "1" 2DIGIT ; 100-199 / "2" %x30-34 DIGIT ; 200-249 / "25" %x30-35 ; 250-255