Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jsexplain
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
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
Verified Software
jsexplain
Commits
6d7e9c19
Commit
6d7e9c19
authored
9 years ago
by
charguer
Browse files
Options
Downloads
Patches
Plain Diff
tokens_by_line
parent
e52ae5d2
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
generator/lineof.ml
+14
-29
14 additions, 29 deletions
generator/lineof.ml
with
14 additions
and
29 deletions
generator/lineof.ml
+
14
−
29
View file @
6d7e9c19
...
...
@@ -63,19 +63,6 @@ module XFile = struct
close_in
f
;
XList
.
rev_not_rec
!
lines
(** Read the content of a file as a list of lines;
returns an empty list if no such file exists *)
let
get_lines_or_empty
file
=
try
get_lines
file
with
FileNotFound
_
->
[]
(** Read the content of a file as a string, terminated with a newline;
raise FileNotFound if no such file exists *)
let
get_contents
file
=
let
lines
=
get_lines
file
in
(
String
.
concat
"
\n
"
lines
)
^
"
\n
"
end
...
...
@@ -114,15 +101,15 @@ type tokens = (string * tokens_start * tokens_stop) list ref
let
tokens
:
tokens
=
ref
[]
let
gather_tokens
basename
input
=
let
gather_tokens
basename
input
_lines
=
let
tokens_start
=
Hashtbl
.
create
50
in
let
tokens_stop
=
Hashtbl
.
create
50
in
(* start tokens *)
begin
~~
List
.
iteri
input_lines
(
fun
line
input
->
let
r
=
Str
.
regexp
"#<
\\
([0-9]*
\\
)#"
in
let
i
=
ref
0
in
let
mk_pos
()
=
{
pos_line
=
!
i
;
pos_col
=
0
}
in
begin
try
let
mk_pos
()
=
{
pos_line
=
line
;
pos_col
=
!
i
}
in
try
while
true
do
(* Printf.printf "search from %d\n" !i; *)
let
j
=
Str
.
search_forward
r
input
!
i
in
...
...
@@ -132,15 +119,14 @@ let gather_tokens basename input =
(* Printf.printf "matched key: %s\n" key; *)
Hashtbl
.
add
tokens_start
(
int_of_string
key
)
pos
done
;
with
|
Not_found
->
()
end
;
end
;
with
Not_found
->
()
);
(* end tokens *)
begin
~~
List
.
iteri
input_lines
(
fun
line
input
->
let
r
=
Str
.
regexp
"#
\\
([0-9]*
\\
)>#"
in
let
i
=
ref
0
in
let
mk_pos
()
=
{
pos_line
=
!
i
;
pos_col
=
0
}
in
begin
try
let
mk_pos
()
=
{
pos_line
=
line
;
pos_col
=
!
i
}
in
try
while
true
do
(* Printf.printf "search from %d\n" !i; *)
let
j
=
Str
.
search_forward
r
input
!
i
in
...
...
@@ -150,9 +136,8 @@ let gather_tokens basename input =
(* Printf.printf "matched key: %s\n" key; *)
Hashtbl
.
add
tokens_stop
(
int_of_string
key
)
pos
done
;
with
|
Not_found
->
()
end
;
end
;
with
Not_found
->
()
);
(* final *)
tokens
:=
(
basename
,
tokens_start
,
tokens_stop
)
::!
tokens
...
...
@@ -165,7 +150,7 @@ let generate_lineof_function output_file : string =
Printf
.
sprintf
"case %d: return {start: %s, stop: %s};"
key
(
aux_pos
pos_start
)
(
aux_pos
pos_stop
)
in
let
aux_file
(
basename
,
tokens_start
,
tokens_stop
)
=
let
filename
=
basename
^
"js"
in
let
filename
=
basename
^
"
.
js"
in
let
keys
=
hashtbl_keys
tokens_start
in
let
skeycases
=
String
.
concat
"@,"
(
~~
List
.
map
keys
(
fun
key
->
let
pos_start
=
try
Hashtbl
.
find
tokens_start
key
...
...
@@ -230,8 +215,8 @@ let _ =
if
not
(
Filename
.
check_suffix
filename
".token.js"
)
then
failwith
"Input file must be of the form *.token.js"
;
let
basename
=
Filename
.
chop_suffix
(
Filename
.
basename
filename
)
".token.js"
in
let
input
=
XFile
.
get_
content
s
filename
in
gather_tokens
basename
input
let
input
_lines
=
XFile
.
get_
line
s
filename
in
gather_tokens
basename
input
_lines
);
(*---------------------------------------------------*)
...
...
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