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
692860f6
Commit
692860f6
authored
Oct 20, 2013
by
Andrew Gibiansky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
haddocks?
parent
70c4e806
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
15 deletions
+41
-15
IHaskell.cabal
IHaskell.cabal
+0
-3
Evaluate.hs
IHaskell/Eval/Evaluate.hs
+31
-9
Parser.hs
IHaskell/Message/Parser.hs
+2
-0
UUID.hs
IHaskell/Message/UUID.hs
+3
-2
Types.hs
IHaskell/Types.hs
+3
-1
Main.hs
Main.hs
+2
-0
No files found.
IHaskell.cabal
View file @
692860f6
...
...
@@ -75,6 +75,3 @@ executable IHaskell
knob ==0.1.*,
directory ==1.2.*,
deepseq ==1.3.*
IHaskell/Eval/Evaluate.hs
View file @
692860f6
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
-- | This module exports all functions used for evaluation of IHaskell input.
module
IHaskell.Eval.Evaluate
(
interpret
,
evaluate
,
Interpreter
,
liftIO
...
...
@@ -15,7 +17,6 @@ import Language.Haskell.Exts.Syntax hiding (Name)
import
InteractiveEval
import
HscTypes
import
Name
import
GhcMonad
(
liftIO
)
import
GHC
hiding
(
Stmt
)
import
GHC.Paths
...
...
@@ -32,6 +33,7 @@ type Interpreter = Ghc
data
Command
=
Directive
String
|
Import
String
|
Declaration
String
|
Statement
String
|
ParseError
LineNumber
ColumnNumber
String
deriving
Show
...
...
@@ -47,6 +49,8 @@ globalImports =
directiveChar
::
Char
directiveChar
=
':'
-- | Run an interpreting action. This is effectively runGhc with
-- initialization and importing.
interpret
::
Interpreter
a
->
IO
a
interpret
action
=
runGhc
(
Just
libdir
)
$
do
-- Set the dynamic session flags
...
...
@@ -81,13 +85,26 @@ parseCommands :: String -- ^ Code containing commands.
->
[
Command
]
-- ^ Commands contained in code string.
parseCommands
code
=
concatMap
makeCommands
pieces
where
pieces
=
groupBy
((
==
)
`
on
`
isDirective
)
$
lines
code
-- Group the text into different pieces.
-- Pieces can be declarations, statement lists, or directives.
-- We distinguish declarations from statements via the first line an
-- indentation, and directives based on the first character.
samePiece
x
y
=
not
(
isDirective
x
||
isDirective
y
)
&&
indentLevel
x
<=
indentLevel
y
indentLevel
(
' '
:
str
)
=
1
+
indentLevel
str
indentLevel
_
=
0
::
Int
pieces
=
groupBy
samePiece
$
lines
code
makeCommands
lines
|
any
isDirective
lines
=
map
createDirective
lines
|
any
isDeclaration
lines
=
case
parseDecl
$
unlines
lines
of
ParseOk
declaration
->
[
Declaration
$
prettyPrint
declaration
]
ParseFailed
srcLoc
errMsg
->
[
ParseError
(
srcLine
srcLoc
)
(
srcColumn
srcLoc
)
errMsg
]
|
otherwise
=
case
parseStmts
$
unlines
lines
of
case
parseStmts
$
trace
(
show
$
unlines
lines
)
$
unlines
lines
of
Left
(
srcLine
,
srcColumn
,
errMsg
)
->
[
ParseError
srcLine
srcColumn
errMsg
]
Right
stmts
->
map
(
Statement
.
prettyPrint
)
$
init
stmts
isDeclaration
line
=
any
(`
isInfixOf
`
line
)
[
"type"
,
"newtype"
,
"data"
]
isDirective
line
=
startswith
[
directiveChar
]
stripped
||
startswith
"import"
stripped
where
stripped
=
strip
line
createDirective
line
=
...
...
@@ -113,7 +130,7 @@ evalCommand (Statement stmt) = do
(
printed
,
result
)
<-
capturedStatement
stmt
case
result
of
RunOk
names
->
--concat <$> mapM showName names
RunOk
_
->
return
[
Display
PlainText
printed
]
RunException
exception
->
do
write
$
"RunException: "
++
show
exception
...
...
@@ -126,8 +143,17 @@ evalCommand (Statement stmt) = do
write
$
concat
[
"Break: "
,
show
exception
,
"
\n
from statement:
\n
"
,
stmt
]
return
[
Display
MimeHtml
$
makeError
$
show
exception
]
evalCommand
(
Declaration
decl
)
=
do
write
$
"Declaration: "
++
decl
ghandle
handler
$
runDecls
decl
>>
return
[]
where
handler
::
SomeException
->
Interpreter
[
DisplayData
]
handler
exception
=
do
write
$
concat
[
"Break: "
,
show
exception
,
"
\n
from declaration:
\n
"
,
decl
]
return
[
Display
MimeHtml
$
makeError
$
show
exception
]
evalCommand
(
ParseError
line
col
err
)
=
return
[
Display
MimeHtml
$
makeError
$
printf
"
error
Error (line %d, column %d): %s"
line
col
err
]
return
[
Display
MimeHtml
$
makeError
$
printf
"Error (line %d, column %d): %s"
line
col
err
]
capturedStatement
::
String
->
Interpreter
(
String
,
RunResult
)
capturedStatement
stmt
=
...
...
@@ -155,10 +181,6 @@ capturedStatement stmt =
return
(
printedOutput
,
result
)
showName
::
Name
->
Interpreter
[
DisplayData
]
showName
_
=
return
[
Display
PlainText
"Hello!"
]
parseStmts
::
String
->
Either
(
LineNumber
,
ColumnNumber
,
String
)
[
Stmt
]
parseStmts
code
=
case
parseResult
of
...
...
IHaskell/Message/Parser.hs
View file @
692860f6
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
-- | This module is responsible for converting from low-level ByteStrings
-- | obtained from the 0MQ sockets into Messages. The only exposed function is
-- | `parseMessage`, which should only be used in the low-level 0MQ interface.
...
...
IHaskell/Message/UUID.hs
View file @
692860f6
...
...
@@ -22,8 +22,9 @@ data UUID = UUID String deriving Eq
instance
Show
UUID
where
show
(
UUID
s
)
=
s
-- | Generate an infinite list of random UUIDs.
randoms
::
Int
->
IO
[
UUID
]
-- | Generate a list of random UUIDs.
randoms
::
Int
-- ^ Number of UUIDs to generate.
->
IO
[
UUID
]
randoms
n
=
replicateM
n
random
-- | Generate a single random UUID.
...
...
IHaskell/Types.hs
View file @
692860f6
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module
IHaskell.Types
(
Profile
(
..
),
Message
(
..
),
...
...
@@ -139,7 +141,7 @@ data Message
getUserExpressions
::
[
ByteString
]
-- ^ Unused.
}
-- | A reply to an execute request.
-- | A reply to an execute request.
|
ExecuteReply
{
header
::
MessageHeader
,
status
::
ExecuteReplyStatus
,
-- ^ The status of the output.
...
...
Main.hs
View file @
692860f6
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
import
ClassyPrelude
hiding
(
liftIO
)
import
Control.Concurrent.Chan
import
Data.Aeson
...
...
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