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
a73ac76b
Commit
a73ac76b
authored
Dec 14, 2013
by
Andrew Gibiansky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added handling of repeated empty lines
parent
c73ad0e6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
24 deletions
+75
-24
Hspec.hs
Hspec.hs
+13
-0
IHaskell.cabal
IHaskell.cabal
+15
-0
Evaluate.hs
IHaskell/Eval/Evaluate.hs
+46
-23
Parser.hs
IHaskell/Eval/Parser.hs
+1
-1
No files found.
Hspec.hs
View file @
a73ac76b
...
...
@@ -144,6 +144,9 @@ layoutChunkerTests = describe "Layout Chunk" $ do
it
"chunks 'a
\\
n string
\\
nextra'"
$
layoutChunks
"a
\n
string
\n
extra"
`
shouldBe
`
[
"a
\n
string"
,
"extra"
]
it
"chunks strings with too many lines"
$
layoutChunks
"a
\n\n
string"
`
shouldBe
`
[
"a"
,
"string"
]
moduleNameTests
=
describe
"Get Module Name"
$
do
it
"parses simple module names"
$
"module A where
\n
x = 3"
`
named
`
[
"A"
]
...
...
@@ -275,3 +278,13 @@ parseStringTests = describe "Parser" $ do
parses
"data X = 3"
`
like
`
[
ParseError
(
Loc
1
10
)
"Illegal literal in type (use -XDataKinds to enable): 3"
]
it
"parses statements after imports"
$
do
parses
"import X
\n
print 3"
`
like
`
[
Import
"import X"
,
Expression
"print 3"
]
parses
"import X
\n\n\n
print 3"
`
like
`
[
Import
"import X"
,
Expression
"print 3"
]
IHaskell.cabal
View file @
a73ac76b
...
...
@@ -42,6 +42,17 @@ build-type: Custom
-- Constraint on the version of Cabal needed to build this package.
cabal-version: >=1.8
extra-source-files:
config/custom.js
config/ipython_config.py
config/ipython_console_config.py
config/ipython_notebook_config.py
config/ipython_qtconsole_config.py
deps/codecell.js
deps/tooltip.js
build-parser.sh
images/ihaskell-logo.png
library
build-depends: base ==4.6.*,
hspec,
...
...
@@ -91,6 +102,10 @@ executable IHaskell
IHaskell.Types
IHaskell.ZeroMQ
IHaskell.Display
IHaskell.Config
IHaskell.GHC.HaskellParser
extensions: DoAndIfThenElse
...
...
IHaskell/Eval/Evaluate.hs
View file @
a73ac76b
...
...
@@ -95,8 +95,7 @@ type Interpreter = Ghc
globalImports
::
[
String
]
globalImports
=
[
"import IHaskell.Types"
,
"import IHaskell.Display"
[
"import IHaskell.Display"
,
"import Control.Applicative ((<$>))"
,
"import GHC.IO.Handle (hDuplicateTo, hDuplicate)"
,
"import System.IO"
...
...
@@ -213,8 +212,8 @@ evalCommand (Module contents) = wrapExecution $ do
writeFile
(
fpFromString
$
directory
++
filename
)
contents
-- Clear old modules of this name
let
mod
ule
Name
=
intercalate
"."
namePieces
removeTarget
$
TargetModule
$
mkModuleName
mod
ule
Name
let
modName
=
intercalate
"."
namePieces
removeTarget
$
TargetModule
$
mkModuleName
modName
removeTarget
$
TargetFile
filename
Nothing
-- Set to use object code for fast running times, as that is the only
...
...
@@ -226,26 +225,50 @@ evalCommand (Module contents) = wrapExecution $ do
-- Remember which modules we've loaded before.
importedModules
<-
getContext
-- Create a new target
target
<-
guessTarget
moduleName
Nothing
addTarget
target
result
<-
load
LoadAllTargets
-- Reset the context, since loading things screws it up.
initializeItVariable
-- Add imports
importDecl
<-
parseImportDecl
$
"import "
++
moduleName
let
implicitImport
=
importDecl
{
ideclImplicit
=
True
}
setContext
$
IIDecl
implicitImport
:
importedModules
-- Switch back to interpreted mode.
flags
<-
getSessionDynFlags
setSessionDynFlags
flags
{
hscTarget
=
HscInterpreted
}
let
-- Get the dot-delimited pieces of hte module name.
moduleNameOf
::
InteractiveImport
->
[
String
]
moduleNameOf
(
IIDecl
decl
)
=
split
"."
.
moduleNameString
.
unLoc
.
ideclName
$
decl
moduleNameOf
(
IIModule
imp
)
=
split
"."
.
moduleNameString
$
imp
-- Return whether this module prevents the loading of the one we're
-- trying to load. If a module B exist, we cannot load A.B. All
-- modules must have unique last names (where A.B has last name B).
-- However, we *can* just reload a module.
preventsLoading
mod
=
let
pieces
=
moduleNameOf
mod
in
last
namePieces
==
last
pieces
&&
namePieces
/=
pieces
-- If we've loaded anything with the same last name, we can't use this.
-- Otherwise, GHC tries to load the original *.hs fails and then fails.
case
find
preventsLoading
importedModules
of
-- If something prevents loading this module, return an error.
Just
previous
->
let
prevLoaded
=
intercalate
"."
(
moduleNameOf
previous
)
in
return
$
displayError
$
printf
"Can't load module %s because already loaded %s"
modName
prevLoaded
-- Since nothing prevents loading the module, compile and load it.
Nothing
->
do
-- Create a new target
target
<-
guessTarget
modName
Nothing
addTarget
target
result
<-
load
LoadAllTargets
-- Reset the context, since loading things screws it up.
initializeItVariable
-- Add imports
importDecl
<-
parseImportDecl
$
"import "
++
modName
let
implicitImport
=
importDecl
{
ideclImplicit
=
True
}
setContext
$
IIDecl
implicitImport
:
importedModules
-- Switch back to interpreted mode.
flags
<-
getSessionDynFlags
setSessionDynFlags
flags
{
hscTarget
=
HscInterpreted
}
case
result
of
Succeeded
->
return
[]
Failed
->
return
$
displayError
$
"Failed to load module "
++
module
Name
case
result
of
Succeeded
->
return
[]
Failed
->
return
$
displayError
$
"Failed to load module "
++
mod
Name
evalCommand
(
Directive
SetExtension
exts
)
=
wrapExecution
$
do
results
<-
mapM
setExtension
(
words
exts
)
...
...
IHaskell/Eval/Parser.hs
View file @
a73ac76b
...
...
@@ -307,7 +307,7 @@ splitAtLoc line col string =
-- beyond the indentation of the first line. This parses Haskell layout
-- rules properly, and allows using multiline expressions via indentation.
layoutChunks
::
String
->
[
String
]
layoutChunks
string
=
layoutLines
(
lines
string
)
layoutChunks
string
=
filter
(
not
.
null
.
strip
)
$
layoutLines
$
lines
string
where
layoutLines
::
[
String
]
->
[
String
]
-- Empty string case. If there's no input, output is empty.
...
...
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