Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
InvisiXML
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alice Brenon
InvisiXML
Commits
d9a49db9
Commit
d9a49db9
authored
4 years ago
by
Alice Brenon
Browse files
Options
Downloads
Patches
Plain Diff
Wire the --pristine option downto the parser
parent
7cd6a081
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/Main.hs
+4
-2
4 additions, 2 deletions
app/Main.hs
lib/Text/InvisiXML.hs
+15
-8
15 additions, 8 deletions
lib/Text/InvisiXML.hs
with
19 additions
and
10 deletions
app/Main.hs
+
4
−
2
View file @
d9a49db9
...
...
@@ -6,7 +6,7 @@ import Control.Monad.Except (runExceptT)
import
Data.Maybe
(
fromMaybe
)
import
Data.Text
(
Text
)
import
qualified
Data.Text.IO
as
Text
(
getContents
,
readFile
,
writeFile
)
import
Text.InvisiXML
(
InvisiXML
(
..
),
parse
)
import
Text.InvisiXML
as
Parser
(
InvisiXML
(
..
),
ParsingConfig
(
..
),
parse
)
import
Text.XML.Light.Serializer
(
encode
)
import
System.FilePath
((
<.>
),
dropExtension
)
import
System.Exit
(
die
)
...
...
@@ -22,8 +22,10 @@ endPoints (Command {input = FileInput f, outputPrefix}) =
run
::
Command
->
IO
()
run
command
=
do
(
source
,
prefix
)
<-
endPoints
command
source
>>=
runExceptT
.
parse
>>=
either
(
fail
.
show
)
(
create
prefix
)
source
>>=
runExceptT
.
parse
parsingConfig
>>=
either
(
fail
.
show
)
(
create
prefix
)
where
parsingConfig
=
ParsingConfig
{
Parser
.
pristine
=
CLI
.
pristine
command
}
create
prefix
(
InvisiXML
{
text
,
structure
})
=
do
Text
.
writeFile
(
prefix
<.>
"txt"
)
text
writeFile
(
prefix
<.>
"ixml"
)
$
encode
structure
...
...
This diff is collapsed.
Click to expand it.
lib/Text/InvisiXML.hs
+
15
−
8
View file @
d9a49db9
...
...
@@ -2,13 +2,14 @@
{-# LANGUAGE FlexibleContexts #-}
module
Text.InvisiXML
(
InvisiXML
(
..
)
,
ParsingConfig
(
..
)
,
Structure
(
..
)
,
merge
,
parse
)
where
import
Control.Monad.Except
(
MonadError
(
..
))
import
Control.Monad.
State
(
State
T
(
..
),
exec
StateT
,
gets
,
modify
,
state
)
import
Control.Monad.
RWS
(
RWS
T
(
..
),
exec
RWST
,
asks
,
gets
,
modify
,
state
)
import
Data.Char
(
isSpace
)
import
Data.List
(
uncons
)
import
Data.PositionTree
as
PositionTree
(
...
...
@@ -80,6 +81,10 @@ data ParsingState = ParsingState {
,
subStructure
::
Structure
}
data
ParsingConfig
=
ParsingConfig
{
pristine
::
Bool
}
openStream
::
[
Token
]
->
ParsingState
openStream
input
=
ParsingState
{
input
...
...
@@ -89,7 +94,7 @@ openStream input = ParsingState {
,
subStructure
=
Structure
empty
}
type
Parser
=
StateT
ParsingState
type
Parser
=
RWST
ParsingConfig
()
ParsingState
pop
::
Monad
m
=>
Parser
m
(
Maybe
Token
)
pop
=
gets
(
uncons
.
input
)
>>=
updateState
...
...
@@ -99,9 +104,9 @@ pop = gets (uncons . input) >>= updateState
state
$
\
parsingState
->
(
Just
t
,
parsingState
{
input
})
appendText
::
Monad
m
=>
String
->
Parser
m
()
appendText
s
=
modify
append
appendText
s
=
asks
(
toText
.
pristine
)
>>=
modify
.
append
where
t
=
Text
.
pack
$
unindent
s
t
oText
b
=
Text
.
pack
$
(
if
b
then
id
else
unindent
)
s
unindent
(
'
\n
'
:
s'
)
=
'
\n
'
:
(
unindent
$
dropWhile
isSpace
s'
)
{-
case dropWhile isSpace s' of
...
...
@@ -110,7 +115,7 @@ appendText s = modify append
-}
unindent
(
c
:
s'
)
=
c
:
(
unindent
s'
)
unindent
[]
=
[]
append
parsingState
append
t
parsingState
|
Text
.
null
t
=
parsingState
|
otherwise
=
parsingState
{
at
=
offset
t
$
at
parsingState
...
...
@@ -143,10 +148,12 @@ checkout actual = gets context >>= compareWith actual
|
tag
tO0
/=
tag
tO1
=
throwError
$
Mismatch
{
open
=
tO0
,
close
=
tO1
}
compareWith
_
_
=
return
()
parse
::
(
XmlSource
s
,
MonadError
XMLError
m
)
=>
s
->
m
InvisiXML
parse
=
fmap
collectState
.
execStateT
fillStructure
.
openStream
.
tokens
parse
::
(
XmlSource
s
,
MonadError
XMLError
m
)
=>
ParsingConfig
->
s
->
m
InvisiXML
parse
config
=
fmap
collectState
.
execRWST
fillStructure
config
.
openStream
.
tokens
where
collectState
(
ParsingState
{
stack
,
subStructure
})
=
InvisiXML
{
collectState
(
ParsingState
{
stack
,
subStructure
}
,
_
)
=
InvisiXML
{
structure
=
subStructure
,
text
=
Text
.
concat
$
reverse
stack
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment