-
Notifications
You must be signed in to change notification settings - Fork 44
Parse left- and right-assoc #2252
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
Parse left- and right-assoc #2252
Conversation
a3c1247
to
7e0553f
Compare
Now with better error messages!
The new name aligns with other modules in kore and megaparsec.
7e0553f
to
06bf285
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parser looks much cleaner to me now. I'm also wondering why the sentence type used to take a type variable in the first place. I have some questions but they're mostly for my own understanding, and I also have a couple of minor suggestions.
sortIdParser :: Parser Id | ||
sortIdParser = idParser | ||
parseSortId :: Parser Id | ||
parseSortId = parseId <?> "sort identifier" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm not very familiar with <?>
. From the documentation, I see it says that <?>
replaces the parsed token with "sort identifier" if it fails to parse any input. Does this mean that "sort identifier" will be part of the error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the error message will be:
unexpected ...
expected sort identifier
type Parser = Parsec String String | ||
type Parser = Parsec ReplParseError String | ||
|
||
newtype ReplParseError = ReplParseError { unReplParseError :: String } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the benefits of using a newtype with an IsString
instance here rather than String
directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we use String
directly, we have to declare an orphan instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's right, we needed the ShowErrorComponent
instance.
(Pattern variable Attribute.Null) | ||
where | ||
from = Recursive.embed . (:<) Attribute.Null . from | ||
{-# INLINE CONLIKE from #-} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I fully understand what CONLIKE
does from the GHC documentation, I'll keep in mind to try to learn more about it, but could you give me some hints related to why it was necessary here? Did something not work properly or is there something specific about this code which makes a pragma like this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CONLIKE
is short for "constructor-like". This tells GHC that this function is inexpensive to compute, like a constructor. This will make the compiler very aggressive about inlining it. I'm using it here because I know that all these functions put together are just applying several constructors on top of the argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand now, thank you!
Co-authored-by: ana-pantilie <[email protected]>
It was due to the class |
takeWhile :: (Char -> Bool) -> Parser String | ||
takeWhile = takeWhileP Nothing | ||
|
||
{-|'endOfInput' is similar to Attoparsec's 'endOfInput'. It matches only the | ||
end-of-input position. | ||
-} | ||
endOfInput :: Parser () | ||
endOfInput = eof | ||
|
||
instance ShowErrorComponent String where | ||
showErrorComponent str = str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing these utilities? (along with the rest from this file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are all either re-exporting a library function under a non-standard name, or they are redefining a library function.
Fixes #2124
Reviewer checklist
stack test --coverage
stack haddock