package parsexp

  1. Overview
  2. Docs

Source file parsexp.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
open! Import

module type Conv = Conv.S
module type Parser = Parser.S
module type Eager_parser = Parser.S_eager

module Conv_error = Conv_error
module Of_sexp_error = Of_sexp_error
module Old_parser_cont_state = Old_parser_cont_state
module Parse_error = Parse_error
module Positions = Positions
module Cst = Cst
module A = Parser_automaton

exception Parse_error = Parse_error.Parse_error
exception Of_sexp_error = Of_sexp_error.Of_sexp_error

module Single =
  Parser.Make
    (Kind.Sexp)
    (struct
      type parsed_value = Sexp.t

      let mode = A.Single
      let make_value _ stack = Automaton_stack.get_single stack
    end)

module Many =
  Parser.Make
    (Kind.Sexp)
    (struct
      type parsed_value = Sexp.t list

      let mode = A.Many
      let make_value _ stack = Automaton_stack.get_many stack
    end)

module Eager =
  Parser.Make_eager
    (Kind.Sexp)
    (struct
      type parsed_value = Sexp.t

      let make_value _ stack = Automaton_stack.get_single stack
    end)

module Single_and_positions =
  Parser.Make
    (Kind.Sexp_with_positions)
    (struct
      type parsed_value = Sexp.t * Positions.t

      let mode = A.Single
      let make_value state stack = Automaton_stack.get_single stack, A.positions state
    end)

module Many_and_positions =
  Parser.Make
    (Kind.Sexp_with_positions)
    (struct
      type parsed_value = Sexp.t list * Positions.t

      let mode = A.Many
      let make_value state stack = Automaton_stack.get_many stack, A.positions state
    end)

module Eager_and_positions =
  Parser.Make_eager
    (Kind.Sexp_with_positions)
    (struct
      type parsed_value = Sexp.t * Positions.t

      let make_value state stack = Automaton_stack.get_single stack, A.positions state
    end)

module Single_just_positions =
  Parser.Make
    (Kind.Positions)
    (struct
      type parsed_value = Positions.t

      let mode = A.Single
      let make_value state () = A.positions state
    end)

module Many_just_positions =
  Parser.Make
    (Kind.Positions)
    (struct
      type parsed_value = Positions.t

      let mode = A.Many
      let make_value state () = A.positions state
    end)

module Eager_just_positions =
  Parser.Make_eager
    (Kind.Positions)
    (struct
      type parsed_value = Positions.t

      let make_value state () = A.positions state
    end)

module Many_cst =
  Parser.Make
    (Kind.Cst)
    (struct
      type parsed_value = Cst.t_or_comment list

      let mode = A.Many
      let make_value _ stack = Automaton_stack.For_cst.get_many stack
    end)

module Eager_cst =
  Parser.Make_eager
    (Kind.Cst)
    (struct
      type parsed_value = Cst.t_or_comment

      let make_value _ stack =
        match Automaton_stack.For_cst.get_many stack with
        | [ sexp ] -> sexp
        | _ -> assert false
      ;;
    end)

type 'a id = 'a
type sexp_list = Sexp.t list

module Conv_single =
  Conv.Make
    (struct
      type 'a res = 'a
      type parsed_sexp = Sexp.t
      type chunk_to_conv = Sexp.t

      let apply_f x ~f = f x
      let find = Positions.find_sub_sexp_phys
    end)
    (Single)
    (Single_just_positions)

module Conv_many =
  Conv.Make
    (struct
      type 'a res = 'a list
      type parsed_sexp = Sexp.t list
      type chunk_to_conv = Sexp.t

      let apply_f x ~f = List.rev (List.rev_map x ~f)
      let find = Positions.find_sub_sexp_in_list_phys
    end)
    (Many)
    (Many_just_positions)

module Conv_many_at_once =
  Conv.Make
    (struct
      type 'a res = 'a
      type parsed_sexp = Sexp.t list
      type chunk_to_conv = Sexp.t list

      let apply_f x ~f = f x
      let find = Positions.find_sub_sexp_in_list_phys
    end)
    (Many)
    (Many_just_positions)

module Private = struct
  module Automaton_stack = Automaton_stack
  module Parser_automaton = Parser_automaton
end
OCaml

Innovation. Community. Security.