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
322c7725
Commit
322c7725
authored
11 years ago
by
Andrew Gibiansky
Committed by
Adam Vogt
11 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixing tests and line numbering of code blocks
parent
4ebe3434
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
28 deletions
+85
-28
Hspec.hs
Hspec.hs
+22
-7
Parser.hs
IHaskell/Eval/Parser.hs
+18
-12
Untitled0.ipynb
Untitled0.ipynb
+42
-0
profile.tar
profile/profile.tar
+0
-0
custom.css
profile/static/custom/custom.css
+3
-9
No files found.
Hspec.hs
View file @
322c7725
...
...
@@ -202,16 +202,31 @@ parserTests = do
layoutChunkerTests
=
describe
"Layout Chunk"
$
do
it
"chunks 'a string'"
$
layoutChunks
"a string"
`
shouldBe
`
[
"a string"
]
map
unloc
(
layoutChunks
"a string"
)
`
shouldBe
`
[
"a string"
]
it
"chunks 'a
\\
nstring'"
$
layoutChunks
"a
\n
string"
`
shouldBe
`
[
"a
\n
string"
]
it
"chunks 'a
\\
n
string'"
$
map
unloc
(
layoutChunks
"a
\n
string"
)
`
shouldBe
`
[
"a
\n
string"
]
it
"chunks 'a
\\
n string
\\
nextra'"
$
layoutChunks
"a
\n
string
\n
extra"
`
shouldBe
`
[
"a
\n
string"
,
"extra"
]
map
unloc
(
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"
]
map
unloc
(
layoutChunks
"a
\n\n
string"
)
`
shouldBe
`
[
"a"
,
"string"
]
it
"parses multiple exprs"
$
do
let
text
=
[
hereLit
|
first
second
third
fourth
|]
layoutChunks
text
`
shouldBe
`
[
Located
2
"first"
,
Located
4
"second"
,
Located
5
"third"
,
Located
7
"fourth"
]
moduleNameTests
=
describe
"Get Module Name"
$
do
it
"parses simple module names"
$
...
...
@@ -379,6 +394,6 @@ parseStringTests = describe "Parser" $ do
first
second
|]
>>=
(`
shouldBe
`
[
Located
1
(
Expression
"first"
),
Located
2
(
Expression
"second"
)])
|]
>>=
(`
shouldBe
`
[
Located
2
(
Expression
"first"
),
Located
4
(
Expression
"second"
)])
This diff is collapsed.
Click to expand it.
IHaskell/Eval/Parser.hs
View file @
322c7725
...
...
@@ -51,6 +51,8 @@ data CodeBlock
-- | Store locations along with a value.
data
Located
a
=
Located
LineNumber
a
deriving
(
Eq
,
Show
)
instance
Functor
Located
where
fmap
f
(
Located
line
a
)
=
Located
line
$
f
a
-- | Directive types. Each directive is associated with a string in the
-- directive code block.
...
...
@@ -83,7 +85,7 @@ parseString codeString = do
Failure
{}
->
-- Split input into chunks based on indentation.
let
chunks
=
layoutChunks
$
dropComments
codeString
in
joinFunctions
<$>
processChunks
1
[]
chunks
joinFunctions
<$>
processChunks
[]
chunks
where
parseChunk
::
GhcMonad
m
=>
String
->
LineNumber
->
m
(
Located
CodeBlock
)
parseChunk
chunk
line
=
Located
line
<$>
...
...
@@ -91,16 +93,16 @@ parseString codeString = do
then
return
$
parseDirective
chunk
line
else
parseCodeChunk
chunk
line
processChunks
::
GhcMonad
m
=>
LineNumber
->
[
Located
CodeBlock
]
->
[
String
]
->
m
[
Located
CodeBlock
]
processChunks
line
accum
remaining
=
processChunks
::
GhcMonad
m
=>
[
Located
CodeBlock
]
->
[
Located
String
]
->
m
[
Located
CodeBlock
]
processChunks
accum
remaining
=
case
remaining
of
-- If we have no more remaining lines, return the accumulated results.
[]
->
return
$
reverse
accum
-- If we have more remaining, parse the current chunk and recurse.
chunk
:
remaining
->
do
Located
line
chunk
:
remaining
->
do
block
<-
parseChunk
chunk
line
processChunks
(
line
+
nlines
chunk
)
(
block
:
accum
)
remaining
processChunks
(
block
:
accum
)
remaining
-- Test wither a given chunk is a directive.
isDirective
::
String
->
Bool
...
...
@@ -248,25 +250,29 @@ parseDirective _ _ = error "Directive must start with colon!"
-- A chunk is a line and all lines immediately following that are indented
-- 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
=
filter
(
not
.
null
)
$
map
strip
$
layoutLines
$
lines
string
layoutChunks
::
String
->
[
Located
String
]
layoutChunks
=
go
1
where
layoutLines
::
[
String
]
->
[
String
]
go
::
LineNumber
->
String
->
[
Located
String
]
go
line
=
filter
(
not
.
null
.
unloc
)
.
map
(
fmap
strip
)
.
layoutLines
line
.
lines
layoutLines
::
LineNumber
->
[
String
]
->
[
Located
String
]
-- Empty string case. If there's no input, output is empty.
layoutLines
[]
=
[]
layoutLines
_
[]
=
[]
-- Use the indent of the first line to find the end of the first block.
layoutLines
(
firstLine
:
rest
)
=
layoutLines
lineIdx
all
@
(
firstLine
:
rest
)
=
let
firstIndent
=
indentLevel
firstLine
blockEnded
line
=
indentLevel
line
<=
firstIndent
in
case
findIndex
blockEnded
rest
of
-- If the first block doesn't end, return the whole string, since
-- that just means the block takes up the entire string.
Nothing
->
[
string
]
Nothing
->
[
Located
lineIdx
$
intercalate
"
\n
"
all
]
-- We found the end of the block. Split this bit out and recurse.
Just
idx
->
joinLines
(
firstLine
:
take
idx
rest
)
:
layoutChunks
(
joinLines
$
drop
idx
rest
)
let
(
before
,
after
)
=
splitAt
idx
rest
in
Located
lineIdx
(
joinLines
$
firstLine
:
before
)
:
go
(
lineIdx
+
idx
+
1
)
(
joinLines
after
)
-- Compute indent level of a string as number of leading spaces.
indentLevel
::
String
->
Int
...
...
This diff is collapsed.
Click to expand it.
Untitled0.ipynb
0 → 100644
View file @
322c7725
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import \n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"no Python documentation found for 'PATH'\n",
"\n"
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
profile/profile.tar
View file @
322c7725
No preview for this file type
This diff is collapsed.
Click to expand it.
profile/static/custom/custom.css
View file @
322c7725
/*
Custom IHaskell CSS.
*/
table
.suggestion-table
{
border
:
0px
;
text-align
:
center
;
}
tr
.suggestion-row
{
border
:
0px
;
}
td
.suggestion-cell
{
border
:
0px
;
.highlight-code
{
white-space
:
pre
;
font-family
:
monospace
;
}
.suggestion-warning
{
font-weight
:
bold
;
...
...
This diff is collapsed.
Click to expand it.
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