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