Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clean-sapl
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
clean-and-itasks
clean-sapl
Commits
ef7e977e
Verified
Commit
ef7e977e
authored
Jun 19, 2018
by
Camil Staps
🚀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add beautify option
parent
f7ebebe1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
2 deletions
+23
-2
src/saplcg.icl
src/saplcg.icl
+23
-2
No files found.
src/saplcg.icl
View file @
ef7e977e
module
saplcg
import
StdBool
import
StdFile
import
StdList
import
StdString
...
...
@@ -13,6 +14,7 @@ import System.CommandLine
import
System
.
File
import
System
.
FilePath
import
System
.
Options
import
System
.
Process
import
Text
import
Sapl
.
Target
.
CleanFlavour
...
...
@@ -22,6 +24,7 @@ import Sapl.Target.JS.CodeGeneratorJS
{
sapl_files
::
![
FilePath
]
,
trampoline
::
!
Bool
,
output
::
!
Maybe
FilePath
,
beautify
::
!
Maybe
FilePath
}
defaultOptions
::
Options
...
...
@@ -29,6 +32,7 @@ defaultOptions =
{
sapl_files
=
[]
,
trampoline
=
False
,
output
=
Nothing
,
beautify
=
Nothing
}
defaultParserState
::
ParserState
...
...
@@ -46,19 +50,31 @@ defaultParserState =
Start
w
#
([
prog
:
opts
],
w
)
=
getCommandLine
w
#
noUsage
=
Nothing
#
usage
=
Just
(
"Usage: "
+++
prog
+++
" [-
-trampoline
] -o OUTPUT INPUT [INPUT..]"
)
#
usage
=
Just
(
"Usage: "
+++
prog
+++
" [-
t|--trampoline] [-b|--beautify PROG
] -o OUTPUT INPUT [INPUT..]"
)
#
opts
=
parseOptions
optionDescription
opts
defaultOptions
|
isError
opts
=
error
noUsage
(
join
"
\n
"
$
fromError
opts
)
w
#
opts
=
fromOk
opts
|
isEmpty
opts
.
sapl_files
=
error
usage
"No sapl files given"
w
|
isNothing
opts
.
output
=
error
usage
"No output file given"
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
#
(
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
)
#
(_,
w
)
=
fclose
out
w
#
w
=
case
opts
.
beautify
of
Nothing
->
w
Just
beautify
#
(
err
,
w
)
=
callProcess
beautify
[
out
,
"-o"
,
out
]
Nothing
w
with
out
=
fromJust
opts
.
output
|
isError
err
->
error
Nothing
(
"Error while beautifying: "
+++
snd
(
fromError
err
))
w
->
w
=
w
where
optionDescription
::
Option
Options
...
...
@@ -67,6 +83,11 @@ where
"--trampoline"
(\
opts
->
Ok
{
opts
&
trampoline
=
True
})
"Turn on trampoline code"
,
Shorthand
"-b"
"--beautify"
$
Option
"--beautify"
(\
b
opts
->
Ok
{
opts
&
beautify
=
Just
b
})
"PROG"
"Name or path of a JavaScript beautifier"
,
Shorthand
"-o"
"--output"
$
Option
"--output"
(\
f
opts
->
Ok
{
opts
&
output
=
Just
f
})
...
...
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