Ticket #103 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

Not able to parse 'a, b, c :: Type' style type signatures

Reported by: erikd Owned by: erikd
Priority: blocker Milestone:
Component: Source Parser Version:
Keywords: Cc:

Description

Type signatures like:

a, b, c
Int

result in an error message like:

unexpected ,

Change History

Changed 5 years ago by erikd

  • status changed from new to assigned

I found where the problem is, its in src/Source/Parsed/Exp.hs.

Basically this code:

    -- | Parse a type sig (only)
    pStmt_sig :: Parser (Stmt SP)
    pStmt_sig
     = do  var     <- liftM vNameV $ pVar
           pTok K.HasType
           typ     <- pType
           return  $ SSig (spV var) var typ

needs to use Parsec.sepBy1 something like this:

    -- | Parse a type sig (only)
    pStmt_sig :: Parser (Stmt SP)
    pStmt_sig
     = do   vars        <- Parsec.sepBy1 pVar (pTok K.Comma)
            let vars' = map vNameV vars
            pTok K.HasType
            typ        <- pType
            case map vNameV vars of
                    [] -> error "pStmt_sig : Empty list."
                    [var] ->  return $ SSig (spV var) var typ
                    _ -> error "Need to handle this case."

The only problem is that it seems that the SSig constructor can only return a single variable name at a time.

I looked at hacking src/Source/Exp.hs to add:

    data Stmt a	
	= SSig		a Var Type
        | SSigs		[a] [Var] Type

but that broke the compile elsewhere (src/Source/Plate/Trans.hs) as well as giving a bunch of non-exhaustive search warnings.

Any clues on the best way to fix this?

Changed 5 years ago by erikd

  • status changed from assigned to closed
  • resolution set to fixed

Fixed by the following two commits:

Thu Aug 13 20:45:27 EST 2009 Erik de Castro Lopo <erikd@…>

  • Finalize fix for #103 with a test.

Thu Aug 13 16:25:40 EST 2009 Ben.Lippmeier@…

  • Partial fix for #103: Allow multiple vars in Source.Exp.Stmt.SSig
Note: See TracTickets for help on using tickets.