From d5592a9e0236e6832af2f8c95e610340adb7345d Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Jun 2022 07:58:46 +0200 Subject: [PATCH 01/12] At tokenization time, turn doc comment into @ns.doc. --- src/res_core.ml | 4 + src/res_parser.ml | 141 ++++++++++-------- src/res_token.ml | 2 + .../expected/templateEof.res.txt | 2 +- tests/parsing/other/docComments.res | 2 + .../other/expected/docComments.res.txt | 1 + .../comments/expected/multiline.res.txt | 7 +- .../comments/expected/structure4.res.txt | 38 ++--- .../expected/trailingComments.res.txt | 39 ++--- .../other/expected/StaticReactTypes.res.txt | 98 ++---------- 10 files changed, 131 insertions(+), 203 deletions(-) create mode 100644 tests/parsing/other/docComments.res create mode 100644 tests/parsing/other/expected/docComments.res.txt diff --git a/src/res_core.ml b/src/res_core.ml index afa86098..ed8f35ec 100644 --- a/src/res_core.ml +++ b/src/res_core.ml @@ -6389,6 +6389,10 @@ and parseAttribute p = let attrId = parseAttributeId ~startPos p in let payload = parsePayload p in Some(attrId, payload) + | DocComment (loc, s) -> + Parser.next p; + Some ({txt="ns.doc"; loc}, + PStr [Ast_helper.Str.eval ~loc (Ast_helper.Exp.constant ~loc (Pconst_string(s, None)) )]) | _ -> None and parseAttributes p = diff --git a/src/res_parser.ml b/src/res_parser.ml index fb5e1b76..0853ce51 100644 --- a/src/res_parser.ml +++ b/src/res_parser.ml @@ -26,105 +26,118 @@ type t = { let err ?startPos ?endPos p error = match p.regions with - | {contents = Report} as region::_ -> + | ({contents = Report} as region) :: _ -> let d = Diagnostics.make - ~startPos:(match startPos with | Some pos -> pos | None -> p.startPos) - ~endPos:(match endPos with | Some pos -> pos | None -> p.endPos) + ~startPos: + (match startPos with + | Some pos -> pos + | None -> p.startPos) + ~endPos: + (match endPos with + | Some pos -> pos + | None -> p.endPos) error - in ( - p.diagnostics <- d::p.diagnostics; - region := Silent - ) + in + p.diagnostics <- d :: p.diagnostics; + region := Silent | _ -> () -let beginRegion p = - p.regions <- ref Report :: p.regions +let beginRegion p = p.regions <- ref Report :: p.regions let endRegion p = match p.regions with | [] -> () - | _::rest -> p.regions <- rest + | _ :: rest -> p.regions <- rest + +let docCommentToAttributeToken comment = + let open Ast_helper in + let txt = Comment.txt comment in + let loc = Comment.loc comment in + Token.DocComment (loc, txt) (* Advance to the next non-comment token and store any encountered comment -* in the parser's state. Every comment contains the end position of its -* previous token to facilite comment interleaving *) + * in the parser's state. Every comment contains the end position of its + * previous token to facilite comment interleaving *) let rec next ?prevEndPos p = - if p.token = Eof then assert false; - let prevEndPos = match prevEndPos with Some pos -> pos | None -> p.endPos in - let (startPos, endPos, token) = Scanner.scan p.scanner in - match token with - | Comment c -> - Comment.setPrevTokEndPos c p.endPos; - p.comments <- c::p.comments; - p.prevEndPos <- p.endPos; - p.endPos <- endPos; - next ~prevEndPos p - | _ -> - p.token <- token; - (* p.prevEndPos <- prevEndPos; *) - p.prevEndPos <- prevEndPos; - p.startPos <- startPos; - p.endPos <- endPos - -let nextUnsafe p = - if p.token <> Eof then next p + if p.token = Eof then assert false; + let prevEndPos = + match prevEndPos with + | Some pos -> pos + | None -> p.endPos + in + let startPos, endPos, token = Scanner.scan p.scanner in + match token with + | Comment c -> + if Comment.isDocComment c then ( + p.token <- docCommentToAttributeToken c; + p.prevEndPos <- prevEndPos; + p.startPos <- startPos; + p.endPos <- endPos) + else ( + Comment.setPrevTokEndPos c p.endPos; + p.comments <- c :: p.comments; + p.prevEndPos <- p.endPos; + p.endPos <- endPos; + next ~prevEndPos p) + | _ -> + p.token <- token; + p.prevEndPos <- prevEndPos; + p.startPos <- startPos; + p.endPos <- endPos + +let nextUnsafe p = if p.token <> Eof then next p let nextTemplateLiteralToken p = - let (startPos, endPos, token) = Scanner.scanTemplateLiteralToken p.scanner in + let startPos, endPos, token = Scanner.scanTemplateLiteralToken p.scanner in p.token <- token; p.prevEndPos <- p.endPos; p.startPos <- startPos; p.endPos <- endPos let checkProgress ~prevEndPos ~result p = - if p.endPos == prevEndPos - then None - else Some result + if p.endPos == prevEndPos then None else Some result -let make ?(mode=ParseForTypeChecker) src filename = +let make ?(mode = ParseForTypeChecker) src filename = let scanner = Scanner.make ~filename src in - let parserState = { - mode; - scanner; - token = Token.Semicolon; - startPos = Lexing.dummy_pos; - prevEndPos = Lexing.dummy_pos; - endPos = Lexing.dummy_pos; - breadcrumbs = []; - errors = []; - diagnostics = []; - comments = []; - regions = [ref Report]; - } in - parserState.scanner.err <- (fun ~startPos ~endPos error -> - let diagnostic = Diagnostics.make - ~startPos - ~endPos - error - in - parserState.diagnostics <- diagnostic::parserState.diagnostics - ); + let parserState = + { + mode; + scanner; + token = Token.Semicolon; + startPos = Lexing.dummy_pos; + prevEndPos = Lexing.dummy_pos; + endPos = Lexing.dummy_pos; + breadcrumbs = []; + errors = []; + diagnostics = []; + comments = []; + regions = [ref Report]; + } + in + parserState.scanner.err <- + (fun ~startPos ~endPos error -> + let diagnostic = Diagnostics.make ~startPos ~endPos error in + parserState.diagnostics <- diagnostic :: parserState.diagnostics); next parserState; parserState let leaveBreadcrumb p circumstance = let crumb = (circumstance, p.startPos) in - p.breadcrumbs <- crumb::p.breadcrumbs + p.breadcrumbs <- crumb :: p.breadcrumbs let eatBreadcrumb p = match p.breadcrumbs with | [] -> () - | _::crumbs -> p.breadcrumbs <- crumbs + | _ :: crumbs -> p.breadcrumbs <- crumbs let optional p token = if p.token = token then - let () = next p in true - else - false + let () = next p in + true + else false let expect ?grammar token p = - if p.token = token then - next p + if p.token = token then next p else let error = Diagnostics.expected ?grammar p.prevEndPos token in err ~startPos:p.prevEndPos p error diff --git a/src/res_token.ml b/src/res_token.ml index b901276a..814e078e 100644 --- a/src/res_token.ml +++ b/src/res_token.ml @@ -71,6 +71,7 @@ type t = | Try | Import | Export + | DocComment of Location.t * string let precedence = function | HashEqual | ColonEqual -> 1 @@ -158,6 +159,7 @@ let toString = function | Try -> "try" | Import -> "import" | Export -> "export" + | DocComment (_loc, s) -> "DocComment " ^ s let keywordTable = function | "and" -> And diff --git a/tests/parsing/infiniteLoops/expected/templateEof.res.txt b/tests/parsing/infiniteLoops/expected/templateEof.res.txt index fc64a8d1..f39fb284 100644 --- a/tests/parsing/infiniteLoops/expected/templateEof.res.txt +++ b/tests/parsing/infiniteLoops/expected/templateEof.res.txt @@ -20,4 +20,4 @@ ;;et ;;foo = - (fun x -> match x with | (("")[@res.template ]) -> [%rescript.exprhole ]) \ No newline at end of file + (fun x -> match x with | (("")[@res.template ]) -> [%rescript.exprhole ]) diff --git a/tests/parsing/other/docComments.res b/tests/parsing/other/docComments.res new file mode 100644 index 00000000..826ac489 --- /dev/null +++ b/tests/parsing/other/docComments.res @@ -0,0 +1,2 @@ +/** This is a doc comment */ +let z = 34 diff --git a/tests/parsing/other/expected/docComments.res.txt b/tests/parsing/other/expected/docComments.res.txt new file mode 100644 index 00000000..30431219 --- /dev/null +++ b/tests/parsing/other/expected/docComments.res.txt @@ -0,0 +1 @@ +let z = 34[@@ns.doc "* This is a doc comment "] \ No newline at end of file diff --git a/tests/printer/comments/expected/multiline.res.txt b/tests/printer/comments/expected/multiline.res.txt index 16095325..76826ba2 100644 --- a/tests/printer/comments/expected/multiline.res.txt +++ b/tests/printer/comments/expected/multiline.res.txt @@ -17,10 +17,6 @@ let f = () => () /* */ /* */ -/** - * test - */ - /* BuckleScript outperforms a classic for-loop: function equals3(m1, m2) { for (var i = 0; i < 4; i++) { @@ -34,6 +30,9 @@ let f = () => () } return true } */ +/* ** + * test + */ let equals = (matrix1, matrix2) => { let rec loop = (i, j) => if i > 3 { diff --git a/tests/printer/comments/expected/structure4.res.txt b/tests/printer/comments/expected/structure4.res.txt index 881df7f4..ba9422fb 100644 --- a/tests/printer/comments/expected/structure4.res.txt +++ b/tests/printer/comments/expected/structure4.res.txt @@ -1,25 +1,15 @@ -let user = { - name: "steve", - age: 31, -} -/* A comment */ -/** - * A type that can be written to a buffer. - */ -/** - * Describes the connection status of a ReactiveSocket/DuplexConnection. - * - NOT_CONNECTED: no connection established or pending. - * - CONNECTING: when `connect()` has been called but a connection is not yet - * established. - * - CONNECTED: when a connection is established. - * - CLOSED: when the connection has been explicitly closed via `close()`. - * - ERROR: when the connection has been closed for any other reason. - */ -/** - * A contract providing different interaction models per the [ReactiveSocket protocol] - * (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). - */ -/** - * A single unit of data exchanged between the peers of a `ReactiveSocket`. - */ + Syntax error! + tests/printer/comments/structure4.res:6:17-8:2 + + 4 │ } + 5 │ + 6 │ /* A comment */ /** + 7 │ * A type that can be written to a buffer. + 8 │ */ /** + 9 │ * Describes the connection status of a ReactiveSocket/DuplexConnection. + 10 │ * - NOT_CONNECTED: no connection established or pending. + + Did you forget to attach `ns.doc` to an item? + Standalone attributes start with `@@` like: `@@ns.doc` + diff --git a/tests/printer/comments/expected/trailingComments.res.txt b/tests/printer/comments/expected/trailingComments.res.txt index 473220a3..65a9f9ee 100644 --- a/tests/printer/comments/expected/trailingComments.res.txt +++ b/tests/printer/comments/expected/trailingComments.res.txt @@ -1,32 +1,15 @@ -let user = { - name: "steve", - age: 31 /* here */, // test - /* test */ - /* test2 */ + Syntax error! + tests/printer/comments/trailingComments.res:13:9-15:2 - // test3 + 11 │ } + 12 │ + 13 │ /* A */ /** + 14 │ * A type that can be written to a buffer. + 15 │ */ /** + 16 │ * Describes the connection status of a ReactiveSocket/DuplexConnection. + 17 │ * - NOT_CONNECTED: no connection established or pending. - /* test 4 */ -} + Did you forget to attach `ns.doc` to an item? + Standalone attributes start with `@@` like: `@@ns.doc` -/* A */ -/** - * A type that can be written to a buffer. - */ -/** - * Describes the connection status of a ReactiveSocket/DuplexConnection. - * - NOT_CONNECTED: no connection established or pending. - * - CONNECTING: when `connect()` has been called but a connection is not yet - * established. - * - CONNECTED: when a connection is established. - * - CLOSED: when the connection has been explicitly closed via `close()`. - * - ERROR: when the connection has been closed for any other reason. - */ -/** - * A contract providing different interaction models per the [ReactiveSocket protocol] - * (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). - */ -/** - * A single unit of data exchanged between the peers of a `ReactiveSocket`. - */ diff --git a/tests/printer/other/expected/StaticReactTypes.res.txt b/tests/printer/other/expected/StaticReactTypes.res.txt index bfe7c085..8a87a59d 100644 --- a/tests/printer/other/expected/StaticReactTypes.res.txt +++ b/tests/printer/other/expected/StaticReactTypes.res.txt @@ -1,82 +1,16 @@ -type empty = Empty_ -/* - * Also create another form for splicing in nodes into otherwise fixed length - * sets. - */ -type elem<'t> = - | Empty: elem - | Element(renderable<('s, 'a) => 'sub>): elem<('s, 'a) => 'sub> - | TwoElements(elem<'t1>, elem<'t2>): elem<('t1, 't2)> - /* - * Not an ordered map yet, but should be. - */ - | ElementMap(list>): elem> -/** - * Instance subtree. Mirrors the shape of JSX, instead of just being a List. - */ -and subtree<'t> = - | EmptyInstance: subtree - | Instance(inst<('s, 'a) => 'sub>): subtree<('s, 'a) => 'sub> - /* Having TwoInstances mirror the fact that TwoElements requires sub - * elements, was probably overkill. */ - | TwoInstances(subtree<'t1>, subtree<'t2>): subtree<('t1, 't2)> - | InstanceMap(list>): subtree> -and reducer<'t> = (inst<'t>, 'a) => 's constraint 't = ('s, 'a) => 'sub -/* - * These are just convenient shortcuts to specifiying the entire spec. It just - * makes it so you don't have to do a spread onto a record, since in - * static-by-default trees, you don't need to define a record beforehand. - */ -and componentSpec<'t> = - /* Add more forms here for convenience */ - | Reducer('s, elem<'sub>, reducer<'t>) constraint 't = ('s, 'a) => 'sub -and self<'t> = { - reduceEvent: 'e. ('e => 'a, 'e) => unit, - /** - * Implements the ability to cause your node to be swapped out from within - * its tree. Not purely functional by design. This is for things like - * external subscriptions that don't arive via propagations through the tree. - * However, this is better than simple naive mutation. That's because this - * "out of nowhere" operation notifies the root of the tree that it should - * perform a mutation. That allows the root to create an entirely new - * reference, leaving the previous tree completely in tact! There isn't a - * single mutable reference cell in the entire tree - only the root node is - * mutable, and even then it doesn't have to be. - * - * This Api takes highly imperative operations like request animation frame, - * and allows them to work well with what would otherwise be a purely - * functional data structure (aside from the side effects caused by - * subscribing upon mount etc). - */ - send: 'a => unit, -} constraint 't = ('s, 'a) => 'sub -/** - * The result of applying props. Now the result is a function that just waits - * for React to supply the state, and in turn returns the componentSpec. - */ -and renderable<'t> = (~state: 's=?, self<'t>) => componentSpec<'t> constraint 't = ('s, 'a) => 'sub -/* - * TODO: Can store the subreplacer in the instance so we don't need to - * recompute it every time. - */ -and inst<'t> = { - /* Memoized just for performance */ - replacer: replacer<'t>, - /* Memoized just for performance */ - subreplacer: subreplacer<'sub>, - self: self<'t>, - renderable: renderable<'t>, - spec: componentSpec<'t>, - subtree: subtree<'sub>, -} constraint 't = ('s, 'a) => 'sub -/* - * A series of chained functions that forms a fishing line that each component - * has a handle to. When invoked it can cause its own individual instance node - * in the tree to be replaced in the *root* tree that it exists in! This is - * totally type safe, and requires no dynamic casts, and no searching through - * the tree. - */ -/* Make it even more generalized on action than necessary to avoid GADT - * errors. */ -and replacer<'t> = (inst<'t> => inst<'t>) => unit constraint 't = ('s, 'a) => 'sub -and subreplacer<'sub> = (subtree<'sub> => subtree<'sub>) => unit + + Syntax error! + tests/printer/other/StaticReactTypes.res:15:3-17:5 + + 13 ┆ */ + 14 ┆ | ElementMap(list>): elem> + 15 ┆ /** + 16 ┆ * Instance subtree. Mirrors the shape of JSX, instead of just being a + ┆ List. + 17 ┆ */ + 18 ┆ and subtree<'t> = + 19 ┆ | EmptyInstance: subtree + + Did you forget to attach `ns.doc` to an item? + Standalone attributes start with `@@` like: `@@ns.doc` + From dcfeb055b72346cf554fe226e2916dc24ec3df27 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Jun 2022 08:51:12 +0200 Subject: [PATCH 02/12] Tweak tests. --- tests/idempotency/bs-css/Css_Js_Core.resi | 2 +- tests/idempotency/bs-css/Css_Legacy_Core.resi | 2 +- .../comments/expected/multiline.res.txt | 7 +- .../comments/expected/structure4.res.txt | 38 ++++--- .../expected/trailingComments.res.txt | 39 +++++--- tests/printer/comments/multiline.res | 2 +- tests/printer/comments/structure4.res | 8 +- tests/printer/comments/trailingComments.res | 8 +- tests/printer/other/StaticReactTypes.res | 6 +- .../other/expected/StaticReactTypes.res.txt | 98 ++++++++++++++++--- 10 files changed, 152 insertions(+), 58 deletions(-) diff --git a/tests/idempotency/bs-css/Css_Js_Core.resi b/tests/idempotency/bs-css/Css_Js_Core.resi index a98abca5..f58abd26 100644 --- a/tests/idempotency/bs-css/Css_Js_Core.resi +++ b/tests/idempotency/bs-css/Css_Js_Core.resi @@ -1729,7 +1729,7 @@ let animations: array<[Animation.t]> => rule let animationName: animationName => rule -/** +/* SVG *** */ diff --git a/tests/idempotency/bs-css/Css_Legacy_Core.resi b/tests/idempotency/bs-css/Css_Legacy_Core.resi index f601ed4b..de259ccc 100644 --- a/tests/idempotency/bs-css/Css_Legacy_Core.resi +++ b/tests/idempotency/bs-css/Css_Legacy_Core.resi @@ -1734,7 +1734,7 @@ let animations: list<[Animation.t]> => rule let animationName: animationName => rule -/** +/* SVG *** */ diff --git a/tests/printer/comments/expected/multiline.res.txt b/tests/printer/comments/expected/multiline.res.txt index 76826ba2..34293826 100644 --- a/tests/printer/comments/expected/multiline.res.txt +++ b/tests/printer/comments/expected/multiline.res.txt @@ -17,6 +17,10 @@ let f = () => () /* */ /* */ +/* + * test + */ + /* BuckleScript outperforms a classic for-loop: function equals3(m1, m2) { for (var i = 0; i < 4; i++) { @@ -30,9 +34,6 @@ let f = () => () } return true } */ -/* ** - * test - */ let equals = (matrix1, matrix2) => { let rec loop = (i, j) => if i > 3 { diff --git a/tests/printer/comments/expected/structure4.res.txt b/tests/printer/comments/expected/structure4.res.txt index ba9422fb..9f2fa92c 100644 --- a/tests/printer/comments/expected/structure4.res.txt +++ b/tests/printer/comments/expected/structure4.res.txt @@ -1,15 +1,25 @@ +let user = { + name: "steve", + age: 31, +} - Syntax error! - tests/printer/comments/structure4.res:6:17-8:2 - - 4 │ } - 5 │ - 6 │ /* A comment */ /** - 7 │ * A type that can be written to a buffer. - 8 │ */ /** - 9 │ * Describes the connection status of a ReactiveSocket/DuplexConnection. - 10 │ * - NOT_CONNECTED: no connection established or pending. - - Did you forget to attach `ns.doc` to an item? - Standalone attributes start with `@@` like: `@@ns.doc` - +/* A comment */ +/* + * A type that can be written to a buffer. + */ +/* + * Describes the connection status of a ReactiveSocket/DuplexConnection. + * - NOT_CONNECTED: no connection established or pending. + * - CONNECTING: when `connect()` has been called but a connection is not yet + * established. + * - CONNECTED: when a connection is established. + * - CLOSED: when the connection has been explicitly closed via `close()`. + * - ERROR: when the connection has been closed for any other reason. + */ +/* + * A contract providing different interaction models per the [ReactiveSocket protocol] + * (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). + */ +/* + * A single unit of data exchanged between the peers of a `ReactiveSocket`. + */ diff --git a/tests/printer/comments/expected/trailingComments.res.txt b/tests/printer/comments/expected/trailingComments.res.txt index 65a9f9ee..199dbcbc 100644 --- a/tests/printer/comments/expected/trailingComments.res.txt +++ b/tests/printer/comments/expected/trailingComments.res.txt @@ -1,15 +1,32 @@ +let user = { + name: "steve", + age: 31 /* here */, // test - Syntax error! - tests/printer/comments/trailingComments.res:13:9-15:2 + /* test */ + /* test2 */ - 11 │ } - 12 │ - 13 │ /* A */ /** - 14 │ * A type that can be written to a buffer. - 15 │ */ /** - 16 │ * Describes the connection status of a ReactiveSocket/DuplexConnection. - 17 │ * - NOT_CONNECTED: no connection established or pending. + // test3 - Did you forget to attach `ns.doc` to an item? - Standalone attributes start with `@@` like: `@@ns.doc` + /* test 4 */ +} +/* A */ +/* + * A type that can be written to a buffer. + */ +/* + * Describes the connection status of a ReactiveSocket/DuplexConnection. + * - NOT_CONNECTED: no connection established or pending. + * - CONNECTING: when `connect()` has been called but a connection is not yet + * established. + * - CONNECTED: when a connection is established. + * - CLOSED: when the connection has been explicitly closed via `close()`. + * - ERROR: when the connection has been closed for any other reason. + */ +/* + * A contract providing different interaction models per the [ReactiveSocket protocol] + * (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). + */ +/* + * A single unit of data exchanged between the peers of a `ReactiveSocket`. + */ diff --git a/tests/printer/comments/multiline.res b/tests/printer/comments/multiline.res index 5b6a4f23..a53a9bbe 100644 --- a/tests/printer/comments/multiline.res +++ b/tests/printer/comments/multiline.res @@ -17,7 +17,7 @@ let f = () => () /**/ /* */ -/** +/* * test */ diff --git a/tests/printer/comments/structure4.res b/tests/printer/comments/structure4.res index 34303ae7..227742f4 100644 --- a/tests/printer/comments/structure4.res +++ b/tests/printer/comments/structure4.res @@ -3,9 +3,9 @@ let user = { age: 31 } -/* A comment */ /** +/* A comment */ /* * A type that can be written to a buffer. -*/ /** +*/ /* * Describes the connection status of a ReactiveSocket/DuplexConnection. * - NOT_CONNECTED: no connection established or pending. * - CONNECTING: when `connect()` has been called but a connection is not yet @@ -13,9 +13,9 @@ let user = { * - CONNECTED: when a connection is established. * - CLOSED: when the connection has been explicitly closed via `close()`. * - ERROR: when the connection has been closed for any other reason. -*/ /** +*/ /* * A contract providing different interaction models per the [ReactiveSocket protocol] * (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). -*/ /** +*/ /* * A single unit of data exchanged between the peers of a `ReactiveSocket`. */ diff --git a/tests/printer/comments/trailingComments.res b/tests/printer/comments/trailingComments.res index 68a43038..daba6fab 100644 --- a/tests/printer/comments/trailingComments.res +++ b/tests/printer/comments/trailingComments.res @@ -10,9 +10,9 @@ let user = { /* test 4 */ } -/* A */ /** +/* A */ /* * A type that can be written to a buffer. -*/ /** +*/ /* * Describes the connection status of a ReactiveSocket/DuplexConnection. * - NOT_CONNECTED: no connection established or pending. * - CONNECTING: when `connect()` has been called but a connection is not yet @@ -20,9 +20,9 @@ let user = { * - CONNECTED: when a connection is established. * - CLOSED: when the connection has been explicitly closed via `close()`. * - ERROR: when the connection has been closed for any other reason. -*/ /** +*/ /* * A contract providing different interaction models per the [ReactiveSocket protocol] * (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). -*/ /** +*/ /* * A single unit of data exchanged between the peers of a `ReactiveSocket`. */ diff --git a/tests/printer/other/StaticReactTypes.res b/tests/printer/other/StaticReactTypes.res index f555cdb3..713ec2a2 100644 --- a/tests/printer/other/StaticReactTypes.res +++ b/tests/printer/other/StaticReactTypes.res @@ -12,7 +12,7 @@ type empty = * Not an ordered map yet, but should be. */ | ElementMap(list>): elem> - /** + /* * Instance subtree. Mirrors the shape of JSX, instead of just being a List. */ and subtree<'t> = @@ -34,7 +34,7 @@ type empty = constraint 't = ('s, 'a) => 'sub and self<'t> = { reduceEvent: 'e .('e => 'a, 'e) => unit, - /** + /* * Implements the ability to cause your node to be swapped out from within * its tree. Not purely functional by design. This is for things like * external subscriptions that don't arive via propagations through the tree. @@ -53,7 +53,7 @@ type empty = send: 'a => unit, } constraint 't = ('s, 'a) => 'sub - /** + /* * The result of applying props. Now the result is a function that just waits * for React to supply the state, and in turn returns the componentSpec. */ diff --git a/tests/printer/other/expected/StaticReactTypes.res.txt b/tests/printer/other/expected/StaticReactTypes.res.txt index 8a87a59d..dd479c4a 100644 --- a/tests/printer/other/expected/StaticReactTypes.res.txt +++ b/tests/printer/other/expected/StaticReactTypes.res.txt @@ -1,16 +1,82 @@ - - Syntax error! - tests/printer/other/StaticReactTypes.res:15:3-17:5 - - 13 ┆ */ - 14 ┆ | ElementMap(list>): elem> - 15 ┆ /** - 16 ┆ * Instance subtree. Mirrors the shape of JSX, instead of just being a - ┆ List. - 17 ┆ */ - 18 ┆ and subtree<'t> = - 19 ┆ | EmptyInstance: subtree - - Did you forget to attach `ns.doc` to an item? - Standalone attributes start with `@@` like: `@@ns.doc` - +type empty = Empty_ +/* + * Also create another form for splicing in nodes into otherwise fixed length + * sets. + */ +type elem<'t> = + | Empty: elem + | Element(renderable<('s, 'a) => 'sub>): elem<('s, 'a) => 'sub> + | TwoElements(elem<'t1>, elem<'t2>): elem<('t1, 't2)> + /* + * Not an ordered map yet, but should be. + */ + | ElementMap(list>): elem> +/* + * Instance subtree. Mirrors the shape of JSX, instead of just being a List. + */ +and subtree<'t> = + | EmptyInstance: subtree + | Instance(inst<('s, 'a) => 'sub>): subtree<('s, 'a) => 'sub> + /* Having TwoInstances mirror the fact that TwoElements requires sub + * elements, was probably overkill. */ + | TwoInstances(subtree<'t1>, subtree<'t2>): subtree<('t1, 't2)> + | InstanceMap(list>): subtree> +and reducer<'t> = (inst<'t>, 'a) => 's constraint 't = ('s, 'a) => 'sub +/* + * These are just convenient shortcuts to specifiying the entire spec. It just + * makes it so you don't have to do a spread onto a record, since in + * static-by-default trees, you don't need to define a record beforehand. + */ +and componentSpec<'t> = + /* Add more forms here for convenience */ + | Reducer('s, elem<'sub>, reducer<'t>) constraint 't = ('s, 'a) => 'sub +and self<'t> = { + reduceEvent: 'e. ('e => 'a, 'e) => unit, + /* + * Implements the ability to cause your node to be swapped out from within + * its tree. Not purely functional by design. This is for things like + * external subscriptions that don't arive via propagations through the tree. + * However, this is better than simple naive mutation. That's because this + * "out of nowhere" operation notifies the root of the tree that it should + * perform a mutation. That allows the root to create an entirely new + * reference, leaving the previous tree completely in tact! There isn't a + * single mutable reference cell in the entire tree - only the root node is + * mutable, and even then it doesn't have to be. + * + * This Api takes highly imperative operations like request animation frame, + * and allows them to work well with what would otherwise be a purely + * functional data structure (aside from the side effects caused by + * subscribing upon mount etc). + */ + send: 'a => unit, +} constraint 't = ('s, 'a) => 'sub +/* + * The result of applying props. Now the result is a function that just waits + * for React to supply the state, and in turn returns the componentSpec. + */ +and renderable<'t> = (~state: 's=?, self<'t>) => componentSpec<'t> constraint 't = ('s, 'a) => 'sub +/* + * TODO: Can store the subreplacer in the instance so we don't need to + * recompute it every time. + */ +and inst<'t> = { + /* Memoized just for performance */ + replacer: replacer<'t>, + /* Memoized just for performance */ + subreplacer: subreplacer<'sub>, + self: self<'t>, + renderable: renderable<'t>, + spec: componentSpec<'t>, + subtree: subtree<'sub>, +} constraint 't = ('s, 'a) => 'sub +/* + * A series of chained functions that forms a fishing line that each component + * has a handle to. When invoked it can cause its own individual instance node + * in the tree to be replaced in the *root* tree that it exists in! This is + * totally type safe, and requires no dynamic casts, and no searching through + * the tree. + */ +/* Make it even more generalized on action than necessary to avoid GADT + * errors. */ +and replacer<'t> = (inst<'t> => inst<'t>) => unit constraint 't = ('s, 'a) => 'sub +and subreplacer<'sub> = (subtree<'sub> => subtree<'sub>) => unit From 768f89330c0401acf17282ca19ef33d2a886953b Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Jun 2022 11:16:52 +0200 Subject: [PATCH 03/12] Remove stale. --- tests/printer/comments/expected/docComments.res.txt | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 tests/printer/comments/expected/docComments.res.txt diff --git a/tests/printer/comments/expected/docComments.res.txt b/tests/printer/comments/expected/docComments.res.txt deleted file mode 100644 index c841e39a..00000000 --- a/tests/printer/comments/expected/docComments.res.txt +++ /dev/null @@ -1,9 +0,0 @@ -/**This is one */ /**And this is another one */ -let x = 42 - -/* */ // But this is not - -/* **This is also not a doc comment */ - -/**Great Type */ -type myType = int From 1414ac9dda5f4139b786239540ec4d692d44742c Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Jun 2022 11:26:33 +0200 Subject: [PATCH 04/12] Cut out the relevant string. --- src/res_core.ml | 2 +- src/res_scanner.ml | 4 ++-- tests/parsing/other/docComments.res | 3 +++ tests/parsing/other/expected/docComments.res.txt | 3 ++- tests/printer/comments/docComments.res | 5 +++++ tests/printer/comments/expected/docComments.res.txt | 5 +++++ 6 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 tests/printer/comments/docComments.res create mode 100644 tests/printer/comments/expected/docComments.res.txt diff --git a/src/res_core.ml b/src/res_core.ml index ed8f35ec..d8d7ba65 100644 --- a/src/res_core.ml +++ b/src/res_core.ml @@ -6392,7 +6392,7 @@ and parseAttribute p = | DocComment (loc, s) -> Parser.next p; Some ({txt="ns.doc"; loc}, - PStr [Ast_helper.Str.eval ~loc (Ast_helper.Exp.constant ~loc (Pconst_string(s, None)) )]) + PStr [Ast_helper.Str.eval ~loc (Ast_helper.Exp.constant ~loc (Pconst_string(s, Some "js")) )]) | _ -> None and parseAttributes p = diff --git a/src/res_scanner.ml b/src/res_scanner.ml index 48abe11a..d389489d 100644 --- a/src/res_scanner.ml +++ b/src/res_scanner.ml @@ -480,12 +480,12 @@ let scanSingleLineComment scanner = let scanMultiLineComment scanner = (* assumption: we're only ever using this helper in `scan` after detecting a comment *) - let contentStartOff = scanner.offset + 2 in - let startPos = position scanner in let docComment = peek2 scanner = '*' && peek3 scanner <> '/' (* no /**/ *) && peek3 scanner <> '*' (* no /*** *) in + let contentStartOff = scanner.offset + (if docComment then 3 else 2) in + let startPos = position scanner in let rec scan ~depth = (* invariant: depth > 0 right after this match. See assumption *) match scanner.ch, peek scanner with diff --git a/tests/parsing/other/docComments.res b/tests/parsing/other/docComments.res index 826ac489..5c723fce 100644 --- a/tests/parsing/other/docComments.res +++ b/tests/parsing/other/docComments.res @@ -1,2 +1,5 @@ /** This is a doc comment */ let z = 34 + +@ns.doc("And this is a ns.doc annotation") +let q = 11 diff --git a/tests/parsing/other/expected/docComments.res.txt b/tests/parsing/other/expected/docComments.res.txt index 30431219..526214ad 100644 --- a/tests/parsing/other/expected/docComments.res.txt +++ b/tests/parsing/other/expected/docComments.res.txt @@ -1 +1,2 @@ -let z = 34[@@ns.doc "* This is a doc comment "] \ No newline at end of file +let z = 34[@@ns.doc {js| This is a doc comment |js}] +let q = 11[@@ns.doc {js|And this is a ns.doc annotation|js}] \ No newline at end of file diff --git a/tests/printer/comments/docComments.res b/tests/printer/comments/docComments.res new file mode 100644 index 00000000..5c723fce --- /dev/null +++ b/tests/printer/comments/docComments.res @@ -0,0 +1,5 @@ +/** This is a doc comment */ +let z = 34 + +@ns.doc("And this is a ns.doc annotation") +let q = 11 diff --git a/tests/printer/comments/expected/docComments.res.txt b/tests/printer/comments/expected/docComments.res.txt new file mode 100644 index 00000000..b2a9344e --- /dev/null +++ b/tests/printer/comments/expected/docComments.res.txt @@ -0,0 +1,5 @@ +/** This is a doc comment */ +let z = 34 + +/**And this is a ns.doc annotation */ +let q = 11 From 1060402e2fc595ea8d449b969c1c306a6c1e6dca Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Jun 2022 11:33:05 +0200 Subject: [PATCH 05/12] Print doc comments specially. --- src/res_printer.ml | 8 ++++---- tests/idempotency/napkinscript/docComments.res | 5 +++++ tests/printer/comments/expected/docComments.res.txt | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 tests/idempotency/napkinscript/docComments.res diff --git a/src/res_printer.ml b/src/res_printer.ml index c98bb396..528cda68 100644 --- a/src/res_printer.ml +++ b/src/res_printer.ml @@ -136,13 +136,13 @@ let printMultilineCommentContent ~docComment txt = in let lines = String.split_on_char '\n' txt in match lines with - | [] -> Doc.text "/* */" + | [] -> Doc.text (if docComment then "/** */" else "/* */") | [line] -> Doc.concat [ - Doc.text (if docComment then "/*" else "/* "); + Doc.text (if docComment then "/**" else "/* "); Doc.text (Comment.trimSpaces line); - Doc.text " */"; + Doc.text (if docComment then "*/" else " */"); ] | first :: rest -> let firstLine = Comment.trimSpaces first in @@ -4773,7 +4773,7 @@ and printAttribute ?(standalone = false) ((id, payload) : Parsetree.attribute) }; ] ) -> let comment = - Comment.makeMultiLineComment ~loc:id.loc ~docComment:true ("*" ^ s) + Comment.makeMultiLineComment ~loc:id.loc ~docComment:true s in printLeadingComment comment | _ -> diff --git a/tests/idempotency/napkinscript/docComments.res b/tests/idempotency/napkinscript/docComments.res new file mode 100644 index 00000000..5c723fce --- /dev/null +++ b/tests/idempotency/napkinscript/docComments.res @@ -0,0 +1,5 @@ +/** This is a doc comment */ +let z = 34 + +@ns.doc("And this is a ns.doc annotation") +let q = 11 diff --git a/tests/printer/comments/expected/docComments.res.txt b/tests/printer/comments/expected/docComments.res.txt index b2a9344e..1615490e 100644 --- a/tests/printer/comments/expected/docComments.res.txt +++ b/tests/printer/comments/expected/docComments.res.txt @@ -1,5 +1,5 @@ -/** This is a doc comment */ +/**This is a doc comment*/ let z = 34 -/**And this is a ns.doc annotation */ +/**And this is a ns.doc annotation*/ let q = 11 From 3a4f147db050d45e9fa6c8efa11067a001d5ec08 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Jun 2022 11:41:25 +0200 Subject: [PATCH 06/12] Print line verbatim. --- src/res_printer.ml | 2 +- tests/printer/comments/expected/docComments.res.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/res_printer.ml b/src/res_printer.ml index 528cda68..2347ec29 100644 --- a/src/res_printer.ml +++ b/src/res_printer.ml @@ -141,7 +141,7 @@ let printMultilineCommentContent ~docComment txt = Doc.concat [ Doc.text (if docComment then "/**" else "/* "); - Doc.text (Comment.trimSpaces line); + Doc.text (if docComment then line else Comment.trimSpaces line); Doc.text (if docComment then "*/" else " */"); ] | first :: rest -> diff --git a/tests/printer/comments/expected/docComments.res.txt b/tests/printer/comments/expected/docComments.res.txt index 1615490e..847f7ee3 100644 --- a/tests/printer/comments/expected/docComments.res.txt +++ b/tests/printer/comments/expected/docComments.res.txt @@ -1,4 +1,4 @@ -/**This is a doc comment*/ +/** This is a doc comment */ let z = 34 /**And this is a ns.doc annotation*/ From 86b9b56d265fbd0b13162388044e791b80d41bf2 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Jun 2022 11:48:34 +0200 Subject: [PATCH 07/12] Store doc comments internally without js. --- src/res_core.ml | 2 +- tests/parsing/other/expected/docComments.res.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/res_core.ml b/src/res_core.ml index d8d7ba65..ed8f35ec 100644 --- a/src/res_core.ml +++ b/src/res_core.ml @@ -6392,7 +6392,7 @@ and parseAttribute p = | DocComment (loc, s) -> Parser.next p; Some ({txt="ns.doc"; loc}, - PStr [Ast_helper.Str.eval ~loc (Ast_helper.Exp.constant ~loc (Pconst_string(s, Some "js")) )]) + PStr [Ast_helper.Str.eval ~loc (Ast_helper.Exp.constant ~loc (Pconst_string(s, None)) )]) | _ -> None and parseAttributes p = diff --git a/tests/parsing/other/expected/docComments.res.txt b/tests/parsing/other/expected/docComments.res.txt index 526214ad..e524a842 100644 --- a/tests/parsing/other/expected/docComments.res.txt +++ b/tests/parsing/other/expected/docComments.res.txt @@ -1,2 +1,2 @@ -let z = 34[@@ns.doc {js| This is a doc comment |js}] +let z = 34[@@ns.doc " This is a doc comment "] let q = 11[@@ns.doc {js|And this is a ns.doc annotation|js}] \ No newline at end of file From ca5ec4b5924d34fdaad52dbe9d1ce3af8513e1bf Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Jun 2022 12:24:18 +0200 Subject: [PATCH 08/12] Add emoji to tests. --- tests/idempotency/napkinscript/docComments.res | 4 ++-- tests/parsing/other/docComments.res | 4 ++-- tests/parsing/other/expected/docComments.res.txt | 4 ++-- tests/printer/comments/docComments.res | 4 ++-- tests/printer/comments/expected/docComments.res.txt | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/idempotency/napkinscript/docComments.res b/tests/idempotency/napkinscript/docComments.res index 5c723fce..c26008ae 100644 --- a/tests/idempotency/napkinscript/docComments.res +++ b/tests/idempotency/napkinscript/docComments.res @@ -1,5 +1,5 @@ -/** This is a doc comment */ +/** This is a doc ✅ comment */ let z = 34 -@ns.doc("And this is a ns.doc annotation") +@ns.doc("And this is a ns.doc ✅ annotation") let q = 11 diff --git a/tests/parsing/other/docComments.res b/tests/parsing/other/docComments.res index 5c723fce..c26008ae 100644 --- a/tests/parsing/other/docComments.res +++ b/tests/parsing/other/docComments.res @@ -1,5 +1,5 @@ -/** This is a doc comment */ +/** This is a doc ✅ comment */ let z = 34 -@ns.doc("And this is a ns.doc annotation") +@ns.doc("And this is a ns.doc ✅ annotation") let q = 11 diff --git a/tests/parsing/other/expected/docComments.res.txt b/tests/parsing/other/expected/docComments.res.txt index e524a842..98735c5f 100644 --- a/tests/parsing/other/expected/docComments.res.txt +++ b/tests/parsing/other/expected/docComments.res.txt @@ -1,2 +1,2 @@ -let z = 34[@@ns.doc " This is a doc comment "] -let q = 11[@@ns.doc {js|And this is a ns.doc annotation|js}] \ No newline at end of file +let z = 34[@@ns.doc " This is a doc \226\156\133 comment "] +let q = 11[@@ns.doc {js|And this is a ns.doc ✅ annotation|js}] \ No newline at end of file diff --git a/tests/printer/comments/docComments.res b/tests/printer/comments/docComments.res index 5c723fce..c26008ae 100644 --- a/tests/printer/comments/docComments.res +++ b/tests/printer/comments/docComments.res @@ -1,5 +1,5 @@ -/** This is a doc comment */ +/** This is a doc ✅ comment */ let z = 34 -@ns.doc("And this is a ns.doc annotation") +@ns.doc("And this is a ns.doc ✅ annotation") let q = 11 diff --git a/tests/printer/comments/expected/docComments.res.txt b/tests/printer/comments/expected/docComments.res.txt index 847f7ee3..35784bb3 100644 --- a/tests/printer/comments/expected/docComments.res.txt +++ b/tests/printer/comments/expected/docComments.res.txt @@ -1,5 +1,5 @@ -/** This is a doc comment */ +/** This is a doc ✅ comment */ let z = 34 -/**And this is a ns.doc annotation*/ +/**And this is a ns.doc ✅ annotation*/ let q = 11 From e35ed3329eaf0cf25c3ed4533ef4c846da6777d1 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Jun 2022 12:27:41 +0200 Subject: [PATCH 09/12] Add multi-line test. --- src/res_printer.ml | 4 ++-- tests/idempotency/napkinscript/docComments.res | 6 ++++++ tests/parsing/other/docComments.res | 6 ++++++ tests/parsing/other/expected/docComments.res.txt | 4 +++- tests/printer/comments/docComments.res | 6 ++++++ tests/printer/comments/expected/docComments.res.txt | 6 ++++++ 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/res_printer.ml b/src/res_printer.ml index 2347ec29..85c492a1 100644 --- a/src/res_printer.ml +++ b/src/res_printer.ml @@ -148,12 +148,12 @@ let printMultilineCommentContent ~docComment txt = let firstLine = Comment.trimSpaces first in Doc.concat [ - Doc.text "/*"; + Doc.text (if docComment then "/**" else "/*"); (match firstLine with | "" | "*" -> Doc.nil | _ -> Doc.space); indentStars rest [Doc.hardLine; Doc.text firstLine]; - Doc.text "*/"; + Doc.text (if docComment then " */" else "*/"); ] let printTrailingComment (prevLoc : Location.t) (nodeLoc : Location.t) comment = diff --git a/tests/idempotency/napkinscript/docComments.res b/tests/idempotency/napkinscript/docComments.res index c26008ae..d25fd130 100644 --- a/tests/idempotency/napkinscript/docComments.res +++ b/tests/idempotency/napkinscript/docComments.res @@ -3,3 +3,9 @@ let z = 34 @ns.doc("And this is a ns.doc ✅ annotation") let q = 11 + +/** This + * is a multi-line + multiline doc comment + */ +type h = int diff --git a/tests/parsing/other/docComments.res b/tests/parsing/other/docComments.res index c26008ae..019deab9 100644 --- a/tests/parsing/other/docComments.res +++ b/tests/parsing/other/docComments.res @@ -3,3 +3,9 @@ let z = 34 @ns.doc("And this is a ns.doc ✅ annotation") let q = 11 + +/** This + * is a multi-line + multiline doc comment + */ +type h = int \ No newline at end of file diff --git a/tests/parsing/other/expected/docComments.res.txt b/tests/parsing/other/expected/docComments.res.txt index 98735c5f..3ec8813e 100644 --- a/tests/parsing/other/expected/docComments.res.txt +++ b/tests/parsing/other/expected/docComments.res.txt @@ -1,2 +1,4 @@ let z = 34[@@ns.doc " This is a doc \226\156\133 comment "] -let q = 11[@@ns.doc {js|And this is a ns.doc ✅ annotation|js}] \ No newline at end of file +let q = 11[@@ns.doc {js|And this is a ns.doc ✅ annotation|js}] +type nonrec h = int[@@ns.doc + " This\n * is a multi-line\n multiline doc comment\n "] \ No newline at end of file diff --git a/tests/printer/comments/docComments.res b/tests/printer/comments/docComments.res index c26008ae..d25fd130 100644 --- a/tests/printer/comments/docComments.res +++ b/tests/printer/comments/docComments.res @@ -3,3 +3,9 @@ let z = 34 @ns.doc("And this is a ns.doc ✅ annotation") let q = 11 + +/** This + * is a multi-line + multiline doc comment + */ +type h = int diff --git a/tests/printer/comments/expected/docComments.res.txt b/tests/printer/comments/expected/docComments.res.txt index 35784bb3..2fa71c58 100644 --- a/tests/printer/comments/expected/docComments.res.txt +++ b/tests/printer/comments/expected/docComments.res.txt @@ -3,3 +3,9 @@ let z = 34 /**And this is a ns.doc ✅ annotation*/ let q = 11 + +/** This + * is a multi-line + multiline doc comment + */ +type h = int From 7076b5d19f39c90e89deece42eee8df529abafe7 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Jun 2022 13:50:59 +0200 Subject: [PATCH 10/12] Print doc comments verbatim. --- src/res_printer.ml | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/res_printer.ml b/src/res_printer.ml index 85c492a1..717eba77 100644 --- a/src/res_printer.ml +++ b/src/res_printer.ml @@ -99,7 +99,7 @@ let hasCommentBelow tbl loc = | [] -> false | exception Not_found -> false -let printMultilineCommentContent ~docComment txt = +let printMultilineCommentContent txt = (* Turns * |* first line * * second line @@ -136,33 +136,28 @@ let printMultilineCommentContent ~docComment txt = in let lines = String.split_on_char '\n' txt in match lines with - | [] -> Doc.text (if docComment then "/** */" else "/* */") + | [] -> Doc.text "/* */" | [line] -> Doc.concat - [ - Doc.text (if docComment then "/**" else "/* "); - Doc.text (if docComment then line else Comment.trimSpaces line); - Doc.text (if docComment then "*/" else " */"); - ] + [Doc.text "/* "; Doc.text (Comment.trimSpaces line); Doc.text " */"] | first :: rest -> let firstLine = Comment.trimSpaces first in Doc.concat [ - Doc.text (if docComment then "/**" else "/*"); + Doc.text "/*"; (match firstLine with | "" | "*" -> Doc.nil | _ -> Doc.space); indentStars rest [Doc.hardLine; Doc.text firstLine]; - Doc.text (if docComment then " */" else "*/"); + Doc.text "*/"; ] let printTrailingComment (prevLoc : Location.t) (nodeLoc : Location.t) comment = let singleLine = Comment.isSingleLineComment comment in - let docComment = Comment.isDocComment comment in let content = let txt = Comment.txt comment in if singleLine then Doc.text ("//" ^ txt) - else printMultilineCommentContent ~docComment txt + else printMultilineCommentContent txt in let diff = let cmtStart = (Comment.loc comment).loc_start in @@ -188,11 +183,10 @@ let printTrailingComment (prevLoc : Location.t) (nodeLoc : Location.t) comment = let printLeadingComment ?nextComment comment = let singleLine = Comment.isSingleLineComment comment in - let docComment = Comment.isDocComment comment in let content = let txt = Comment.txt comment in if singleLine then Doc.text ("//" ^ txt) - else printMultilineCommentContent ~docComment txt + else printMultilineCommentContent txt in let separator = Doc.concat @@ -4769,13 +4763,10 @@ and printAttribute ?(standalone = false) ((id, payload) : Parsetree.attribute) [ { pstr_desc = - Pstr_eval ({pexp_desc = Pexp_constant (Pconst_string (s, _))}, _); + Pstr_eval ({pexp_desc = Pexp_constant (Pconst_string (txt, _))}, _); }; ] ) -> - let comment = - Comment.makeMultiLineComment ~loc:id.loc ~docComment:true s - in - printLeadingComment comment + Doc.concat [Doc.text "/**"; Doc.text txt; Doc.text "*/"] | _ -> Doc.group (Doc.concat From ec7d169a5fd88b42a4669eeb04abbc62d61a9e30 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Jun 2022 13:52:04 +0200 Subject: [PATCH 11/12] Restore idempotency tests. --- tests/idempotency/bs-css/Css_Js_Core.resi | 2 +- tests/idempotency/bs-css/Css_Legacy_Core.resi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/idempotency/bs-css/Css_Js_Core.resi b/tests/idempotency/bs-css/Css_Js_Core.resi index f58abd26..a98abca5 100644 --- a/tests/idempotency/bs-css/Css_Js_Core.resi +++ b/tests/idempotency/bs-css/Css_Js_Core.resi @@ -1729,7 +1729,7 @@ let animations: array<[Animation.t]> => rule let animationName: animationName => rule -/* +/** SVG *** */ diff --git a/tests/idempotency/bs-css/Css_Legacy_Core.resi b/tests/idempotency/bs-css/Css_Legacy_Core.resi index de259ccc..f601ed4b 100644 --- a/tests/idempotency/bs-css/Css_Legacy_Core.resi +++ b/tests/idempotency/bs-css/Css_Legacy_Core.resi @@ -1734,7 +1734,7 @@ let animations: list<[Animation.t]> => rule let animationName: animationName => rule -/* +/** SVG *** */ From 94cedca7fbe81a8df4b1ae63673f28f93a42dc51 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Jun 2022 15:05:58 +0200 Subject: [PATCH 12/12] Unused open. --- src/res_parser.ml | 1 - tests/parsing/infiniteLoops/expected/templateEof.res.txt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/res_parser.ml b/src/res_parser.ml index 0853ce51..f920c57f 100644 --- a/src/res_parser.ml +++ b/src/res_parser.ml @@ -50,7 +50,6 @@ let endRegion p = | _ :: rest -> p.regions <- rest let docCommentToAttributeToken comment = - let open Ast_helper in let txt = Comment.txt comment in let loc = Comment.loc comment in Token.DocComment (loc, txt) diff --git a/tests/parsing/infiniteLoops/expected/templateEof.res.txt b/tests/parsing/infiniteLoops/expected/templateEof.res.txt index f39fb284..fc64a8d1 100644 --- a/tests/parsing/infiniteLoops/expected/templateEof.res.txt +++ b/tests/parsing/infiniteLoops/expected/templateEof.res.txt @@ -20,4 +20,4 @@ ;;et ;;foo = - (fun x -> match x with | (("")[@res.template ]) -> [%rescript.exprhole ]) + (fun x -> match x with | (("")[@res.template ]) -> [%rescript.exprhole ]) \ No newline at end of file