The end of the scheme

Hello,

I actually have a misunderstanding about the grammar of the scheme. Here’s it:
image
I would like to know why :// is not included. Well I tried to test
http: and the parser returned null, although it respects the scheme grammar.

best regards

The grammar looks something like this:

URI -> scheme + "://" + [userinfo "@"] + host + path + ["?" + query]

and the scheme follows the rule you posted. The interpretation of this is that every valid URI starts with a letter followed by an arbitrary number of letters and digits and then a colon and two slashes. So everything before :// is considered the scheme. The :// is just a separator so you can identify what the scheme is. These would all be valid URIs if there was no ://:

httpsgoogle
https
httpsuser:password@google

Note that the : alone is not sufficient to identify the scheme, because it also occurs in the userinfo.

Since the :// follows every scheme it is pointless to include it in the scheme. You don’t say the space after your first name out loud when somebody asks you what your name is. :grinning:

1 Like

Can I claim that sbcd1:// is a valid scheme?

The string sbcd1:// is a valid URI in our grammar and has scheme sbcd1.

2 posts were split to a new topic: UriParserTest testScheme: NullPointerException

Thank you for the reply🙂. So if I understood it well,
http: is a valid URI but not a valid scheme. I actually received the test results and parsing http: returned null(not valid). I don’t understand this part

No, http:// is a valid URI, https: is not. There is no URI in our specification which does not contain ://.

Your confusion probably comes from the fact that the // is not in the first rule but rather in the rule for the hierarchical, so it is “hidden”. It can be helpful to substitute some of the rules into each other to get a better overview, like I did above:

URI -> scheme + "://" + [userinfo "@"] + host + path + ["?" + query]

where I inserted the rule for the authority into the rule for the hierarchical and the resulting rule for the hierarchical into the rule for the URI.

Yeah exactly ! That was my confusion. Thanks :slightly_smiling_face:

am still somehow confused. I just tried to follow the examples which are given to us by so doing:

....create("test://").parse() -- the multiple dots at the beginning represents the function name. Am a bit lazy

Is that what you mean by am passing null to the create method??

More generally speaking, the scheme is the part of the string that is generated with the scheme rule in the grammar:

scheme        = ALPHA *( ALPHA / DIGIT )

Therefore, it is the first part before the colon in the URI.

A post was split to a new topic: Valid scheme http://