From ad56165e1a57b489a90ae28ff999bd7b45c9464d Mon Sep 17 00:00:00 2001 From: Iwan Date: Sun, 5 Jul 2020 13:39:16 +0200 Subject: [PATCH] Close binary expressions breadcrumbs correct. Fixes https://github.com/BuckleScript/syntax/issues/16 --- src/napkin_core.ml | 1 + .../__snapshots__/parse.spec.js.snap | 64 +++++++++++++++++++ tests/parsing/errors/structure/gh16A.ns | 7 ++ tests/parsing/errors/structure/gh16B.ns | 21 ++++++ 4 files changed, 93 insertions(+) create mode 100644 tests/parsing/errors/structure/gh16A.ns create mode 100644 tests/parsing/errors/structure/gh16B.ns diff --git a/src/napkin_core.ml b/src/napkin_core.ml index b7aaa479..0bc89a29 100644 --- a/src/napkin_core.ml +++ b/src/napkin_core.ml @@ -2068,6 +2068,7 @@ and parseBinaryExpr ?(context=OrdinaryExpr) ?a p prec = (makeInfixOperator p token startPos endPos) [Nolabel, a; Nolabel, b] in + Parser.eatBreadcrumb p; loop expr end in diff --git a/tests/parsing/errors/structure/__snapshots__/parse.spec.js.snap b/tests/parsing/errors/structure/__snapshots__/parse.spec.js.snap index ea0f07b4..fd7cdea0 100644 --- a/tests/parsing/errors/structure/__snapshots__/parse.spec.js.snap +++ b/tests/parsing/errors/structure/__snapshots__/parse.spec.js.snap @@ -37,6 +37,70 @@ consecutive statements on a line must be separated by ';' or a newline +========================================================" +`; + +exports[`gh16A.ns 1`] = ` +"=====Parsetree========================================== +module C = struct module T = (Fun)(struct ;;foo (a + c) (b + d) end) end +;;Js.log \\"test\\" +=====Errors============================================= + +File \\"/syntax/tests/parsing/errors/structure/gh16A.ns\\", line 6, characters 0-1: + + +4 │ }) +5 │ } +6 │ ) +7 │ Js.log(\\"test\\"); // Is omitted from the compiled JS + +I'm not sure what to parse here when looking at \\")\\". + + + +========================================================" +`; + +exports[`gh16B.ns 1`] = ` +"=====Parsetree========================================== +open Ws +let wss = Server.make { port = 82 } +let address = wss |. Server.address +let log msg = Js.log ({|> Server: |} ^ msg) +;;log + (((((({|Running on: |} ^ address.address) ^ {|:|}) ^ + (address.port |. string_of_int)) + ^ {| (|}) + ^ address.family) + ^ {|)|}) +module ClientSet = + struct + module T = + (Belt.Id.MakeComparable)(struct + type nonrec t = Client.t + let cmp a b = + ((compare (a |. Client.getUniqueId) + (b |. Client.getUniqueId)) + [@ns.braces ]) + end) + let empty = Belt.Set.make ~id:(((module T))[@ns.namedArgLoc ]) + end +;;Js.log \\"test\\" +=====Errors============================================= + +File \\"/syntax/tests/parsing/errors/structure/gh16B.ns\\", line 19, characters 1-2: + + +17 │ +18 │ +19 │ })))))))))))))))))))))))))))))); // this \\")\\" here, this can even be \\"))))))))))))))))\\" and should error +20 │ +21 │ Js.log(\\"test\\") // should not be omitted + +I'm not sure what to parse here when looking at \\")\\". + + + ========================================================" `; diff --git a/tests/parsing/errors/structure/gh16A.ns b/tests/parsing/errors/structure/gh16A.ns new file mode 100644 index 00000000..a395fdc0 --- /dev/null +++ b/tests/parsing/errors/structure/gh16A.ns @@ -0,0 +1,7 @@ +module C = { + module T = Fun({ + foo(a + c, b + d) + }) +} +) +Js.log("test"); // Is omitted from the compiled JS diff --git a/tests/parsing/errors/structure/gh16B.ns b/tests/parsing/errors/structure/gh16B.ns new file mode 100644 index 00000000..90b872e4 --- /dev/null +++ b/tests/parsing/errors/structure/gh16B.ns @@ -0,0 +1,21 @@ +open Ws + +let wss = Server.make({port: 82}) +let address = wss->Server.address +let log = msg => Js.log(`> Server: ${msg}`) +log(`Running on: ${address.address}:${address.port->string_of_int} (${address.family})`) + +module ClientSet = { + module T = Belt.Id.MakeComparable({ + type t = Client.t; + let cmp = (a, b) => { + compare(a->Client.getUniqueId, b->Client.getUniqueId); + }; + }); + + let empty = Belt.Set.make(~id=module (T)); + + +})))))))))))))))))))))))))))))); // this ")" here, this can even be "))))))))))))))))" and should error + +Js.log("test") // should not be omitted