tangled
alpha
login
or
join now
jon.recoil.org
/
js_top_worker
0
fork
atom
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
Fix parser
jon.recoil.org
9 months ago
463956e8
36e69b8b
+82
-47
2 changed files
expand all
collapse all
unified
split
lib
toplexer.mll
test
libtest
parse_test.ml
+5
-8
lib/toplexer.mll
···
21
| "# " {
22
true, List.rev acc
23
}
0
0
0
24
| _ as c {
25
output_line_legacy c acc lexbuf
26
}
···
29
}
30
31
and output_line_legacy c acc = parse
32
-
| ((_ # '\n')* as line) "\n# " {
33
-
true, List.rev ((String.make 1 c ^ line) :: acc)
34
-
}
35
-
| ((_ # '\n')* as line) "\n" (_ as c') {
36
-
output_line_legacy c' ((String.make 1 c ^ line) :: acc) lexbuf
37
-
}
38
-
| ((_ # '\n')* as line) "\n" eof {
39
-
false, List.rev ("" :: (String.make 1 c ^ line) :: acc)
40
}
41
| (_ # '\n')* as line eof {
42
false, List.rev ((String.make 1 c ^ line) :: acc)
···
21
| "# " {
22
true, List.rev acc
23
}
24
+
| '\n' {
25
+
line_prefix (""::acc) lexbuf
26
+
}
27
| _ as c {
28
output_line_legacy c acc lexbuf
29
}
···
32
}
33
34
and output_line_legacy c acc = parse
35
+
| ((_ # '\n')* as line) "\n" {
36
+
line_prefix ((String.make 1 c ^ line) :: acc) lexbuf
0
0
0
0
0
0
37
}
38
| (_ # '\n')* as line eof {
39
false, List.rev ((String.make 1 c ^ line) :: acc)
+77
-39
test/libtest/parse_test.ml
···
9
let check phrase =
10
let output = snd (Js_top_worker.Impl.mangle_toplevel true phrase []) in
11
print_endline "input:";
12
-
print_endline phrase;
13
print_endline "output:";
14
-
print_endline output;
15
let output_mapped = String.map (fun c -> if c = ' ' then '.' else c) output in
16
print_endline "output mapped:";
17
-
print_endline output_mapped
18
19
let%expect_test _ =
20
check "# foo;; junk\n bar\n# baz;;\n moo\n# unterminated;; foo\n";
21
-
[%expect{|
22
input:
23
-
# foo;; junk
24
bar
25
# baz;;
26
moo
27
# unterminated;; foo
28
-
29
output:
30
-
foo;;
31
32
baz;;
33
34
unterminated;;
35
-
36
output mapped:
37
-
..foo;;.....
38
.....
39
..baz;;
40
.....
41
-
..unterminated;;.... |}]
0
0
42
43
let%expect_test _ =
44
check "# 1+2;;\n- 3 : int\n \n";
45
-
[%expect{|
46
input:
47
-
# 1+2;;
48
- 3 : int
49
50
-
51
output:
52
-
1+2;;
53
-
54
55
0
56
output mapped:
57
-
..1+2;;
58
.........
59
-
.. |}]
0
0
60
61
let%expect_test _ =
62
check "# 1+2;;";
63
-
[%expect{|
64
input:
65
-
# 1+2;;
66
output:
67
-
1+2;;
68
output mapped:
69
-
..1+2;; |}]
0
70
71
let%expect_test _ =
72
check "# 1+2;;\nx\n";
73
-
[%expect{|
74
input:
75
-
# 1+2;;
76
x
77
-
78
output:
79
-
1+2;;
80
81
-
82
output mapped:
83
-
..1+2;;
84
-
. |}]
0
0
85
86
let%expect_test _ =
87
check "# let ;;\n foo";
88
-
[%expect "
89
-
fallback parser
90
-
Got phrase
91
-
input:
92
-
# let ;;
93
-
foo
94
-
output:
95
-
let ;;
0
0
0
0
0
96
97
-
output mapped:
98
-
..let.;;
99
-
....."]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
···
9
let check phrase =
10
let output = snd (Js_top_worker.Impl.mangle_toplevel true phrase []) in
11
print_endline "input:";
12
+
Printf.printf "{|%s|}\n" phrase;
13
print_endline "output:";
14
+
Printf.printf "{|%s|}\n" output;
15
let output_mapped = String.map (fun c -> if c = ' ' then '.' else c) output in
16
print_endline "output mapped:";
17
+
Printf.printf "{|%s|}\n" output_mapped
18
19
let%expect_test _ =
20
check "# foo;; junk\n bar\n# baz;;\n moo\n# unterminated;; foo\n";
21
+
[%expect{xxx|
22
input:
23
+
{|# foo;; junk
24
bar
25
# baz;;
26
moo
27
# unterminated;; foo
28
+
|}
29
output:
30
+
{| foo;;
31
32
baz;;
33
34
unterminated;;
35
+
|}
36
output mapped:
37
+
{|..foo;;.....
38
.....
39
..baz;;
40
.....
41
+
..unterminated;;....
42
+
|}
43
+
|xxx}]
44
45
let%expect_test _ =
46
check "# 1+2;;\n- 3 : int\n \n";
47
+
[%expect{xxx|
48
input:
49
+
{|# 1+2;;
50
- 3 : int
51
52
+
|}
53
output:
54
+
{| 1+2;;
0
55
56
57
+
|}
58
output mapped:
59
+
{|..1+2;;
60
.........
61
+
..
62
+
|}
63
+
|xxx}]
64
65
let%expect_test _ =
66
check "# 1+2;;";
67
+
[%expect{xxx|
68
input:
69
+
{|# 1+2;;|}
70
output:
71
+
{| 1+2;;|}
72
output mapped:
73
+
{|..1+2;;|}
74
+
|xxx}]
75
76
let%expect_test _ =
77
check "# 1+2;;\nx\n";
78
+
[%expect{xxx|
79
input:
80
+
{|# 1+2;;
81
x
82
+
|}
83
output:
84
+
{| 1+2;;
85
86
+
|}
87
output mapped:
88
+
{|..1+2;;
89
+
.
90
+
|}
91
+
|xxx}]
92
93
let%expect_test _ =
94
check "# let ;;\n foo";
95
+
[%expect "
96
+
fallback parser
97
+
Got phrase
98
+
input:
99
+
{|# let ;;
100
+
foo|}
101
+
output:
102
+
{| let ;;
103
+
|}
104
+
output mapped:
105
+
{|..let.;;
106
+
.....|}
107
+
"]
108
109
+
110
+
let%expect_test _ =
111
+
check "# let x=1;;\n foo\n\n# let y=2;;\n bar\n\n";
112
+
[%expect "
113
+
input:
114
+
{|# let x=1;;
115
+
foo
116
+
117
+
# let y=2;;
118
+
bar
119
+
120
+
|}
121
+
output:
122
+
{| let x=1;;
123
+
124
+
125
+
let y=2;;
126
+
127
+
128
+
|}
129
+
output mapped:
130
+
{|..let.x=1;;
131
+
.....
132
+
133
+
..let.y=2;;
134
+
.....
135
+
136
+
|}
137
+
"]