Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
why3
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
81
Issues
81
List
Boards
Labels
Milestones
Merge Requests
8
Merge Requests
8
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Why3
why3
Commits
54d6b937
Commit
54d6b937
authored
Jun 05, 2018
by
Guillaume Melquiond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify extract_ocaml_code.
parent
f091aad9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
64 deletions
+23
-64
Makefile.in
Makefile.in
+5
-5
doc/extract_ocaml_code.ml
doc/extract_ocaml_code.ml
+18
-59
No files found.
Makefile.in
View file @
54d6b937
...
@@ -1873,19 +1873,19 @@ doc/extract_ocaml_code: doc/extract_ocaml_code.ml
...
@@ -1873,19 +1873,19 @@ doc/extract_ocaml_code: doc/extract_ocaml_code.ml
$(OCAMLC)
str.cma
-o
$@
$<
$(OCAMLC)
str.cma
-o
$@
$<
doc/logic__%.ml
:
examples/use_api/logic.ml doc/extract_ocaml_code
doc/logic__%.ml
:
examples/use_api/logic.ml doc/extract_ocaml_code
doc/extract_ocaml_code
examples/use_api/logic.ml
$*
doc
doc/extract_ocaml_code
$*
<
$<
>
$@
doc/whyconf__%.ml
:
src/driver/whyconf.ml doc/extract_ocaml_code
doc/whyconf__%.ml
:
src/driver/whyconf.ml doc/extract_ocaml_code
doc/extract_ocaml_code
src/driver/whyconf.ml
$*
doc
doc/extract_ocaml_code
$*
<
$<
>
$@
doc/call_provers__%.ml
:
src/driver/call_provers.ml doc/extract_ocaml_code
doc/call_provers__%.ml
:
src/driver/call_provers.ml doc/extract_ocaml_code
doc/extract_ocaml_code
src/driver/call_provers.ml
$*
doc
doc/extract_ocaml_code
$*
<
$<
>
$@
doc/mlw_tree__%.ml
:
examples/use_api/mlw_tree.ml doc/extract_ocaml_code
doc/mlw_tree__%.ml
:
examples/use_api/mlw_tree.ml doc/extract_ocaml_code
doc/extract_ocaml_code
examples/use_api/mlw_tree.ml
$*
doc
doc/extract_ocaml_code
$*
<
$<
>
$@
doc/transform__%.ml
:
examples/use_api/transform.ml doc/extract_ocaml_code
doc/transform__%.ml
:
examples/use_api/transform.ml doc/extract_ocaml_code
doc/extract_ocaml_code
examples/use_api/transform.ml
$*
doc
doc/extract_ocaml_code
$*
<
$<
>
$@
OCAMLCODE_LOGIC
=
opening printformula declarepropvars declarepropatoms
\
OCAMLCODE_LOGIC
=
opening printformula declarepropvars declarepropatoms
\
buildtask printtask buildtask2
\
buildtask printtask buildtask2
\
...
...
doc/extract_ocaml_code.ml
View file @
54d6b937
(*
(*
Simple utility to extract a portion of
a file
Simple utility to extract a portion of
the standard input
extract_ocaml_code <
path/file.ext> <id> <dir
>
extract_ocaml_code <
id
>
extracts the part of path/file.ext between lines containing anchors BEGIN{id} and END{id}
outputs the part of the standard input between anchors BEGIN{id} and END{id}
and puts the result in the file dir/file_id.ext
*)
*)
open
Format
let
section
=
match
Sys
.
argv
with
let
filename
,
section
,
output_dir
=
|
[
|
_
;
section
|
]
->
section
if
Array
.
length
Sys
.
argv
=
4
then
|
_
->
Sys
.
argv
.
(
1
)
,
Sys
.
argv
.
(
2
)
,
Sys
.
argv
.
(
3
)
Format
.
eprintf
"Usage: %s <id>@
\n
\
else
Output the part of the standard input between anchors BEGIN{id} and END{id}@."
begin
Sys
.
argv
.
(
0
);
eprintf
"Usage: %s <path/file.ext> <id> <dir>@
\n
\
exit
2
Extract the part of path/file.ext between lines containing anchors BEGIN{id} and END{id}@
\n
\
and puts the result in the file dir/file_id.ext@."
Sys
.
argv
.
(
0
);
exit
2
end
let
ch_in
=
try
open_in
filename
with
exn
->
eprintf
"Cannot open %s for reading: %s@."
filename
(
Printexc
.
to_string
exn
);
exit
1
let
basename
=
Filename
.
basename
filename
let
ext
=
Filename
.
extension
basename
let
basename
=
Filename
.
remove_extension
basename
let
begin_re
=
Str
.
regexp_string
(
"BEGIN{"
^
section
^
"}"
)
let
begin_re
=
Str
.
regexp_string
(
"BEGIN{"
^
section
^
"}"
)
let
search_begin
()
=
let
search_begin
()
=
try
try
while
true
do
while
true
do
let
l
=
input_line
ch_in
in
let
l
=
read_line
()
in
try
try
let
_
=
Str
.
search_forward
begin_re
l
0
in
raise
Exit
let
_
=
Str
.
search_forward
begin_re
l
0
in
raise
Exit
with
Not_found
->
()
with
Not_found
->
()
done
done
with
with
End_of_file
->
|
End_of_file
->
eprintf
"Error: opening anchor BEGIN{%s} not found in file %s@."
section
filename
;
Format
.
eprintf
"Error: opening anchor BEGIN{%s} not found@."
section
;
close_in
ch_in
;
exit
1
exit
1
|
Exit
->
()
|
Exit
->
()
let
end_re
=
Str
.
regexp_string
(
"END{"
^
section
^
"}"
)
let
end_re
=
Str
.
regexp_string
(
"END{"
^
section
^
"}"
)
let
file_out
=
Filename
.
concat
output_dir
(
basename
^
"__"
^
section
^
ext
)
let
ch_out
=
try
open_out
file_out
with
exn
->
eprintf
"Cannot open %s for writing: %s@."
file_out
(
Printexc
.
to_string
exn
);
close_in
ch_in
;
exit
1
let
search_end
()
=
let
search_end
()
=
try
try
while
true
do
while
true
do
let
l
=
input_line
ch_in
in
let
l
=
read_line
()
in
try
try
let
_
=
Str
.
search_forward
end_re
l
0
in
raise
Exit
let
_
=
Str
.
search_forward
end_re
l
0
in
raise
Exit
with
Not_found
->
with
Not_found
->
output_string
ch_out
l
;
print_string
l
;
output_char
ch_out
'\n'
print_char
'\n'
done
done
with
with
Exit
->
()
End_of_file
->
eprintf
"Error: ending anchor END{%s} not found in file %s@."
section
filename
;
close_in
ch_in
;
close_out
ch_out
;
exit
1
|
Exit
->
close_in
ch_in
;
close_out
ch_out
let
()
=
let
()
=
search_begin
()
;
search_end
()
search_begin
()
;
search_end
()
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