Suggest that user forgot " ".
component Main {
fun render : Html {
<h1>test</h1>
}
}
The error message here bugged me (A none self closing HTML tag must have a closing tag.), I counted at least three times, all the closing tags are there ... ;-)
So parsing an HTML tag works like this: first it matches the header tag, then it tries to find any child elements (tags, strings, arrays, fragments, HTML expressions, etc...) then the closing tag, now test in itself is not a proper child element thus it tries to match it as the closing tag but fails and that's why the error is what it is.
I don't know how to improve this any further and looking for suggestions, we know where the exact position the parser stops (t after <h1>), we know that we are parsing an HTML element (h1) and we know that the next token is test.
I do not know which parser Mint uses and if this works with this parser, but how about trying to parse [^<]+ aka, an error, after trying to parse all other possible types of childnodes, before checking for the closing tag?
Here is a related example. To be honest, I still do not know what I am doing wrong here.
component Main {
fun today: Time {
new Date()
}
fun render : String {
"Hi"
}
}
Gives The body of a function must end with a closing bracket. I was looking for the bracket } but found Date() instead. and highlights Date() in the codesnippet.
To be honest, I still do not know what I am doing wrong here.
There is no new keyword in Mint, in this example it's parsed as a variable and then the parser expects the end bracket } hence the error. To get the current time you can use the Time.now function https://www.mint-lang.com/api/modules/Time#now.
aka, an error, after trying to parse all other possible types of childnodes, before checking for the closing tag?
So you are saying that instead of showing an error about not finding the closing that we should show an error about something is not a valid child element?
There is no
newkeyword in Mint, in this example it's parsed as a variable and then the parser expects the end bracket}hence the error. To get the current time you can use theTime.nowfunction https://www.mint-lang.com/api/modules/Time#now.
Ahh, ok. I am still not wholly through the docs and had the illusion that I am actually writing Javascript inside of function bodies.
So you are saying that instead of showing an error about not finding the closing that we should show an error about something is not a valid child element?
Exactly. I am assuming here that the Mint parser parses alternatives in the order they are defined (Like PEG parsers do) and that [^<] is the last alternative.
In this case it means we would only have to check the first "t" of the word "test".
I don't know how to improve this any further and looking for suggestions, we know where the exact position the parser stops (
tafter<h1>), we know that we are parsing an HTML element (h1) and we know that the next token istest.
I don't know if you need to be precise on this issue. Just altering the error message may be sufficient. I feel like I was confused by this error enough times as a beginner that it warrants a change to the error message, something like
A none self closing HTML tag must have a closing tag. If you are trying to render a static string, it should be enclosed in quotes.
If you wanted to be precise, you might be able to go the approach of checking all valid starting tokens that are not String (what else is there besides <?), and if its not one of the valid tokens then you know it's String, and you can precisely show the correct error message that it should be enclosed in string. But maybe that is an oversimplification.
In Mint 0.20.0 this exact error will not happen since every expression will be allowed inside HTML tags. I'll close this issue when 0.20.0 is released.