package reason

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file reason_comment.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
type category =
  | EndOfLine
  | SingleLine
  | Regular

type t =
  { location : Location.t
  ; category : category
  ; text : string
  }

let category t = t.category
let location t = t.location

let wrap t =
  match t.text with
  | "" | "*" -> "/***/"
  | txt when Reason_syntax_util.isLineComment txt ->
    "//"
    (* single line comments of the form `// comment` have a `\n` at the end *)
    ^ String.sub txt ~pos:0 ~len:(String.length txt - 1)
    ^ Reason_syntax_util.EOLMarker.string
  | txt when txt.[0] = '*' && txt.[1] <> '*' ->
    (* CHECK: this comment printing seems fishy.
     *  It apply to invalid docstrings.
     *  In this case, it will add a spurious '*'.
     *  E.g. /**
     *        * bla */
     *  In an invalid context is turned into
     *       /***
     *        * bla */
     *  I think this case should be removed.
     *)
    "/**" ^ txt ^ "*/"
  | txt -> "/*" ^ txt ^ "*/"

let make ~location category text = { text; category; location }

let isLineComment { category; text; _ } =
  match category with
  | SingleLine -> Reason_syntax_util.isLineComment text
  | EndOfLine | Regular -> false