Help needed: parsing pattern synonym contexts
Simon Peyton Jones
simonpj at microsoft.com
Tue Jun 24 16:37:49 UTC 2014
What do you mean by "doesn't work"? Crashes? Fails to build with some error? Builds but doesn't parse what you expect?
In the latter case, what happened to the shift/reduce and reduce/reduce errors reported by Happy? Esp the latter. If you are getting more you need to track them down.
For exmape if I see
pattern P ...
and I've gotten to the P. Have I seen an empty forall, and this is the beginning of context, or have I seen an empty patsyn_context, and this is the beginning of constr_stuff. I think this'll be a reduce/reduce error.
I think it may be helped by
patsyn_contxt :: forall | forall context '=>'
c.f the defn of 'constr'.
IN haste
Simoin
| -----Original Message-----
| From: ghc-devs [mailto:ghc-devs-bounces at haskell.org] On Behalf Of Dr.
| ERDI Gergo
| Sent: 24 June 2014 13:12
| To: GHC Devs
| Subject: Help needed: parsing pattern synonym contexts
|
| Hi,
|
| I'm working on adding type signatures to pattern synonyms. The syntax
| I'm after would look something like, e.g.:
|
| pattern (Eq b) => P Int (Bool, b) (f [a]) :: (Show a) => Maybe [a]
|
| My problem is with parsing the two contexts. I wrote the parser in the
| following way, which I felt natural (actions omitted for brevity)
|
| pattern_synonym_sig :: { LSig RdrName }
| : 'pattern' patsyn_context patsyn_stuff '::' patsyn_context
| type
|
| patsyn_stuff :: { Located (Located RdrName, HsPatSynDetails (LHsType
| RdrName)) }
| : constr_stuff
|
| patsyn_context :: { LHsContext RdrName }
| : {- empty -}
| | forall context '=>'
|
| However, this doesn't work, no matter if those contexts are present or
| not. If I remove both contexts from the rules, i.e. if I replace
| pattern_synonym_sig with
|
| : 'pattern' patsyn_stuff '::' type
|
| then parsing succeeds when there are no contexts on either side. I've
| also tried
|
| : 'pattern' patsyn_stuff '::' ctype
|
| with the intention of recovering the required context from the ctype
| (and I could do similar tricks to get the provided context from the
| patsyn_stuff by using a modified version of constr_stuff); however, even
| that doesn't work as I expected it, i.e. with this latter version, this:
|
| pattern Single a :: (Eq a) => [a]
|
| fails with a parse error on "::".
|
| Can someone help me out here please?
|
| Thanks,
| Gergo
| _______________________________________________
| ghc-devs mailing list
| ghc-devs at haskell.org
| http://www.haskell.org/mailman/listinfo/ghc-devs
More information about the ghc-devs
mailing list