Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-ihaskell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-ihaskell
Commits
9e4ef2e6
Commit
9e4ef2e6
authored
Sep 01, 2018
by
Erik de Castro Lopo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ghc-parser: Switch on -Wall and fix all warnings
parent
3d382e7b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
70 additions
and
54 deletions
+70
-54
Parser.hs
ghc-parser/generic-src/Language/Haskell/GHC/Parser.hs
+66
-49
ghc-parser.cabal
ghc-parser/ghc-parser.cabal
+1
-0
HappyParser.hs
ghc-parser/src-8.0/Language/Haskell/GHC/HappyParser.hs
+0
-1
HappyParser.hs
ghc-parser/src-8.4/Language/Haskell/GHC/HappyParser.hs
+0
-4
stack-8.0.yaml
stack-8.0.yaml
+1
-0
stack-8.4.yaml
stack-8.4.yaml
+1
-0
stack.yaml
stack.yaml
+1
-0
No files found.
ghc-parser/generic-src/Language/Haskell/GHC/Parser.hs
View file @
9e4ef2e6
...
@@ -31,15 +31,14 @@ import Bag
...
@@ -31,15 +31,14 @@ import Bag
import
ErrUtils
hiding
(
ErrMsg
)
import
ErrUtils
hiding
(
ErrMsg
)
import
FastString
import
FastString
#
if
MIN_VERSION_ghc
(
8
,
4
,
0
)
#
if
MIN_VERSION_ghc
(
8
,
4
,
0
)
import
GHC
hiding
(
Located
,
Parsed
)
import
GHC
hiding
(
Located
,
Parsed
,
parser
)
#
else
#
else
import
GHC
hiding
(
Located
)
import
GHC
hiding
(
Located
,
parser
)
#
endif
#
endif
import
Lexer
import
Lexer
hiding
(
buffer
)
import
OrdList
import
OrdList
import
Outputable
hiding
((
<>
))
import
qualified
SrcLoc
as
SrcLoc
import
SrcLoc
hiding
(
Located
)
import
StringBuffer
hiding
(
len
)
import
StringBuffer
import
qualified
Language.Haskell.GHC.HappyParser
as
Parse
import
qualified
Language.Haskell.GHC.HappyParser
as
Parse
...
@@ -74,12 +73,48 @@ data Located a = Located {
...
@@ -74,12 +73,48 @@ data Located a = Located {
data
Parser
a
=
Parser
(
P
a
)
data
Parser
a
=
Parser
(
P
a
)
-- Our parsers.
-- Our parsers.
parserStatement
=
Parser
Parse
.
fullStatement
#
if
MIN_VERSION_ghc
(
8
,
4
,
0
)
parserImport
=
Parser
Parse
.
fullImport
parserStatement
::
Parser
(
Maybe
(
LStmt
GhcPs
(
LHsExpr
GhcPs
)))
parserDeclaration
=
Parser
Parse
.
fullDeclaration
#
else
parserExpression
=
Parser
Parse
.
fullExpression
parserStatement
::
Parser
(
Maybe
(
LStmt
RdrName
(
LHsExpr
RdrName
)))
parserTypeSignature
=
Parser
Parse
.
fullTypeSignature
#
endif
parserModule
=
Parser
Parse
.
fullModule
parserStatement
=
Parser
Parse
.
fullStatement
#
if
MIN_VERSION_ghc
(
8
,
4
,
0
)
parserImport
::
Parser
(
LImportDecl
GhcPs
)
#
else
parserImport
::
Parser
(
LImportDecl
RdrName
)
#
endif
parserImport
=
Parser
Parse
.
fullImport
#
if
MIN_VERSION_ghc
(
8
,
4
,
0
)
parserDeclaration
::
Parser
(
OrdList
(
LHsDecl
GhcPs
))
#
else
parserDeclaration
::
Parser
(
OrdList
(
LHsDecl
RdrName
))
#
endif
parserDeclaration
=
Parser
Parse
.
fullDeclaration
#
if
MIN_VERSION_ghc
(
8
,
4
,
0
)
parserExpression
::
Parser
(
LHsExpr
GhcPs
)
#
else
parserExpression
::
Parser
(
LHsExpr
RdrName
)
#
endif
parserExpression
=
Parser
Parse
.
fullExpression
#
if
MIN_VERSION_ghc
(
8
,
4
,
0
)
parserTypeSignature
::
Parser
(
SrcLoc
.
Located
(
OrdList
(
LHsDecl
GhcPs
)))
#
else
parserTypeSignature
::
Parser
(
SrcLoc
.
Located
(
OrdList
(
LHsDecl
RdrName
)))
#
endif
parserTypeSignature
=
Parser
Parse
.
fullTypeSignature
#
if
MIN_VERSION_ghc
(
8
,
4
,
0
)
parserModule
::
Parser
(
SrcLoc
.
Located
(
HsModule
GhcPs
))
#
else
parserModule
::
Parser
(
SrcLoc
.
Located
(
HsModule
RdrName
))
#
endif
parserModule
=
Parser
Parse
.
fullModule
-- | Run a GHC parser on a string. Return success or failure with
-- | Run a GHC parser on a string. Return success or failure with
-- associated information for both.
-- associated information for both.
...
@@ -87,7 +122,7 @@ runParser :: DynFlags -> Parser a -> String -> ParseOutput a
...
@@ -87,7 +122,7 @@ runParser :: DynFlags -> Parser a -> String -> ParseOutput a
runParser
flags
(
Parser
parser
)
str
=
runParser
flags
(
Parser
parser
)
str
=
-- Create an initial parser state.
-- Create an initial parser state.
let
filename
=
"<interactive>"
let
filename
=
"<interactive>"
location
=
mkRealSrcLoc
(
mkFastString
filename
)
1
1
location
=
SrcLoc
.
mkRealSrcLoc
(
mkFastString
filename
)
1
1
buffer
=
stringToStringBuffer
str
buffer
=
stringToStringBuffer
str
parseState
=
mkPState
flags
buffer
location
in
parseState
=
mkPState
flags
buffer
location
in
-- Convert a GHC parser output into our own.
-- Convert a GHC parser output into our own.
...
@@ -95,48 +130,29 @@ runParser flags (Parser parser) str =
...
@@ -95,48 +130,29 @@ runParser flags (Parser parser) str =
where
where
toParseOut
::
ParseResult
a
->
ParseOutput
a
toParseOut
::
ParseResult
a
->
ParseOutput
a
#
if
MIN_VERSION_ghc
(
8
,
4
,
0
)
#
if
MIN_VERSION_ghc
(
8
,
4
,
0
)
toParseOut
(
PFailed
_
sp
a
n
@
(
RealSrcSpan
realSpan
)
err
)
=
toParseOut
(
PFailed
_
spn
@
(
RealSrcSpan
realSpan
)
err
)
=
#
else
#
else
toParseOut
(
PFailed
sp
a
n
@
(
RealSrcSpan
realSpan
)
err
)
=
toParseOut
(
PFailed
spn
@
(
RealSrcSpan
realSpan
)
err
)
=
#
endif
#
endif
let
errMsg
=
printErrorBag
$
unitBag
$
mkPlainErrMsg
flags
sp
a
n
err
let
errMsg
=
printErrorBag
$
unitBag
$
mkPlainErrMsg
flags
spn
err
l
ine
=
srcLocLine
$
realSrcSpanStart
realSpan
l
n
=
srcLocLine
$
SrcLoc
.
realSrcSpanStart
realSpan
col
=
srcLocCol
$
realSrcSpanStart
realSpan
col
=
srcLocCol
$
SrcLoc
.
realSrcSpanStart
realSpan
in
Failure
errMsg
$
Loc
l
ine
col
in
Failure
errMsg
$
Loc
l
n
col
#
if
MIN_VERSION_ghc
(
8
,
4
,
0
)
#
if
MIN_VERSION_ghc
(
8
,
4
,
0
)
toParseOut
(
PFailed
_
sp
a
n
err
)
=
toParseOut
(
PFailed
_
spn
err
)
=
#
else
#
else
toParseOut
(
PFailed
sp
a
n
err
)
=
toParseOut
(
PFailed
spn
err
)
=
#
endif
#
endif
let
errMsg
=
printErrorBag
$
unitBag
$
mkPlainErrMsg
flags
sp
a
n
err
let
errMsg
=
printErrorBag
$
unitBag
$
mkPlainErrMsg
flags
spn
err
in
Failure
errMsg
$
Loc
0
0
in
Failure
errMsg
$
Loc
0
0
toParseOut
(
POk
parseState
result
)
=
toParseOut
(
POk
_parseState
result
)
=
let
parseEnd
=
realSrcSpanStart
$
last_loc
parseState
Parsed
result
endLine
=
srcLocLine
parseEnd
endCol
=
srcLocCol
parseEnd
(
before
,
after
)
=
splitAtLoc
endLine
endCol
str
in
Parsed
result
-- Convert the bag of errors into an error string.
-- Convert the bag of errors into an error string.
printErrorBag
bag
=
joinLines
.
map
show
$
bagToList
bag
printErrorBag
bag
=
joinLines
.
map
show
$
bagToList
bag
-- | Split a string at a given line and column. The column is included in
-- the second part of the split.
splitAtLoc
::
LineNumber
->
ColumnNumber
->
String
->
(
String
,
String
)
splitAtLoc
line
col
string
=
if
line
>
length
(
lines
string
)
then
(
string
,
""
)
else
(
before
,
after
)
where
(
beforeLines
,
afterLines
)
=
splitAt
line
$
lines
string
theLine
=
last
beforeLines
(
beforeChars
,
afterChars
)
=
splitAt
(
col
-
1
)
theLine
before
=
joinLines
(
init
beforeLines
)
++
'
\n
'
:
beforeChars
after
=
joinLines
$
afterChars
:
afterLines
-- Not the same as 'unlines', due to trailing \n
-- Not the same as 'unlines', due to trailing \n
joinLines
::
[
String
]
->
String
joinLines
::
[
String
]
->
String
joinLines
=
intercalate
"
\n
"
joinLines
=
intercalate
"
\n
"
...
@@ -151,7 +167,7 @@ layoutChunks :: String -> [Located String]
...
@@ -151,7 +167,7 @@ layoutChunks :: String -> [Located String]
layoutChunks
=
joinQuasiquotes
.
go
1
layoutChunks
=
joinQuasiquotes
.
go
1
where
where
go
::
LineNumber
->
String
->
[
Located
String
]
go
::
LineNumber
->
String
->
[
Located
String
]
go
l
ine
=
filter
(
not
.
null
.
unloc
)
.
map
(
fmap
strip
)
.
layoutLines
line
.
lines
go
l
n
=
filter
(
not
.
null
.
unloc
)
.
map
(
fmap
strip
)
.
layoutLines
ln
.
lines
-- drop spaces on left and right
-- drop spaces on left and right
strip
=
dropRight
.
dropLeft
strip
=
dropRight
.
dropLeft
...
@@ -165,13 +181,13 @@ layoutChunks = joinQuasiquotes . go 1
...
@@ -165,13 +181,13 @@ layoutChunks = joinQuasiquotes . go 1
layoutLines
_
[]
=
[]
layoutLines
_
[]
=
[]
-- Use the indent of the first line to find the end of the first block.
-- Use the indent of the first line to find the end of the first block.
layoutLines
lineIdx
all
@
(
firstLine
:
rest
)
=
layoutLines
lineIdx
xs
@
(
firstLine
:
rest
)
=
let
firstIndent
=
indentLevel
firstLine
let
firstIndent
=
indentLevel
firstLine
blockEnded
l
ine
=
indentLevel
line
<=
firstIndent
in
blockEnded
l
n
=
indentLevel
ln
<=
firstIndent
in
case
findIndex
blockEnded
rest
of
case
findIndex
blockEnded
rest
of
-- If the first block doesn't end, return the whole string, since
-- If the first block doesn't end, return the whole string, since
-- that just means the block takes up the entire string.
-- that just means the block takes up the entire string.
Nothing
->
[
Located
lineIdx
$
intercalate
"
\n
"
all
]
Nothing
->
[
Located
lineIdx
$
intercalate
"
\n
"
xs
]
-- We found the end of the block. Split this bit out and recurse.
-- We found the end of the block. Split this bit out and recurse.
Just
idx
->
Just
idx
->
...
@@ -213,6 +229,7 @@ removeComments = removeOneLineComments . removeMultilineComments 0 0
...
@@ -213,6 +229,7 @@ removeComments = removeOneLineComments . removeMultilineComments 0 0
where
where
dropLine
=
removeOneLineComments
.
dropWhile
(
/=
'
\n
'
)
dropLine
=
removeOneLineComments
.
dropWhile
(
/=
'
\n
'
)
removeMultilineComments
::
Int
->
Int
->
String
->
String
removeMultilineComments
nesting
pragmaNesting
str
=
removeMultilineComments
nesting
pragmaNesting
str
=
case
str
of
case
str
of
-- Don't remove comments after cmd directives
-- Don't remove comments after cmd directives
...
@@ -253,8 +270,8 @@ removeComments = removeOneLineComments . removeMultilineComments 0 0
...
@@ -253,8 +270,8 @@ removeComments = removeOneLineComments . removeMultilineComments 0 0
-- Take a part of a string that ends in an unescaped quote.
-- Take a part of a string that ends in an unescaped quote.
takeString
str
=
case
str
of
takeString
str
=
case
str
of
escaped
@
(
'
\\
'
:
'"'
:
rest
)
->
escaped
escaped
@
(
'
\\
'
:
'"'
:
_
)
->
escaped
'"'
:
rest
->
"
\"
"
'"'
:
_
->
"
\"
"
x
:
xs
->
x
:
takeString
xs
x
:
xs
->
x
:
takeString
xs
[]
->
[]
[]
->
[]
...
...
ghc-parser/ghc-parser.cabal
View file @
9e4ef2e6
...
@@ -18,6 +18,7 @@ cabal-version: >=1.16
...
@@ -18,6 +18,7 @@ cabal-version: >=1.16
library
library
build-tools: happy, cpphs
build-tools: happy, cpphs
ghc-options: -Wall
exposed-modules: Language.Haskell.GHC.Parser,
exposed-modules: Language.Haskell.GHC.Parser,
Language.Haskell.GHC.HappyParser
Language.Haskell.GHC.HappyParser
-- other-modules:
-- other-modules:
...
...
ghc-parser/src-8.0/Language/Haskell/GHC/HappyParser.hs
View file @
9e4ef2e6
...
@@ -17,7 +17,6 @@ import HsSyn
...
@@ -17,7 +17,6 @@ import HsSyn
import
OrdList
import
OrdList
-- compiler/parser
-- compiler/parser
import
RdrHsSyn
import
Lexer
import
Lexer
-- compiler/basicTypes
-- compiler/basicTypes
...
...
ghc-parser/src-8.4/Language/Haskell/GHC/HappyParser.hs
View file @
9e4ef2e6
...
@@ -17,12 +17,8 @@ import HsSyn
...
@@ -17,12 +17,8 @@ import HsSyn
import
OrdList
import
OrdList
-- compiler/parser
-- compiler/parser
import
RdrHsSyn
import
Lexer
import
Lexer
-- compiler/basicTypes
import
RdrName
fullStatement
::
P
(
Maybe
(
LStmt
GhcPs
(
LHsExpr
GhcPs
)))
fullStatement
::
P
(
Maybe
(
LStmt
GhcPs
(
LHsExpr
GhcPs
)))
fullStatement
=
parseStmt
fullStatement
=
parseStmt
...
...
stack-8.0.yaml
View file @
9e4ef2e6
...
@@ -21,6 +21,7 @@ extra-deps: []
...
@@ -21,6 +21,7 @@ extra-deps: []
ghc-options
:
ghc-options
:
# Eventually we want "$locals": -Wall -Werror
# Eventually we want "$locals": -Wall -Werror
ghc-parser
:
-Wall -Werror
ihaskell
:
-Wall -Werror
ihaskell
:
-Wall -Werror
nix
:
nix
:
...
...
stack-8.4.yaml
View file @
9e4ef2e6
...
@@ -20,6 +20,7 @@ extra-deps:
...
@@ -20,6 +20,7 @@ extra-deps:
ghc-options
:
ghc-options
:
# Eventually we want "$locals": -Wall -Werror
# Eventually we want "$locals": -Wall -Werror
ghc-parser
:
-Wall -Werror
ihaskell
:
-Wall -Werror
ihaskell
:
-Wall -Werror
nix
:
nix
:
...
...
stack.yaml
View file @
9e4ef2e6
...
@@ -19,6 +19,7 @@ packages:
...
@@ -19,6 +19,7 @@ packages:
ghc-options
:
ghc-options
:
# Eventually we want "$locals": -Wall -Werror
# Eventually we want "$locals": -Wall -Werror
ghc-parser
:
-Wall -Werror
ihaskell
:
-Wall -Werror
ihaskell
:
-Wall -Werror
allow-newer
:
true
allow-newer
:
true
...
...
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