Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
What's the purpose of the set of unexpected items? #227
I understand how multiple possible tokens could be expected, but I struggle to understand what a set of unexpected tokens means.
In my own code, this set is always empty or singleton. If this covers all the cases, then perhaps it should be
Or, if the intention is that the multiple consecutive tokens are unexpected, shouldn't it be a list?
This is a good question, thanks for asking it now while the (re-)design in this area is still in flux.
I think I know of only one case when there may be several unexpected tokens:
module Main (main) where import Data.Void import Text.Megaparsec -- current master import Text.Megaparsec.Char type Parser = Parsec Void String pScheme :: Parser String pScheme = choice [ string "data" , string "file" , string "ftp" , string "https" , string "http" , string "irc" , string "mailto" ] main :: IO () main = parseTest pScheme "dat"
This currently prints:
This is because
Logically, it sort of makes sense:
It looks like unexpected item can only be a token from the input stream or
So what takes precedence over what in that case? Should labels win over collection of tokens, what about end of input? It looks like it's not possible to get unexpected end of input and unexpected token(s) at the same position, but I doubt it's encodable in the types in a satisfactory fashion.
I'd put it in the docs for
Or make a separate haddock section explaining the two sets and reference it from other places. (This would subsume #226.) I can't find the docs for that markup at the moment, but it was something like