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
7d5ac39e
Commit
7d5ac39e
authored
Feb 16, 2014
by
Andrew Gibiansky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #193 from PierreR/master
Fix #192: compilation failure with classy-prelude 0.8
parents
86db7eff
2c2249e6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
65 deletions
+65
-65
Completion.hs
src/IHaskell/Eval/Completion.hs
+8
-8
Evaluate.hs
src/IHaskell/Eval/Evaluate.hs
+14
-14
Hoogle.hs
src/IHaskell/Eval/Hoogle.hs
+23
-23
Parser.hs
src/IHaskell/Eval/Parser.hs
+8
-8
Main.hs
src/Main.hs
+12
-12
No files found.
src/IHaskell/Eval/Completion.hs
View file @
7d5ac39e
...
@@ -11,7 +11,7 @@ This has a limited amount of context sensitivity. It distinguishes between four
...
@@ -11,7 +11,7 @@ This has a limited amount of context sensitivity. It distinguishes between four
-}
-}
module
IHaskell.Eval.Completion
(
complete
,
completionTarget
,
completionType
,
CompletionType
(
..
))
where
module
IHaskell.Eval.Completion
(
complete
,
completionTarget
,
completionType
,
CompletionType
(
..
))
where
import
ClassyPrelude
hiding
(
liftIO
)
import
ClassyPrelude
hiding
(
init
,
last
,
head
,
liftIO
)
--import Prelude
--import Prelude
import
Control.Applicative
((
<$>
))
import
Control.Applicative
((
<$>
))
...
@@ -50,7 +50,7 @@ data CompletionType
...
@@ -50,7 +50,7 @@ data CompletionType
|
Qualified
String
String
|
Qualified
String
String
|
ModuleName
String
String
|
ModuleName
String
String
|
HsFilePath
String
String
|
HsFilePath
String
String
|
FilePath
String
String
|
FilePath
String
String
|
KernelOption
String
|
KernelOption
String
|
Extension
String
|
Extension
String
deriving
(
Show
,
Eq
)
deriving
(
Show
,
Eq
)
...
@@ -70,7 +70,7 @@ complete line pos = do
...
@@ -70,7 +70,7 @@ complete line pos = do
let
target
=
completionTarget
line
pos
let
target
=
completionTarget
line
pos
let
matchedText
=
case
completionType
line
pos
target
of
let
matchedText
=
case
completionType
line
pos
target
of
HsFilePath
_
match
->
match
HsFilePath
_
match
->
match
FilePath
_
match
->
match
FilePath
_
match
->
match
otherwise
->
intercalate
"."
target
otherwise
->
intercalate
"."
target
...
@@ -104,8 +104,8 @@ complete line pos = do
...
@@ -104,8 +104,8 @@ complete line pos = do
kernelOptNames
=
concatMap
getSetName
kernelOpts
kernelOptNames
=
concatMap
getSetName
kernelOpts
otherNames
=
[
"-package"
,
"-Wall"
,
"-w"
]
otherNames
=
[
"-package"
,
"-Wall"
,
"-w"
]
fNames
=
map
extName
fFlags
++
fNames
=
map
extName
fFlags
++
map
extName
fWarningFlags
++
map
extName
fWarningFlags
++
map
extName
fLangFlags
map
extName
fLangFlags
fNoNames
=
map
(
"no"
++
)
fNames
fNoNames
=
map
(
"no"
++
)
fNames
fAllNames
=
map
(
"-f"
++
)
(
fNames
++
fNoNames
)
fAllNames
=
map
(
"-f"
++
)
(
fNames
++
fNoNames
)
...
@@ -189,7 +189,7 @@ completionType line loc target
...
@@ -189,7 +189,7 @@ completionType line loc target
isModName
=
all
isCapitalized
(
init
target
)
isModName
=
all
isCapitalized
(
init
target
)
isCapitalized
=
isUpper
.
head
isCapitalized
=
isUpper
.
head
lineUpToCursor
=
take
loc
line
lineUpToCursor
=
take
loc
line
fileComplete
filePath
=
case
parseShell
lineUpToCursor
of
fileComplete
filePath
=
case
parseShell
lineUpToCursor
of
Right
xs
->
filePath
lineUpToCursor
$
Right
xs
->
filePath
lineUpToCursor
$
if
endswith
(
last
xs
)
lineUpToCursor
if
endswith
(
last
xs
)
lineUpToCursor
then
last
xs
then
last
xs
...
@@ -212,7 +212,7 @@ completionTarget code cursor = expandCompletionPiece pieceToComplete
...
@@ -212,7 +212,7 @@ completionTarget code cursor = expandCompletionPiece pieceToComplete
delimPolicy
=
Drop
delimPolicy
=
Drop
}
}
isDelim
::
Char
->
Int
->
Bool
isDelim
::
Char
->
Int
->
Bool
isDelim
char
idx
=
char
`
elem
`
neverIdent
||
isSymbol
char
isDelim
char
idx
=
char
`
elem
`
neverIdent
||
isSymbol
char
splitAlongCursor
::
[[(
Char
,
Int
)]]
->
[[(
Char
,
Int
)]]
splitAlongCursor
::
[[(
Char
,
Int
)]]
->
[[(
Char
,
Int
)]]
...
@@ -286,4 +286,4 @@ completePathFilter includeFile includeDirectory left right = liftIO $ do
...
@@ -286,4 +286,4 @@ completePathFilter includeFile includeDirectory left right = liftIO $ do
visible
=
filter
(
not
.
isHidden
)
suggestions
visible
=
filter
(
not
.
isHidden
)
suggestions
hidden
=
filter
isHidden
suggestions
hidden
=
filter
isHidden
suggestions
return
$
visible
++
hidden
return
$
visible
++
hidden
src/IHaskell/Eval/Evaluate.hs
View file @
7d5ac39e
...
@@ -9,7 +9,7 @@ module IHaskell.Eval.Evaluate (
...
@@ -9,7 +9,7 @@ module IHaskell.Eval.Evaluate (
interpret
,
evaluate
,
Interpreter
,
liftIO
,
typeCleaner
,
globalImports
interpret
,
evaluate
,
Interpreter
,
liftIO
,
typeCleaner
,
globalImports
)
where
)
where
import
ClassyPrelude
hiding
(
liftIO
,
hGetContents
,
try
)
import
ClassyPrelude
hiding
(
init
,
last
,
liftIO
,
head
,
hGetContents
,
tail
,
try
)
import
Control.Concurrent
(
forkIO
,
threadDelay
)
import
Control.Concurrent
(
forkIO
,
threadDelay
)
import
Prelude
(
putChar
,
head
,
tail
,
last
,
init
,
(
!!
))
import
Prelude
(
putChar
,
head
,
tail
,
last
,
init
,
(
!!
))
import
Data.List.Utils
import
Data.List.Utils
...
@@ -118,7 +118,7 @@ interpret allowedStdin action = runGhc (Just libdir) $ do
...
@@ -118,7 +118,7 @@ interpret allowedStdin action = runGhc (Just libdir) $ do
sandboxPackages
<-
liftIO
getSandboxPackageConf
sandboxPackages
<-
liftIO
getSandboxPackageConf
let
pkgConfs
=
case
sandboxPackages
of
let
pkgConfs
=
case
sandboxPackages
of
Nothing
->
extraPkgConfs
dflags
Nothing
->
extraPkgConfs
dflags
Just
path
->
Just
path
->
let
pkg
=
PkgConfFile
path
in
let
pkg
=
PkgConfFile
path
in
(
pkg
:
)
.
extraPkgConfs
dflags
(
pkg
:
)
.
extraPkgConfs
dflags
...
@@ -274,19 +274,19 @@ safely state = ghandle handler . ghandle sourceErrorHandler
...
@@ -274,19 +274,19 @@ safely state = ghandle handler . ghandle sourceErrorHandler
sourceErrorHandler
srcerr
=
do
sourceErrorHandler
srcerr
=
do
let
msgs
=
bagToList
$
srcErrorMessages
srcerr
let
msgs
=
bagToList
$
srcErrorMessages
srcerr
errStrs
<-
forM
msgs
$
\
msg
->
do
errStrs
<-
forM
msgs
$
\
msg
->
do
shortStr
<-
doc
$
errMsgShortDoc
msg
shortStr
<-
doc
$
errMsgShortDoc
msg
contextStr
<-
doc
$
errMsgExtraInfo
msg
contextStr
<-
doc
$
errMsgExtraInfo
msg
return
$
unlines
[
shortStr
,
contextStr
]
return
$
unlines
[
shortStr
,
contextStr
]
let
fullErr
=
unlines
errStrs
let
fullErr
=
unlines
errStrs
return
EvalOut
{
return
EvalOut
{
evalStatus
=
Failure
,
evalStatus
=
Failure
,
evalResult
=
displayError
fullErr
,
evalResult
=
displayError
fullErr
,
evalState
=
state
,
evalState
=
state
,
evalPager
=
""
evalPager
=
""
}
}
doc
::
GhcMonad
m
=>
SDoc
->
m
String
doc
::
GhcMonad
m
=>
SDoc
->
m
String
doc
sdoc
=
do
doc
sdoc
=
do
flags
<-
getSessionDynFlags
flags
<-
getSessionDynFlags
...
@@ -301,7 +301,7 @@ doc sdoc = do
...
@@ -301,7 +301,7 @@ doc sdoc = do
string_txt
(
Pretty
.
Str
s1
)
s2
=
s1
++
s2
string_txt
(
Pretty
.
Str
s1
)
s2
=
s1
++
s2
string_txt
(
Pretty
.
PStr
s1
)
s2
=
unpackFS
s1
++
s2
string_txt
(
Pretty
.
PStr
s1
)
s2
=
unpackFS
s1
++
s2
string_txt
(
Pretty
.
LStr
s1
_
)
s2
=
unpackLitString
s1
++
s2
string_txt
(
Pretty
.
LStr
s1
_
)
s2
=
unpackLitString
s1
++
s2
wrapExecution
::
KernelState
wrapExecution
::
KernelState
->
Interpreter
Display
->
Interpreter
Display
...
@@ -332,7 +332,7 @@ setDynFlags ext = do
...
@@ -332,7 +332,7 @@ setDynFlags ext = do
-- Create the parse errors.
-- Create the parse errors.
let
noParseErrs
=
map
((
"Could not parse: "
++
)
.
unLoc
)
unrecognized
let
noParseErrs
=
map
((
"Could not parse: "
++
)
.
unLoc
)
unrecognized
allWarns
=
map
unLoc
warnings
++
allWarns
=
map
unLoc
warnings
++
[
"-package not supported yet"
|
packageFlags
flags
/=
packageFlags
flags'
]
[
"-package not supported yet"
|
packageFlags
flags
/=
packageFlags
flags'
]
warnErrs
=
map
(
"Warning: "
++
)
allWarns
warnErrs
=
map
(
"Warning: "
++
)
allWarns
return
$
noParseErrs
++
warnErrs
return
$
noParseErrs
++
warnErrs
...
@@ -395,8 +395,8 @@ evalCommand _ (Module contents) state = wrapExecution state $ do
...
@@ -395,8 +395,8 @@ evalCommand _ (Module contents) state = wrapExecution state $ do
-- Since nothing prevents loading the module, compile and load it.
-- Since nothing prevents loading the module, compile and load it.
Nothing
->
doLoadModule
modName
modName
Nothing
->
doLoadModule
modName
modName
-- | Directives set via `:set`.
-- | Directives set via `:set`.
evalCommand
output
(
Directive
SetDynFlag
flags
)
state
=
evalCommand
output
(
Directive
SetDynFlag
flags
)
state
=
case
words
flags
of
case
words
flags
of
-- For a single flag.
-- For a single flag.
[
flag
]
->
do
[
flag
]
->
do
...
@@ -633,7 +633,7 @@ evalCommand _ (Directive GetInfo str) state = safely state $ do
...
@@ -633,7 +633,7 @@ evalCommand _ (Directive GetInfo str) state = safely state $ do
htmlify
str
=
htmlify
str
=
printf
"<div style='background: rgb(247, 247, 247);'><form><textarea id='code'>%s</textarea></form></div>"
str
printf
"<div style='background: rgb(247, 247, 247);'><form><textarea id='code'>%s</textarea></form></div>"
str
++
script
++
script
script
=
script
=
"<script>CodeMirror.fromTextArea(document.getElementById('code'), {mode: 'haskell', readOnly: 'nocursor'});</script>"
"<script>CodeMirror.fromTextArea(document.getElementById('code'), {mode: 'haskell', readOnly: 'nocursor'});</script>"
return
EvalOut
{
return
EvalOut
{
...
@@ -686,7 +686,7 @@ evalCommand output (Statement stmt) state = wrapExecution state $ do
...
@@ -686,7 +686,7 @@ evalCommand output (Statement stmt) state = wrapExecution state $ do
-- Return plain and html versions.
-- Return plain and html versions.
-- Previously there was only a plain version.
-- Previously there was only a plain version.
text
->
Display
text
->
Display
[
plain
$
joined
++
"
\n
"
++
text
,
[
plain
$
joined
++
"
\n
"
++
text
,
html
$
htmled
++
mono
text
]
html
$
htmled
++
mono
text
]
...
@@ -730,7 +730,7 @@ evalCommand output (Expression expr) state = do
...
@@ -730,7 +730,7 @@ evalCommand output (Expression expr) state = do
-- Check if the error is due to trying to print something that doesn't
-- Check if the error is due to trying to print something that doesn't
-- implement the Show typeclass.
-- implement the Show typeclass.
isShowError
(
ManyDisplay
_
)
=
False
isShowError
(
ManyDisplay
_
)
=
False
isShowError
(
Display
errs
)
=
isShowError
(
Display
errs
)
=
-- Note that we rely on this error message being 'type cleaned', so
-- Note that we rely on this error message being 'type cleaned', so
-- that `Show` is not displayed as GHC.Show.Show.
-- that `Show` is not displayed as GHC.Show.Show.
startswith
"No instance for (Show"
msg
&&
startswith
"No instance for (Show"
msg
&&
...
@@ -842,7 +842,7 @@ hoogleResults state results = EvalOut {
...
@@ -842,7 +842,7 @@ hoogleResults state results = EvalOut {
evalPager
=
output
evalPager
=
output
}
}
where
where
fmt
=
fmt
=
case
getFrontend
state
of
case
getFrontend
state
of
IPythonNotebook
->
Hoogle
.
HTML
IPythonNotebook
->
Hoogle
.
HTML
IPythonConsole
->
Hoogle
.
Plain
IPythonConsole
->
Hoogle
.
Plain
...
...
src/IHaskell/Eval/Hoogle.hs
View file @
7d5ac39e
{-# LANGUAGE NoImplicitPrelude, FlexibleInstances, OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude, FlexibleInstances, OverloadedStrings #-}
module
IHaskell.Eval.Hoogle
(
module
IHaskell.Eval.Hoogle
(
search
,
search
,
document
,
document
,
render
,
render
,
...
@@ -7,7 +7,7 @@ module IHaskell.Eval.Hoogle (
...
@@ -7,7 +7,7 @@ module IHaskell.Eval.Hoogle (
HoogleResult
HoogleResult
)
where
)
where
import
ClassyPrelude
hiding
(
span
,
div
)
import
ClassyPrelude
hiding
(
last
,
span
,
div
)
import
Text.Printf
import
Text.Printf
import
Network.HTTP
import
Network.HTTP
import
Data.Aeson
import
Data.Aeson
...
@@ -93,7 +93,7 @@ document string = do
...
@@ -93,7 +93,7 @@ document string = do
[]
->
[
NoResult
"no matching identifiers found."
]
[]
->
[
NoResult
"no matching identifiers found."
]
res
->
res
res
->
res
where
where
matches
(
SearchResult
resp
)
=
matches
(
SearchResult
resp
)
=
case
split
" "
$
self
resp
of
case
split
" "
$
self
resp
of
name
:
_
->
strip
string
==
strip
name
name
:
_
->
strip
string
==
strip
name
_
->
False
_
->
False
...
@@ -109,33 +109,33 @@ render HTML = renderHtml
...
@@ -109,33 +109,33 @@ render HTML = renderHtml
-- | Render a Hoogle result to plain text.
-- | Render a Hoogle result to plain text.
renderPlain
::
HoogleResult
->
String
renderPlain
::
HoogleResult
->
String
renderPlain
(
NoResult
res
)
=
renderPlain
(
NoResult
res
)
=
"No response available: "
++
res
"No response available: "
++
res
renderPlain
(
SearchResult
resp
)
=
renderPlain
(
SearchResult
resp
)
=
printf
"%s
\n
URL: %s
\n
%s"
printf
"%s
\n
URL: %s
\n
%s"
(
self
resp
)
(
self
resp
)
(
location
resp
)
(
location
resp
)
(
docs
resp
)
(
docs
resp
)
renderPlain
(
DocResult
resp
)
=
renderPlain
(
DocResult
resp
)
=
printf
"%s
\n
URL: %s
\n
%s"
printf
"%s
\n
URL: %s
\n
%s"
(
self
resp
)
(
self
resp
)
(
location
resp
)
(
location
resp
)
(
docs
resp
)
(
docs
resp
)
-- | Render a Hoogle result to HTML.
-- | Render a Hoogle result to HTML.
renderHtml
::
HoogleResult
->
String
renderHtml
::
HoogleResult
->
String
renderHtml
(
NoResult
resp
)
=
renderHtml
(
NoResult
resp
)
=
printf
"<span class='err-msg'>No result: %s</span>"
resp
printf
"<span class='err-msg'>No result: %s</span>"
resp
renderHtml
(
DocResult
resp
)
=
renderHtml
(
DocResult
resp
)
=
renderSelf
(
self
resp
)
(
location
resp
)
renderSelf
(
self
resp
)
(
location
resp
)
++
++
renderDocs
(
docs
resp
)
renderDocs
(
docs
resp
)
renderHtml
(
SearchResult
resp
)
=
renderHtml
(
SearchResult
resp
)
=
renderSelf
(
self
resp
)
(
location
resp
)
renderSelf
(
self
resp
)
(
location
resp
)
++
++
renderDocs
(
docs
resp
)
renderDocs
(
docs
resp
)
...
@@ -156,17 +156,17 @@ renderSelf string loc
...
@@ -156,17 +156,17 @@ renderSelf string loc
span
"hoogle-class"
(
link
loc
$
extractClass
string
)
++
span
"hoogle-class"
(
link
loc
$
extractClass
string
)
++
packageSub
package
packageSub
package
|
otherwise
|
otherwise
=
let
[
name
,
args
]
=
split
"::"
string
=
let
[
name
,
args
]
=
split
"::"
string
package
=
extractPackageName
loc
package
=
extractPackageName
loc
modname
=
extractModuleName
loc
in
modname
=
extractModuleName
loc
in
span
"hoogle-name"
(
unicodeReplace
$
span
"hoogle-name"
(
unicodeReplace
$
link
loc
(
strip
name
)
++
link
loc
(
strip
name
)
++
" :: "
++
" :: "
++
strip
args
)
strip
args
)
++
packageAndModuleSub
package
modname
++
packageAndModuleSub
package
modname
where
where
extractPackage
=
strip
.
replace
"package"
""
extractPackage
=
strip
.
replace
"package"
""
extractModule
=
strip
.
replace
"module"
""
extractModule
=
strip
.
replace
"module"
""
extractClass
=
strip
.
replace
"class"
""
extractClass
=
strip
.
replace
"class"
""
...
@@ -176,28 +176,28 @@ renderSelf string loc
...
@@ -176,28 +176,28 @@ renderSelf string loc
unicodeReplace
::
String
->
String
unicodeReplace
::
String
->
String
unicodeReplace
=
unicodeReplace
=
replace
"forall"
"∀"
.
replace
"forall"
"∀"
.
replace
"=>"
"⇒"
.
replace
"=>"
"⇒"
.
replace
"->"
"→"
.
replace
"->"
"→"
.
replace
"::"
"∷"
replace
"::"
"∷"
packageSub
Nothing
=
""
packageSub
Nothing
=
""
packageSub
(
Just
package
)
=
packageSub
(
Just
package
)
=
span
"hoogle-sub"
$
span
"hoogle-sub"
$
"("
++
pkg
++
" "
++
span
"hoogle-package"
package
++
")"
"("
++
pkg
++
" "
++
span
"hoogle-package"
package
++
")"
packageAndModuleSub
Nothing
_
=
""
packageAndModuleSub
Nothing
_
=
""
packageAndModuleSub
(
Just
package
)
Nothing
=
packageSub
(
Just
package
)
packageAndModuleSub
(
Just
package
)
Nothing
=
packageSub
(
Just
package
)
packageAndModuleSub
(
Just
package
)
(
Just
modname
)
=
packageAndModuleSub
(
Just
package
)
(
Just
modname
)
=
span
"hoogle-sub"
$
span
"hoogle-sub"
$
"("
++
pkg
++
" "
++
span
"hoogle-package"
package
++
"("
++
pkg
++
" "
++
span
"hoogle-package"
package
++
", "
++
mod
++
" "
++
span
"hoogle-module"
modname
++
")"
", "
++
mod
++
" "
++
span
"hoogle-module"
modname
++
")"
renderDocs
::
String
->
String
renderDocs
::
String
->
String
renderDocs
doc
=
renderDocs
doc
=
let
groups
=
groupBy
bothAreCode
$
lines
doc
let
groups
=
groupBy
bothAreCode
$
lines
doc
nonull
=
filter
(
not
.
null
.
strip
)
nonull
=
filter
(
not
.
null
.
strip
)
bothAreCode
s1
s2
=
bothAreCode
s1
s2
=
startswith
">"
(
strip
s1
)
&&
startswith
">"
(
strip
s1
)
&&
startswith
">"
(
strip
s2
)
startswith
">"
(
strip
s2
)
isCode
(
s
:
_
)
=
startswith
">"
$
strip
s
isCode
(
s
:
_
)
=
startswith
">"
$
strip
s
...
...
src/IHaskell/Eval/Parser.hs
View file @
7d5ac39e
...
@@ -15,7 +15,7 @@ module IHaskell.Eval.Parser (
...
@@ -15,7 +15,7 @@ module IHaskell.Eval.Parser (
)
where
)
where
-- Hide 'unlines' to use our own 'joinLines' instead.
-- Hide 'unlines' to use our own 'joinLines' instead.
import
ClassyPrelude
hiding
(
liftIO
,
unlines
)
import
ClassyPrelude
hiding
(
head
,
tail
,
liftIO
,
unlines
)
import
Data.List
(
findIndex
,
maximumBy
,
maximum
,
inits
)
import
Data.List
(
findIndex
,
maximumBy
,
maximum
,
inits
)
import
Data.String.Utils
(
startswith
,
strip
,
split
)
import
Data.String.Utils
(
startswith
,
strip
,
split
)
...
@@ -112,7 +112,7 @@ parseString codeString = do
...
@@ -112,7 +112,7 @@ parseString codeString = do
activateParsingExtensions
::
GhcMonad
m
=>
CodeBlock
->
m
()
activateParsingExtensions
::
GhcMonad
m
=>
CodeBlock
->
m
()
activateParsingExtensions
(
Directive
SetExtension
ext
)
=
void
$
setExtension
ext
activateParsingExtensions
(
Directive
SetExtension
ext
)
=
void
$
setExtension
ext
activateParsingExtensions
(
Directive
SetDynFlag
flags
)
=
activateParsingExtensions
(
Directive
SetDynFlag
flags
)
=
case
stripPrefix
"-X"
flags
of
case
stripPrefix
"-X"
flags
of
Just
ext
->
void
$
setExtension
ext
Just
ext
->
void
$
setExtension
ext
Nothing
->
return
()
Nothing
->
return
()
...
@@ -201,10 +201,10 @@ joinFunctions (Located line (Declaration decl) : rest) =
...
@@ -201,10 +201,10 @@ joinFunctions (Located line (Declaration decl) : rest) =
-- Get all declarations with the same name as the first declaration.
-- Get all declarations with the same name as the first declaration.
-- The name of a declaration is the first word, which we expect to be
-- The name of a declaration is the first word, which we expect to be
-- the name of the function.
-- the name of the function.
havingSameName
::
[
Located
CodeBlock
]
->
([
Located
CodeBlock
],
[
Located
CodeBlock
])
havingSameName
::
[
Located
CodeBlock
]
->
([
Located
CodeBlock
],
[
Located
CodeBlock
])
havingSameName
blocks
=
havingSameName
blocks
=
let
name
=
head
$
words
decl
let
name
=
head
$
words
decl
sameName
=
takeWhile
(
isNamedDecl
name
)
rest
sameName
=
takeWhile
(
isNamedDecl
name
)
rest
others
=
drop
(
length
sameName
)
rest
in
others
=
drop
(
length
sameName
)
rest
in
(
Located
line
(
Declaration
decl
)
:
sameName
,
others
)
(
Located
line
(
Declaration
decl
)
:
sameName
,
others
)
...
@@ -216,8 +216,8 @@ joinFunctions (Located line (Declaration decl) : rest) =
...
@@ -216,8 +216,8 @@ joinFunctions (Located line (Declaration decl) : rest) =
-- declarations. Parse the declaration joining separately.
-- declarations. Parse the declaration joining separately.
joinFunctions
(
Located
line
(
TypeSignature
sig
)
:
Located
dl
(
Declaration
decl
)
:
rest
)
=
joinFunctions
(
Located
line
(
TypeSignature
sig
)
:
Located
dl
(
Declaration
decl
)
:
rest
)
=
Located
line
(
Declaration
$
sig
++
"
\n
"
++
joinedDecl
)
:
remaining
Located
line
(
Declaration
$
sig
++
"
\n
"
++
joinedDecl
)
:
remaining
where
Located
_
(
Declaration
joinedDecl
)
:
remaining
=
joinFunctions
$
Located
dl
(
Declaration
decl
)
:
rest
where
Located
_
(
Declaration
joinedDecl
)
:
remaining
=
joinFunctions
$
Located
dl
(
Declaration
decl
)
:
rest
joinFunctions
(
x
:
xs
)
=
x
:
joinFunctions
xs
joinFunctions
(
x
:
xs
)
=
x
:
joinFunctions
xs
joinFunctions
[]
=
[]
joinFunctions
[]
=
[]
...
@@ -232,7 +232,7 @@ parseDirective (':':directive) line = case find rightDirective directives of
...
@@ -232,7 +232,7 @@ parseDirective (':':directive) line = case find rightDirective directives of
Just
(
directiveType
,
_
)
->
Directive
directiveType
arg
Just
(
directiveType
,
_
)
->
Directive
directiveType
arg
where
arg
=
unwords
restLine
where
arg
=
unwords
restLine
_
:
restLine
=
words
directive
_
:
restLine
=
words
directive
Nothing
->
Nothing
->
let
directiveStart
=
case
words
directive
of
let
directiveStart
=
case
words
directive
of
[]
->
""
[]
->
""
first
:
_
->
first
in
first
:
_
->
first
in
...
@@ -264,7 +264,7 @@ getModuleName moduleSrc = do
...
@@ -264,7 +264,7 @@ getModuleName moduleSrc = do
let
output
=
runParser
flags
parserModule
moduleSrc
let
output
=
runParser
flags
parserModule
moduleSrc
case
output
of
case
output
of
Failure
{}
->
error
"Module parsing failed."
Failure
{}
->
error
"Module parsing failed."
Parsed
mod
->
Parsed
mod
->
case
unLoc
<$>
hsmodName
(
unLoc
mod
)
of
case
unLoc
<$>
hsmodName
(
unLoc
mod
)
of
Nothing
->
error
"Module must have a name."
Nothing
->
error
"Module must have a name."
Just
name
->
return
$
split
"."
$
moduleNameString
name
Just
name
->
return
$
split
"."
$
moduleNameString
name
...
...
src/Main.hs
View file @
7d5ac39e
{-# LANGUAGE NoImplicitPrelude, CPP, OverloadedStrings, ScopedTypeVariables #-}
{-# LANGUAGE NoImplicitPrelude, CPP, OverloadedStrings, ScopedTypeVariables #-}
-- | Description : Argument parsing and basic messaging loop, using Haskell
-- | Description : Argument parsing and basic messaging loop, using Haskell
-- Chans to communicate with the ZeroMQ sockets.
-- Chans to communicate with the ZeroMQ sockets.
module
Main
where
module
Main
where
-- Prelude imports.
-- Prelude imports.
import
ClassyPrelude
hiding
(
liftIO
)
import
ClassyPrelude
hiding
(
l
ast
,
l
iftIO
)
import
Prelude
(
last
,
read
)
import
Prelude
(
last
,
read
)
-- Standard library imports.
-- Standard library imports.
...
@@ -45,7 +45,7 @@ main :: IO ()
...
@@ -45,7 +45,7 @@ main :: IO ()
main
=
do
main
=
do
args
<-
parseFlags
<$>
map
unpack
<$>
getArgs
args
<-
parseFlags
<$>
map
unpack
<$>
getArgs
case
args
of
case
args
of
Left
errorMessage
->
Left
errorMessage
->
hPutStrLn
stderr
errorMessage
hPutStrLn
stderr
errorMessage
Right
args
->
Right
args
->
ihaskell
args
ihaskell
args
...
@@ -57,9 +57,9 @@ chooseIPython (_:xs) = chooseIPython xs
...
@@ -57,9 +57,9 @@ chooseIPython (_:xs) = chooseIPython xs
ihaskell
::
Args
->
IO
()
ihaskell
::
Args
->
IO
()
-- If no mode is specified, print help text.
-- If no mode is specified, print help text.
ihaskell
(
Args
(
ShowHelp
help
)
_
)
=
ihaskell
(
Args
(
ShowHelp
help
)
_
)
=
putStrLn
$
pack
help
putStrLn
$
pack
help
ihaskell
(
Args
Console
flags
)
=
showingHelp
Console
flags
$
do
ihaskell
(
Args
Console
flags
)
=
showingHelp
Console
flags
$
do
ipython
<-
chooseIPython
flags
ipython
<-
chooseIPython
flags
setupIPython
ipython
setupIPython
ipython
...
@@ -113,7 +113,7 @@ showingHelp mode flags act =
...
@@ -113,7 +113,7 @@ showingHelp mode flags act =
putStrLn
$
pack
$
help
mode
putStrLn
$
pack
$
help
mode
Nothing
->
Nothing
->
act
act
-- | Parse initialization information from the flags.
-- | Parse initialization information from the flags.
initInfo
::
FrontendType
->
[
Argument
]
->
IO
InitInfo
initInfo
::
FrontendType
->
[
Argument
]
->
IO
InitInfo
initInfo
front
[]
=
return
InitInfo
{
extensions
=
[]
,
initCells
=
[]
,
initDir
=
"."
,
frontend
=
front
}
initInfo
front
[]
=
return
InitInfo
{
extensions
=
[]
,
initCells
=
[]
,
initDir
=
"."
,
frontend
=
front
}
...
@@ -155,11 +155,11 @@ runKernel profileSrc initInfo = do
...
@@ -155,11 +155,11 @@ runKernel profileSrc initInfo = do
-- reason (completely unknown to me).
-- reason (completely unknown to me).
liftIO
ignoreCtrlC
liftIO
ignoreCtrlC
-- Initialize the context by evaluating everything we got from the
-- Initialize the context by evaluating everything we got from the
-- command line flags. This includes enabling some extensions and also
-- command line flags. This includes enabling some extensions and also
-- running some code.
-- running some code.
let
extLines
=
map
(
":extension "
++
)
$
extensions
initInfo
let
extLines
=
map
(
":extension "
++
)
$
extensions
initInfo
noPublish
_
=
return
()
noPublish
_
=
return
()
evaluator
line
=
do
evaluator
line
=
do
-- Create a new state each time.
-- Create a new state each time.
stateVar
<-
liftIO
initialKernelState
stateVar
<-
liftIO
initialKernelState
...
@@ -178,7 +178,7 @@ runKernel profileSrc initInfo = do
...
@@ -178,7 +178,7 @@ runKernel profileSrc initInfo = do
-- Create the reply, possibly modifying kernel state.
-- Create the reply, possibly modifying kernel state.
oldState
<-
liftIO
$
takeMVar
state
oldState
<-
liftIO
$
takeMVar
state
(
newState
,
reply
)
<-
replyTo
interface
request
replyHeader
oldState
(
newState
,
reply
)
<-
replyTo
interface
request
replyHeader
oldState
liftIO
$
putMVar
state
newState
liftIO
$
putMVar
state
newState
-- Write the reply to the reply channel.
-- Write the reply to the reply channel.
...
@@ -217,7 +217,7 @@ createReplyHeader parent = do
...
@@ -217,7 +217,7 @@ createReplyHeader parent = do
msgType
=
repType
msgType
=
repType
}
}
-- | Compute a reply to a message.
-- | Compute a reply to a message.
replyTo
::
ZeroMQInterface
->
Message
->
MessageHeader
->
KernelState
->
Interpreter
(
KernelState
,
Message
)
replyTo
::
ZeroMQInterface
->
Message
->
MessageHeader
->
KernelState
->
Interpreter
(
KernelState
,
Message
)
-- Reply to kernel info requests with a kernel info reply. No computation
-- Reply to kernel info requests with a kernel info reply. No computation
...
@@ -333,9 +333,9 @@ replyTo _ ObjectInfoRequest{objectName=oname} replyHeader state = do
...
@@ -333,9 +333,9 @@ replyTo _ ObjectInfoRequest{objectName=oname} replyHeader state = do
docs
<-
info
$
Chars
.
unpack
oname
docs
<-
info
$
Chars
.
unpack
oname
let
reply
=
ObjectInfoReply
{
let
reply
=
ObjectInfoReply
{
header
=
replyHeader
,
header
=
replyHeader
,
objectName
=
oname
,
objectName
=
oname
,
objectFound
=
strip
docs
/=
""
,
objectFound
=
strip
docs
/=
""
,
objectTypeString
=
Chars
.
pack
docs
,
objectTypeString
=
Chars
.
pack
docs
,
objectDocString
=
Chars
.
pack
docs
objectDocString
=
Chars
.
pack
docs
}
}
return
(
state
,
reply
)
return
(
state
,
reply
)
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