Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
clean-and-itasks
clean-sapl
Commits
27c75fa4
Verified
Commit
27c75fa4
authored
Jun 19, 2018
by
Camil Staps
Browse files
Split up parsing and code generation to allow for cyclic dependencies in constructors
parent
ef7e977e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/saplcg.icl
View file @
27c75fa4
...
...
@@ -7,7 +7,7 @@ import StdString
import
StdTuple
import
Data
.
Error
from
Data
.
Func
import
$,
seqSt
from
Data
.
Func
import
$,
mapSt
,
seqSt
from
Data
.
Map
import
fromList
,
newMap
import
Data
.
Maybe
import
System
.
CommandLine
...
...
@@ -60,10 +60,13 @@ Start w
|
isNothing
opts
.
output
=
error
usage
"No output file given"
w
|
isNothing
opts
.
output
&&
isJust
opts
.
beautify
=
error
Nothing
"Cannot use beautifier when outputting to stdout"
w
#
(
files
,(
pst
,
w
))
=
mapSt
(
parseFile
opts
)
opts
.
sapl_files
(
defaultParserState
,
w
)
|
any
isNothing
files
=
error
Nothing
"Parsing failed"
w
#
(
ok
,
out
,
w
)
=
case
opts
.
output
of
Nothing
->
let
(
f
,
w`
)
=
stdio
w
in
(
True
,
f
,
w`
)
Just
o
->
fopen
o
FWriteText
w
#
(
out
,_,
w
)
=
seqSt
(
handleFile
opts
)
opts
.
sapl_
files
(
out
,
defaultParserState
,
w
)
#
(
out
,_,
w
)
=
seqSt
(
genCode
opts
)
[
f
\\
Just
f
<-
files
]
(
out
,
pst
,
w
)
#
(_,
w
)
=
fclose
out
w
#
w
=
case
opts
.
beautify
of
...
...
@@ -110,11 +113,19 @@ error usage s w
#
w
=
setReturnCode
1
w
=
w
handl
eFile
::
!
Options
!
FilePath
!*(!
*
File
,!
ParserState
,!*
World
)
->
*(!
*
File
,
!
ParserState
,!*
World
)
handl
eFile
opts
fp
(
out
,
pst
,
w
)
pars
eFile
::
!
Options
!
FilePath
!*(!
ParserState
,!*
World
)
->
*(!
Maybe
String
,
!*(
!
ParserState
,!*
World
)
)
pars
eFile
opts
fp
(
pst
,
w
)
#!
(
f
,
w
)
=
readFile
fp
w
|
isError
f
=
(
out
,
pst
,
error
Nothing
(
fromError
f
<+
" "
+++
fp
)
w
)
#!
genResult
=
generateJS
cleanFlavour
opts
.
trampoline
(
fromOk
f
)
(
Just
pst
)
|
isError
f
=
(
Nothing
,
(
pst
,
error
Nothing
(
fromError
f
<+
" "
+++
fp
)
w
))
#!
f
=
fromOk
f
#!
parseRes
=
parse
(
tokensWithPositions
f
)
|
isError
parseRes
=
(
Nothing
,
(
pst
,
error
Nothing
(
fp
+++
": "
<+
fromError
parseRes
)
w
))
#!
(_,
pst`
)
=
fromOk
parseRes
=
(
Just
f
,
(
mergeParserStates
pst`
(
Just
pst
),
w
))
genCode
::
!
Options
!
String
!*(!*
File
,!
ParserState
,!*
World
)
->
*(!*
File
,!
ParserState
,!*
World
)
genCode
opts
sapl
(
out
,
pst
,
w
)
#!
genResult
=
generateJS
cleanFlavour
opts
.
trampoline
sapl
(
Just
pst
)
|
isError
genResult
=
(
out
,
pst
,
error
Nothing
(
fromError
genResult
)
w
)
#!
(
res
,
pst
)
=
fromOk
genResult
#!
(
mbError
,
out
)
=
intoFile
res
out
...
...
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