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

Support parsing Backpack signatures. #355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Language/Haskell/Exts/InternalLexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ data Token
| KW_Instance
| KW_Let
| KW_Module
| KW_Signature
| KW_NewType
| KW_Of
| KW_Proc -- arrows
Expand Down Expand Up @@ -300,6 +301,7 @@ special_varids = [
( "as", (KW_As, Nothing) ),
( "qualified", (KW_Qualified, Nothing) ),
( "hiding", (KW_Hiding, Nothing) ),
( "signature", (KW_Signature, Nothing) ),

-- FFI
( "export", (KW_Export, Just (Any [ForeignFunctionInterface])) ),
Expand Down Expand Up @@ -1399,6 +1401,7 @@ showToken t = case t of
KW_Instance -> "instance"
KW_Let -> "let"
KW_Module -> "module"
KW_Signature -> "signature"
KW_NewType -> "newtype"
KW_Of -> "of"
KW_Proc -> "proc"
Expand Down
7 changes: 6 additions & 1 deletion src/Language/Haskell/Exts/InternalParser.ly
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ Reserved Ids
> 'let' { Loc $$ KW_Let }
> 'mdo' { Loc $$ KW_MDo }
> 'module' { Loc $$ KW_Module } -- 114
> 'signature' { Loc $$ KW_Signature }
> 'newtype' { Loc $$ KW_NewType }
> 'of' { Loc $$ KW_Of }
> 'proc' { Loc $$ KW_Proc } -- arrows
Expand Down Expand Up @@ -297,7 +298,7 @@ Pragmas
> %partial ngparsePragmasAndModuleHead moduletophead
> %partial ngparsePragmasAndModuleName moduletopname
> %tokentype { Loc Token }
> %expect 10
> %expect 12
> %%

-----------------------------------------------------------------------------
Expand Down Expand Up @@ -365,6 +366,7 @@ Module Header

> optmodulehead :: { Maybe (ModuleHead L) }
> : 'module' modid maybemodwarning maybeexports 'where' { Just $ ModuleHead ($1 <^^> $5 <** [$1,$5]) $2 $3 $4 }
> | 'signature' modid maybemodwarning maybeexports 'where' { Just $ ModuleHead ($1 <^^> $5 <** [$1,$5]) $2 $3 $4 }
> | {- empty -} { Nothing }

> maybemodwarning :: { Maybe (WarningText L) }
Expand Down Expand Up @@ -1609,6 +1611,7 @@ Hsx Extensions - requires XmlSyntax, but the lexer handles all that.
> | 'let' { Loc $1 "let" }
> | 'mdo' { Loc $1 "mdo" }
> | 'module' { Loc $1 "module" }
> | 'signature' { Loc $1 "signature" }
> | 'newtype' { Loc $1 "newtype" }
> | 'of' { Loc $1 "of" }
> | 'proc' { Loc $1 "proc" }
Expand Down Expand Up @@ -1893,6 +1896,7 @@ Identifiers and Symbols
> : VARID { let Loc l (VarId v) = $1 in Ident (nIS l) v }
> | 'as' { as_name (nIS $1) }
> | 'qualified' { qualified_name (nIS $1) }
> | 'signature' { signature_name (nIS $1) }
> | 'hiding' { hiding_name (nIS $1) }
> | 'export' { export_name (nIS $1) }
> | 'stdcall' { stdcall_name (nIS $1) }
Expand Down Expand Up @@ -2084,6 +2088,7 @@ Exported as partial parsers:

> moduletopname :: { (([ModulePragma L], [S], L), Maybe (ModuleName L)) }
> : toppragmas 'module' modid { ($1, Just $3) }
> | toppragmas 'signature' modid { ($1, Just $3) }
> | toppragmas {- empty -} { ($1, Nothing) }

> moduletophead :: { (([ModulePragma L], [S], L), Maybe (ModuleHead L)) }
Expand Down
5 changes: 3 additions & 2 deletions src/Language/Haskell/Exts/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module Language.Haskell.Exts.Syntax (
unit_con_name, tuple_con_name, list_cons_name, unboxed_singleton_con_name,
unit_con, tuple_con, unboxed_singleton_con,
-- ** Special identifiers
as_name, qualified_name, hiding_name, minus_name, bang_name, dot_name, star_name,
as_name, qualified_name, signature_name, hiding_name, minus_name, bang_name, dot_name, star_name,
export_name, safe_name, unsafe_name, interruptible_name, threadsafe_name,
stdcall_name, ccall_name, cplusplus_name, dotnet_name, jvm_name, js_name,
javascript_name, capi_name, forall_name, family_name, role_name,
Expand Down Expand Up @@ -1013,9 +1013,10 @@ tuple_con l b i = Con l (tuple_con_name l b i)
unboxed_singleton_con :: l -> Exp l
unboxed_singleton_con l = Con l (unboxed_singleton_con_name l)

as_name, qualified_name, hiding_name, minus_name, bang_name, dot_name, star_name :: l -> Name l
as_name, qualified_name, signature_name, hiding_name, minus_name, bang_name, dot_name, star_name :: l -> Name l
as_name l = Ident l "as"
qualified_name l = Ident l "qualified"
signature_name l = Ident l "signature"
hiding_name l = Ident l "hiding"
minus_name l = Symbol l "-"
bang_name l = Symbol l "!"
Expand Down