Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
4,311
Issues
4,311
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
384
Merge Requests
384
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
cb8044eb
Commit
cb8044eb
authored
Sep 17, 2006
by
bjorn@bringert.net
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added parser and abstract syntax support for stand-alone deriving declarations.
parent
52f8fed4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
6 deletions
+35
-6
compiler/hsSyn/HsDecls.lhs
compiler/hsSyn/HsDecls.lhs
+20
-1
compiler/parser/Lexer.x
compiler/parser/Lexer.x
+1
-1
compiler/parser/Parser.y.pp
compiler/parser/Parser.y.pp
+2
-3
compiler/parser/RdrHsSyn.lhs
compiler/parser/RdrHsSyn.lhs
+12
-1
No files found.
compiler/hsSyn/HsDecls.lhs
View file @
cb8044eb
...
...
@@ -9,7 +9,7 @@ Definitions for: @TyDecl@ and @oCnDecl@, @ClassDecl@,
\begin{code}
module HsDecls (
HsDecl(..), LHsDecl, TyClDecl(..), LTyClDecl,
InstDecl(..), LInstDecl, NewOrData(..),
InstDecl(..), LInstDecl,
DerivDecl(..), LDerivDecl,
NewOrData(..),
RuleDecl(..), LRuleDecl, RuleBndr(..),
DefaultDecl(..), LDefaultDecl, SpliceDecl(..),
ForeignDecl(..), LForeignDecl, ForeignImport(..), ForeignExport(..),
...
...
@@ -67,6 +67,7 @@ type LHsDecl id = Located (HsDecl id)
data HsDecl id
= TyClD (TyClDecl id)
| InstD (InstDecl id)
| DerivD (DerivDecl id)
| ValD (HsBind id)
| SigD (Sig id)
| DefD (DefaultDecl id)
...
...
@@ -153,6 +154,7 @@ instance OutputableBndr name => Outputable (HsDecl name) where
ppr (ValD binds) = ppr binds
ppr (DefD def) = ppr def
ppr (InstD inst) = ppr inst
ppr (DerivD deriv) = ppr deriv
ppr (ForD fd) = ppr fd
ppr (SigD sd) = ppr sd
ppr (RuleD rd) = ppr rd
...
...
@@ -713,6 +715,23 @@ instDeclATs :: InstDecl name -> [LTyClDecl name]
instDeclATs (InstDecl _ _ _ ats) = ats
\end{code}
%************************************************************************
%* *
\subsection[DerivDecl]{A stand-alone instance deriving declaration
%* *
%************************************************************************
\begin{code}
type LDerivDecl name = Located (DerivDecl name)
data DerivDecl name
= DerivDecl (Located name) (LHsType name)
instance (OutputableBndr name) => Outputable (DerivDecl name) where
ppr (DerivDecl cls ty)
= hsep [ptext SLIT("deriving"), ppr cls, ppr ty]
\end{code}
%************************************************************************
%* *
\subsection[DefaultDecl]{A @default@ declaration}
...
...
compiler/parser/Lexer.x
View file @
cb8044eb
...
...
@@ -27,7 +27,7 @@ module Lexer (
failLocMsgP, failSpanMsgP, srcParseFail,
popContext, pushCurrentContext, setLastToken, setSrcLoc,
getLexState, popLexState, pushLexState,
extension, bangPatEnabled
extension,
glaExtsEnabled,
bangPatEnabled
) where
#include "HsVersions.h"
...
...
compiler/parser/Parser.y.pp
View file @
cb8044eb
...
...
@@ -455,9 +455,8 @@ topdecl :: { OrdList (LHsDecl RdrName) }
:
cl_decl
{
unitOL
(
L1
(
TyClD
(
unLoc
$1
)))
}
|
ty_decl
{
unitOL
(
L1
(
TyClD
(
unLoc
$1
)))
}
|
'instance'
inst_type
where
{
let
(
binds
,
sigs
,
ats
)
=
cvBindsAndSigs
(
unLoc
$3
)
in
unitOL
(
L
(
comb3
$1
$2
$3
)
(
InstD
(
InstDecl
$2
binds
sigs
ats
)))
}
{
let
(
binds
,
sigs
)
=
cvBindsAndSigs
(
unLoc
$3
)
in
unitOL
(
L
(
comb3
$1
$2
$3
)
(
InstD
(
InstDecl
$2
binds
sigs
)))
}
|
'default'
'('
comma_types0
')'
{
unitOL
(
LL
$
DefD
(
DefaultDecl
$3
))
}
|
'foreign'
fdecl
{
unitOL
(
LL
(
unLoc
$2
))
}
|
'{-# DEPRECATED'
deprecations
'#-}'
{
$2
}
...
...
compiler/parser/RdrHsSyn.lhs
View file @
cb8044eb
...
...
@@ -40,6 +40,7 @@ module RdrHsSyn (
checkSynHdr, -- LHsType RdrName -> P (Located RdrName, [LHsTyVarBndr RdrName], [LHsType RdrName])
checkKindSigs, -- [LTyClDecl RdrName] -> P ()
checkInstType, -- HsType -> P HsType
checkDerivDecl, -- LDerivDecl RdrName -> P (LDerivDecl RdrName)
checkPattern, -- HsExp -> P HsPat
checkPatterns, -- SrcLoc -> [HsExp] -> P [HsPat]
checkDo, -- [Stmt] -> P [Stmt]
...
...
@@ -56,7 +57,7 @@ import RdrName ( RdrName, isRdrTyVar, mkUnqual, rdrNameOcc,
isRdrDataCon, isUnqual, getRdrName, isQual,
setRdrNameSpace )
import BasicTypes ( maxPrecedence, Activation, InlineSpec(..), alwaysInlineSpec, neverInlineSpec )
import Lexer ( P, failSpanMsgP, extension, bangPatEnabled )
import Lexer ( P, failSpanMsgP, extension,
glaExtsEnabled,
bangPatEnabled )
import TysWiredIn ( unitTyCon )
import ForeignCall ( CCallConv, Safety, CCallTarget(..), CExportSpec(..),
DNCallSpec(..), DNKind(..), CLabelString )
...
...
@@ -559,6 +560,16 @@ checkDictTy (L spn ty) = check ty []
check (HsParTy t) args = check (unLoc t) args
check _ _ = parseError spn "Malformed context in instance header"
---------------------------------------------------------------------------
-- Checking stand-alone deriving declarations
checkDerivDecl :: LDerivDecl RdrName -> P (LDerivDecl RdrName)
checkDerivDecl d@(L loc _) =
do glaExtOn <- extension glaExtsEnabled
if glaExtOn then return d
else parseError loc "Illegal stand-alone deriving declaration (use -fglasgow-exts)"
---------------------------------------------------------------------------
-- Checking statements in a do-expression
-- We parse do { e1 ; e2 ; }
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment