Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
teiwa
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
teiwa
Commits
a3f12ffd
Commit
a3f12ffd
authored
3 years ago
by
Alice Brenon
Browse files
Options
Downloads
Patches
Plain Diff
Factorize stack-editing functions in Annotation
parent
97c90f5e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/Text/TEIWA/Annotation.hs
+10
-12
10 additions, 12 deletions
lib/Text/TEIWA/Annotation.hs
with
10 additions
and
12 deletions
lib/Text/TEIWA/Annotation.hs
+
10
−
12
View file @
a3f12ffd
...
...
@@ -32,12 +32,12 @@ data Annotation = Token Text | Annotations [Node] deriving Show
attribute
::
(
Text
,
Text
)
->
Text
attribute
(
k
,
v
)
=
Text
.
concat
[
" "
,
k
,
"=
\"
"
,
v
,
"
\"
"
]
openTag
::
Tag
->
String
openTag
(
Tag
{
name
,
annotated
})
=
openTag
::
Tag
->
Editor
m
openTag
(
Tag
{
name
,
annotated
})
=
tell
.
Text
.
pack
$
printf
"<%s%s>"
name
.
Text
.
concat
$
attribute
<$>
annotated
closeTag
::
Tag
->
String
closeTag
=
printf
"</%s>"
.
name
closeTag
::
Tag
->
Editor
m
closeTag
=
tell
.
Text
.
pack
$
printf
"</%s>"
.
name
data
EditorState
=
EditorState
{
input
::
Text
...
...
@@ -45,15 +45,13 @@ data EditorState = EditorState {
}
type
Editor
m
=
RWST
Config
Text
EditorState
m
()
enter
::
Monad
m
=>
Tag
->
Editor
m
enter
t
=
modify
$
\
editorState
->
editorState
{
tagStack
=
t
:
tagStack
editorState
}
editStack
::
MonadState
EditorState
m
=>
([
Tag
]
->
(
a
,
[
Tag
]))
->
m
a
editStack
f
=
state
$
\
editorState
->
let
(
output
,
newTagStack
)
=
f
$
tagStack
editorState
in
(
output
,
editorState
{
tagStack
=
newTagStack
})
flushTags
::
Monad
m
=>
Editor
m
flushTags
=
do
tags
<-
gets
tagStack
modify
$
\
editorState
->
editorState
{
tagStack
=
[]
}
mapM_
(
tell
.
Text
.
pack
.
openTag
)
tags
flushTags
=
editStack
(
\
stack
->
(
stack
,
[]
))
>>=
mapM_
openTag
forget
::
Monad
m
=>
Int64
->
Editor
m
forget
count
=
modify
$
...
...
@@ -61,7 +59,7 @@ forget count = modify $
annotateNode
::
MonadError
Error
m
=>
Node
->
Editor
m
annotateNode
(
Node
{
tag
,
inside
})
=
e
nter
tag
*>
annotator
inside
*>
tell
(
Text
.
pack
$
closeTag
tag
)
e
ditStack
(
\
s
->
(
()
,
tag
:
s
))
*>
annotator
inside
*>
closeTag
tag
annotator
::
MonadError
Error
m
=>
Annotation
->
Editor
m
annotator
(
Token
t
)
=
gets
(
Text
.
breakOn
t
.
input
)
>>=
wrap
...
...
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