Parser output at rule "violation"


I’m a bit confused on how the parser should behave if rules are violated.
Say we input the string "https://127.a.b.c", thats clearly a violation of the IPv4-address rule since youre only allowed to use digits.
Now, what would the parser output? Would it output null and discard the whole input, or would it output <https://>, discarding only the part where the authority->host->IPv4address->dec-octet rule thingy was violated? After all, the input string was obeying the scheme and hierarchical rule. Or something in between?


1 Like


the comments in say that the parser should

return the parsed Uri instance or null when the string is not a valid Uri with regards to the grammar given in Uri

So, you should only return a non-null reference if the entire input is a valid URI. You should not discard just parts of the input.

However, your example input https://127.a.b.c is a valid URI: The grammar in defines that a host may either be an IPv4address (which this is not), or a reg-name, which this is, since it is a string of alphabet characters, digits, and dots. Your parser should therefore parse it as such.

1 Like

You’re right, I haven’t thought about the reg name. However, that answered my question. Thanks :slight_smile:

1 Like