Skip to content
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

Regression in parsec-3.1.6 #9

Closed
edsko opened this issue Sep 23, 2014 · 2 comments
Closed

Regression in parsec-3.1.6 #9

edsko opened this issue Sep 23, 2014 · 2 comments

Comments

@edsko
Copy link

edsko commented Sep 23, 2014

Consider

import Control.Applicative ((<*), (<$>), (<$))
import Text.Parsec
import Text.Parsec.Language (haskellStyle)
import Text.Parsec.String (Parser)
import Text.Parsec.Expr
import qualified Text.Parsec.Token as P

data Expr = Const Integer | Op Expr Expr
  deriving Show

{-------------------------------------------------------------------------------
  Syntax analysis
-------------------------------------------------------------------------------}

parseTopLevel :: Parser Expr
parseTopLevel = parseExpr <* eof

parseExpr :: Parser Expr
parseExpr = buildExpressionParser table (Const <$> integer)
  where
    table = [[ Infix (Op <$ reserved ">>>") AssocLeft ]]

{-------------------------------------------------------------------------------
  Lexical analysis
-------------------------------------------------------------------------------}

lexer = P.makeTokenParser haskellStyle { P.reservedOpNames = [">>>"] }

integer    = P.integer    lexer
reserved   = P.reserved   lexer
reservedOp = P.reservedOp lexer

with parsec-3.1.5 and below we get

*Main> parseTest parseTopLevel "4 >> 5"
parse error at (line 1, column 3):
unexpected '>'
expecting operator or end of input

but with parsec-3.1.6 we get

*Main> parseTest parseTopLevel "4 >> 5"
parse error at (line 1, column 5):
unexpected " "
expecting operator
@kosmikus
Copy link

This is caused by 8607649. I think that change should just be reverted for now.

kosmikus referenced this issue Sep 23, 2014
Example

Before:

  Prelude Text.Parsec> parseTest (string "abcd") "abbe"
  parse error at (line 1, column 1):
  unexpected "b"
  expecting "abcd"

After:

  *Main> parseTest (string "abcd") "abbe"
  parse error at (line 1, column 3):
  unexpected "b"
  expecting "cd"

Before this patch, 'b' was reported to be found at 1:1, which is clearly not the
case. After this patch, we correctly report the location of the wrong token, and
also report missing tokens starting from that position.
aslatter added a commit that referenced this issue Sep 25, 2014
Also move test for #2 to have a more regular structure for tests aimed at
specific bugs.
@aslatter
Copy link
Collaborator

Thanks for the bug report.

I've reverted the change, and I'll be pushing out 3.1.7 soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants