this repo has no description

Fix parser

+82 -47
+5 -8
lib/toplexer.mll
··· 21 21 | "# " { 22 22 true, List.rev acc 23 23 } 24 + | '\n' { 25 + line_prefix (""::acc) lexbuf 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 - | ((_ # '\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) 35 + | ((_ # '\n')* as line) "\n" { 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 - print_endline phrase; 12 + Printf.printf "{|%s|}\n" phrase; 13 13 print_endline "output:"; 14 - print_endline output; 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 - print_endline output_mapped 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 - [%expect{| 21 + [%expect{xxx| 22 22 input: 23 - # foo;; junk 23 + {|# foo;; junk 24 24 bar 25 25 # baz;; 26 26 moo 27 27 # unterminated;; foo 28 - 28 + |} 29 29 output: 30 - foo;; 30 + {| foo;; 31 31 32 32 baz;; 33 33 34 34 unterminated;; 35 - 35 + |} 36 36 output mapped: 37 - ..foo;;..... 37 + {|..foo;;..... 38 38 ..... 39 39 ..baz;; 40 40 ..... 41 - ..unterminated;;.... |}] 41 + ..unterminated;;.... 42 + |} 43 + |xxx}] 42 44 43 45 let%expect_test _ = 44 46 check "# 1+2;;\n- 3 : int\n \n"; 45 - [%expect{| 47 + [%expect{xxx| 46 48 input: 47 - # 1+2;; 49 + {|# 1+2;; 48 50 - 3 : int 49 51 50 - 52 + |} 51 53 output: 52 - 1+2;; 53 - 54 + {| 1+2;; 54 55 55 56 57 + |} 56 58 output mapped: 57 - ..1+2;; 59 + {|..1+2;; 58 60 ......... 59 - .. |}] 61 + .. 62 + |} 63 + |xxx}] 60 64 61 65 let%expect_test _ = 62 66 check "# 1+2;;"; 63 - [%expect{| 67 + [%expect{xxx| 64 68 input: 65 - # 1+2;; 69 + {|# 1+2;;|} 66 70 output: 67 - 1+2;; 71 + {| 1+2;;|} 68 72 output mapped: 69 - ..1+2;; |}] 73 + {|..1+2;;|} 74 + |xxx}] 70 75 71 76 let%expect_test _ = 72 77 check "# 1+2;;\nx\n"; 73 - [%expect{| 78 + [%expect{xxx| 74 79 input: 75 - # 1+2;; 80 + {|# 1+2;; 76 81 x 77 - 82 + |} 78 83 output: 79 - 1+2;; 84 + {| 1+2;; 80 85 81 - 86 + |} 82 87 output mapped: 83 - ..1+2;; 84 - . |}] 88 + {|..1+2;; 89 + . 90 + |} 91 + |xxx}] 85 92 86 93 let%expect_test _ = 87 94 check "# let ;;\n foo"; 88 - [%expect " 89 - fallback parser 90 - Got phrase 91 - input: 92 - # let ;; 93 - foo 94 - output: 95 - let ;; 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 + "] 96 108 97 - output mapped: 98 - ..let.;; 99 - ....."] 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 + "]