package ez_opam_file

  1. Overview
  2. Docs

Source file v1.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# 1 "src/ez_opam_file/v1.new.ml"
(**************************************************************************)
(*                                                                        *)
(*  Copyright (c) 2020 OCamlPro SAS & Origin Labs SAS                     *)
(*                                                                        *)
(*  All rights reserved.                                                  *)
(*  This file is distributed under the terms of the GNU Lesser General    *)
(*  Public License version 2.1, with the special exception on linking     *)
(*  described in the LICENSE.md file in the root directory.               *)
(*                                                                        *)
(*                                                                        *)
(**************************************************************************)

module T = OpamParserTypes
module F = OpamParserTypes.FullPos

module OpamParserTypes = struct

  (** Defines the types for the opam format lexer and parser *)

  (** Type definitions used by the legacy and the new full position modules *)

  (** Relational operators *)
  type relop = [ `Eq  (** [=] *)
               | `Neq (** [!=] *)
               | `Geq (** [>=] *)
               | `Gt  (** [>] *)
               | `Leq (** [<=] *)
               | `Lt  (** [<] *)
               ]

  (** Logical operators *)
  type logop = [ `And (** [&] *) | `Or (** [|] *) ]

  (** Prefix operators *)
  type pfxop = [ `Not (** [!] *) | `Defined (** [?] *) ]

  type file_name = string

  (** Source file positions: [(filename, line, column)] *)
  type pos = file_name * int * int

  (** Environment variable update operators *)
  type env_update_op = T.env_update_op = Eq       (** [=] *)
                     | PlusEq   (** [+=] *)
                     | EqPlus   (** [=+] *)
                     | ColonEq  (** [:=] *)
                     | EqColon  (** [=:] *)
                     | EqPlusEq (** [=+=] *)

  (** [OpamParserTypes] transitional module with full position types *)
  module FullPos = struct

    (** Source file positions *)
    type file_name = string

    (** Full position *)
    type pos = F.pos = {
      filename: file_name;
      start: int * int; (* line, column *)
      stop: int * int;  (* line, column *)
    }

    (** [with_pos] type, used for all units, embedding the element [pelem] ans
        its position [pos] *)
    type 'a with_pos = 'a F.with_pos = {
      pelem : 'a;
      pos : pos
    }

    type relop_kind = relop
    type relop = relop_kind with_pos

    type logop_kind = logop
    type logop = logop_kind with_pos

    type pfxop_kind = pfxop
    type pfxop = pfxop_kind with_pos

    type env_update_op_kind = env_update_op
    type env_update_op = env_update_op_kind with_pos

    (** Base values *)
    type value_kind = F.value_kind =
      | Bool of bool
      (** [bool] atoms *)
      | Int of int
      (** [int] atoms *)
      | String of string
      (** [string] atoms *)
      | Relop of relop * value * value
      (** Relational operators with two values (e.g. [os != "win32"]) *)
      | Prefix_relop of relop * value
      (** Relational operators in prefix position (e.g. [< "4.07.0"]) *)
      | Logop of logop * value * value
      (** Logical operators *)
      | Pfxop of pfxop * value
      (** Prefix operators *)
      | Ident of string
      (** Identifiers *)
      | List of value list with_pos
      (** Lists of values ([[x1 x2 ... x3]]) *)
      | Group of value list with_pos
      (** Groups of values ([(x1 x2 ... x3)]) *)
      | Option of value * value list with_pos
      (** Value with optional list ([x1 {x2 x3 x4}]) *)
      | Env_binding of value * env_update_op * value
      (** Environment variable binding ([FOO += "bar"]) *)
    and value = value_kind with_pos

    (** An opamfile section *)
    type opamfile_section = F.opamfile_section =
      { section_kind  : string with_pos;             (** Section kind
                                                         (e.g. [extra-source]) *)
        section_name  : string with_pos option;      (** Section name
                                                         (e.g. ["myfork.patch"]) *)
        section_items : opamfile_item list with_pos; (** Content of the section *)
      }

    (** An opamfile is composed of sections and variable definitions *)
    and opamfile_item_kind = F.opamfile_item_kind =
      | Section of opamfile_section         (** e.g. [kind ["name"] { ... }] *)
      | Variable of string with_pos * value (** e.g. [opam-version: "2.0"] *)
    and opamfile_item = opamfile_item_kind with_pos

    (** A file is a list of items and the filename *)
    type opamfile = F.opamfile = {
      file_contents: opamfile_item list; (** Content of the file *)
      file_name    : file_name;          (** Name of the disk file this record was
                                             loaded from *)
    }

  end
end


module OpamParser = OpamParser
module OpamPrinter = OpamPrinter
OCaml

Innovation. Community. Security.