Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
99bdcc1b
Commit
99bdcc1b
authored
Apr 05, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'check-language' of
https://github.com/mosesn/capnproto
Supports choosing output languages on the command line.
parents
7a00f5c2
718b5c05
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
7 deletions
+35
-7
Main.hs
compiler/src/Main.hs
+35
-7
No files found.
compiler/src/Main.hs
View file @
99bdcc1b
...
...
@@ -24,6 +24,7 @@
module
Main
(
main
)
where
import
System.Environment
import
System.Console.GetOpt
import
Compiler
import
Util
(
delimit
)
import
Text.Parsec.Pos
...
...
@@ -31,27 +32,54 @@ import Text.Parsec.Error
import
Text.Printf
(
printf
)
import
qualified
Data.List
as
List
import
qualified
Data.ByteString.Lazy.Char8
as
LZ
import
Data.List
import
Data.Maybe
import
Semantics
import
CxxGenerator
main
::
IO
()
main
=
do
files
<-
getArgs
mapM_
handleFile
files
let
options
=
[
Option
[
'o'
]
[
"output"
]
(
ReqArg
id
"FILE"
)
"Where to send the files"
]
args
<-
getArgs
let
tup
=
getOpt
RequireOrder
options
args
let
(
optionResults
,
files
,
_
)
=
tup
let
langDirs
=
catMaybes
(
map
splitAtEquals
optionResults
)
handleFilesLangs
(
generatorFnsFor
langDirs
)
files
handleFile
filename
=
do
splitAtEquals
::
String
->
Maybe
(
String
,
String
)
splitAtEquals
str
=
do
holder
<-
(
elemIndex
'='
str
)
Just
((
splitAt
holder
str
))
handleFilesLangs
eithers
files
=
mapM_
(
\
x
->
handleFiles
x
files
)
eithers
handleFiles
(
Right
fn
)
files
=
mapM_
(
handleFile
fn
)
files
handleFiles
(
Left
str
)
_
=
putStrLn
str
handleFile
generateCode
filename
=
do
text
<-
readFile
filename
case
parseAndCompileFile
filename
text
of
Active
desc
[]
->
do
print
desc
header
<-
generateCxxHeader
desc
LZ
.
writeFile
(
filename
++
".h"
)
header
source
<-
generateCxxSource
desc
LZ
.
writeFile
(
filename
++
".c++"
)
source
generateCode
desc
filename
Active
_
e
->
mapM_
printError
(
List
.
sortBy
compareErrors
e
)
Failed
e
->
mapM_
printError
(
List
.
sortBy
compareErrors
e
)
generatorFnsFor
::
[(
String
,
String
)]
->
[
Either
String
(
FileDesc
->
FilePath
->
(
IO
()
))]
generatorFnsFor
langDirs
=
do
map
(
\
langDir
->
generatorFnFor
(
fst
langDir
)
(
tail
(
snd
langDir
)))
langDirs
generatorFnFor
::
String
->
String
->
Either
String
(
FileDesc
->
FilePath
->
(
IO
()
))
generatorFnFor
lang
dir
=
case
lang
of
"c++"
->
Right
(
\
desc
filename
->
do
header
<-
generateCxxHeader
desc
LZ
.
writeFile
(
dir
++
"/"
++
filename
++
".h"
)
header
source
<-
generateCxxSource
desc
LZ
.
writeFile
(
dir
++
"/"
++
filename
++
".c++"
)
source
)
_
->
Left
"Only c++ is supported for now"
compareErrors
a
b
=
compare
(
errorPos
a
)
(
errorPos
b
)
-- TODO: This is a fairly hacky way to make showErrorMessages' output not suck. We could do better
...
...
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