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
867aabca
Commit
867aabca
authored
Jul 09, 2019
by
Vaibhav Sagar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use parseDynamicFilePragma
parent
a1244922
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
1 deletion
+31
-1
Parser.hs
ghc-parser/generic-src/Language/Haskell/GHC/Parser.hs
+19
-0
Parser.hs
src/IHaskell/Eval/Parser.hs
+4
-1
Eval.hs
src/tests/IHaskell/Test/Eval.hs
+8
-0
No files found.
ghc-parser/generic-src/Language/Haskell/GHC/Parser.hs
View file @
867aabca
...
...
@@ -18,6 +18,7 @@ module Language.Haskell.GHC.Parser (
parserTypeSignature
,
parserModule
,
parserExpression
,
parsePragmasIntoDynFlags
,
-- Haskell string preprocessing.
removeComments
,
...
...
@@ -28,6 +29,7 @@ import Data.List (intercalate, findIndex, isInfixOf)
import
Data.Char
(
isAlphaNum
)
import
Bag
import
DynFlags
(
parseDynamicFilePragma
)
import
ErrUtils
hiding
(
ErrMsg
)
import
FastString
#
if
MIN_VERSION_ghc
(
8
,
4
,
0
)
...
...
@@ -35,8 +37,10 @@ import GHC hiding (Located, Parsed, parser)
#
else
import
GHC
hiding
(
Located
,
parser
)
#
endif
import
HeaderInfo
(
getOptions
)
import
Lexer
hiding
(
buffer
)
import
OrdList
import
Panic
(
handleGhcException
)
import
qualified
SrcLoc
as
SrcLoc
import
StringBuffer
hiding
(
len
)
...
...
@@ -153,6 +157,21 @@ runParser flags (Parser parser) str =
-- Convert the bag of errors into an error string.
printErrorBag
bag
=
joinLines
.
map
show
$
bagToList
bag
-- Taken from http://blog.shaynefletcher.org/2019/06/have-ghc-parsing-respect-dynamic-pragmas.html
parsePragmasIntoDynFlags
::
DynFlags
->
FilePath
->
String
->
IO
(
Maybe
DynFlags
)
parsePragmasIntoDynFlags
flags
filepath
str
=
catchErrors
$
do
let
opts
=
getOptions
flags
(
stringToStringBuffer
str
)
filepath
(
flags'
,
_
,
_
)
<-
parseDynamicFilePragma
flags
opts
return
$
Just
flags'
where
catchErrors
::
IO
(
Maybe
DynFlags
)
->
IO
(
Maybe
DynFlags
)
catchErrors
act
=
handleGhcException
reportErr
(
handleSourceError
reportErr
act
)
reportErr
e
=
do
putStrLn
$
"error : "
++
show
e
return
Nothing
-- Not the same as 'unlines', due to trailing \n
joinLines
::
[
String
]
->
String
joinLines
=
intercalate
"
\n
"
...
...
src/IHaskell/Eval/Parser.hs
View file @
867aabca
...
...
@@ -75,7 +75,10 @@ data PragmaType = PragmaLanguage
parseString
::
String
->
Ghc
[
Located
CodeBlock
]
parseString
codeString
=
do
-- Try to parse this as a single module.
flags
<-
getSessionDynFlags
flags'
<-
getSessionDynFlags
flags
<-
do
result
<-
liftIO
$
parsePragmasIntoDynFlags
flags'
"<interactive>"
codeString
return
$
fromMaybe
flags'
result
let
output
=
runParser
flags
parserModule
codeString
case
output
of
Parsed
mdl
...
...
src/tests/IHaskell/Test/Eval.hs
View file @
867aabca
...
...
@@ -175,3 +175,11 @@ testEval =
import Debug.Trace
trace "test" 5
|]
`
becomes
`
[
"test
\n
5"
]
-- it "immediately applies language extensions" $ do
-- [hereLit|
-- {-# LANGUAGE RankNTypes #-}
-- identity :: forall a. a -> a
-- identity a = a
-- |] `becomes` []
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