-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What's the purpose of the set of unexpected items? #227
Comments
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. |
Ah, I see. This is a consequence of not using a lexer. Being a proponent of lexers, I don't sympathize with this use case, but I guess it's a valid one. Perhaps you could include this example in the documentation too? |
Where do you propose to put it? |
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 |
There is a description of the sets in the docs for |
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
Maybe
instead ofSet
?Or, if the intention is that the multiple consecutive tokens are unexpected, shouldn't it be a list?
The text was updated successfully, but these errors were encountered: