Rename String to Quoted_string
This commit is contained in:
parent
75ad9736f8
commit
73f529ae82
|
@ -328,7 +328,7 @@ module Unexpanded = struct
|
|||
|
||||
let t sexp =
|
||||
match sexp with
|
||||
| Atom _ | String _ ->
|
||||
| Atom _ | Quoted_string _ ->
|
||||
of_sexp_errorf sexp
|
||||
"if you meant for this to be executed with bash, write (bash \"...\") instead"
|
||||
| List _ -> t sexp
|
||||
|
|
|
@ -190,7 +190,7 @@ module Pp_or_flags = struct
|
|||
PP (Pp.of_string s)
|
||||
|
||||
let t = function
|
||||
| Atom (_, s) | String (_, s) -> of_string s
|
||||
| Atom (_, s) | Quoted_string (_, s) -> of_string s
|
||||
| List (_, l) -> Flags (List.map l ~f:string)
|
||||
|
||||
let split l =
|
||||
|
@ -225,7 +225,7 @@ module Dep_conf = struct
|
|||
in
|
||||
fun sexp ->
|
||||
match sexp with
|
||||
| Atom _ | String _ -> File (String_with_vars.t sexp)
|
||||
| Atom _ | Quoted_string _ -> File (String_with_vars.t sexp)
|
||||
| List _ -> t sexp
|
||||
|
||||
open Sexp
|
||||
|
@ -356,7 +356,7 @@ module Lib_dep = struct
|
|||
let choice = function
|
||||
| List (_, l) as sexp ->
|
||||
let rec loop required forbidden = function
|
||||
| [Atom (_, "->"); fsexp] | [String (_, "->"); fsexp] ->
|
||||
| [Atom (_, "->"); fsexp] | [Quoted_string (_, "->"); fsexp] ->
|
||||
let common = String_set.inter required forbidden in
|
||||
if not (String_set.is_empty common) then
|
||||
of_sexp_errorf sexp
|
||||
|
@ -366,9 +366,10 @@ module Lib_dep = struct
|
|||
; forbidden
|
||||
; file = file fsexp
|
||||
}
|
||||
| Atom (_, "->") :: _ | String (_, "->") :: _ | List _ :: _ | [] ->
|
||||
| Atom (_, "->") :: _ | Quoted_string (_, "->") :: _
|
||||
| List _ :: _ | [] ->
|
||||
of_sexp_error sexp "(<[!]libraries>... -> <file>) expected"
|
||||
| (Atom (_, s) | String (_, s)) :: l ->
|
||||
| (Atom (_, s) | Quoted_string (_, s)) :: l ->
|
||||
let len = String.length s in
|
||||
if len > 0 && s.[0] = '!' then
|
||||
let s = String.sub s ~pos:1 ~len:(len - 1) in
|
||||
|
|
|
@ -25,7 +25,7 @@ let loc t = t.loc
|
|||
let parse_general sexp ~f =
|
||||
let rec of_sexp : Sexp.Ast.t -> _ = function
|
||||
| Atom (loc, "\\") -> Loc.fail loc "unexpected \\"
|
||||
| (Atom (_, "") | String (_, _)) as t -> Ast.Element (f t)
|
||||
| (Atom (_, "") | Quoted_string (_, _)) as t -> Ast.Element (f t)
|
||||
| Atom (loc, s) as t ->
|
||||
if s.[0] = ':' then
|
||||
Special (loc, String.sub s ~pos:1 ~len:(String.length s - 1))
|
||||
|
@ -43,7 +43,7 @@ let parse_general sexp ~f =
|
|||
let t sexp : t =
|
||||
let ast =
|
||||
parse_general sexp ~f:(function
|
||||
| Atom (loc, s) | String (loc, s) -> (loc, s)
|
||||
| Atom (loc, s) | Quoted_string (loc, s) -> (loc, s)
|
||||
| List _ -> assert false)
|
||||
in
|
||||
{ ast
|
||||
|
|
18
src/sexp.ml
18
src/sexp.ml
|
@ -85,7 +85,7 @@ end
|
|||
module To_sexp = struct
|
||||
type nonrec 'a t = 'a -> t
|
||||
let unit () = List []
|
||||
let string s = String s
|
||||
let string s = Quoted_string s
|
||||
let int n = Atom (string_of_int n)
|
||||
let float f = Atom (string_of_float f)
|
||||
let bool b = Atom (string_of_bool b)
|
||||
|
@ -109,7 +109,7 @@ end
|
|||
module Of_sexp = struct
|
||||
type ast = Ast.t =
|
||||
| Atom of Loc.t * string
|
||||
| String of Loc.t * string
|
||||
| Quoted_string of Loc.t * string
|
||||
| List of Loc.t * ast list
|
||||
|
||||
type 'a t = ast -> 'a
|
||||
|
@ -126,7 +126,7 @@ module Of_sexp = struct
|
|||
|
||||
let string = function
|
||||
| Atom (_, s) -> s
|
||||
| String (_, s) -> s
|
||||
| Quoted_string (_, s) -> s
|
||||
| List _ as sexp -> of_sexp_error sexp "Atom expected"
|
||||
|
||||
let int sexp =
|
||||
|
@ -158,7 +158,7 @@ module Of_sexp = struct
|
|||
| sexp -> of_sexp_error sexp "S-expression of the form (_ _ _) expected"
|
||||
|
||||
let list f = function
|
||||
| (Atom _ | String _) as sexp -> of_sexp_error sexp "List expected"
|
||||
| (Atom _ | Quoted_string _) as sexp -> of_sexp_error sexp "List expected"
|
||||
| List (_, l) -> List.map l ~f
|
||||
|
||||
let array f sexp = Array.of_list (list f sexp)
|
||||
|
@ -292,7 +292,7 @@ module Of_sexp = struct
|
|||
|
||||
let make_record_parser_state sexp =
|
||||
match sexp with
|
||||
| Atom _ | String _ -> of_sexp_error sexp "List expected"
|
||||
| Atom _ | Quoted_string _ -> of_sexp_error sexp "List expected"
|
||||
| List (loc, sexps) ->
|
||||
let unparsed =
|
||||
List.fold_left sexps ~init:Name_map.empty ~f:(fun acc sexp ->
|
||||
|
@ -301,7 +301,7 @@ module Of_sexp = struct
|
|||
Name_map.add acc ~key:name ~data:{ value = None; entry = sexp }
|
||||
| List (_, [name_sexp; value]) -> begin
|
||||
match name_sexp with
|
||||
| Atom (_, name) | String (_, name) ->
|
||||
| Atom (_, name) | Quoted_string (_, name) ->
|
||||
Name_map.add acc ~key:name ~data:{ value = Some value;
|
||||
entry = sexp }
|
||||
| List _ ->
|
||||
|
@ -410,7 +410,7 @@ module Of_sexp = struct
|
|||
|
||||
let sum cstrs sexp =
|
||||
match sexp with
|
||||
| Atom (loc, s) | String (loc, s) -> begin
|
||||
| Atom (loc, s) | Quoted_string (loc, s) -> begin
|
||||
match find_cstr cstrs sexp s with
|
||||
| C.Tuple t -> Constructor_args_spec.convert t.args t.rest sexp [] (t.make loc)
|
||||
| C.Record _ -> of_sexp_error sexp "'%s' expect arguments"
|
||||
|
@ -419,7 +419,7 @@ module Of_sexp = struct
|
|||
| List (loc, name_sexp :: args) ->
|
||||
match name_sexp with
|
||||
| List _ -> of_sexp_error name_sexp "Atom expected"
|
||||
| Atom (_, s) | String (_, s) ->
|
||||
| Atom (_, s) | Quoted_string (_, s) ->
|
||||
match find_cstr cstrs sexp s with
|
||||
| C.Tuple t -> Constructor_args_spec.convert t.args t.rest sexp args (t.make loc)
|
||||
| C.Record r -> record r.parse (List (loc, args))
|
||||
|
@ -427,7 +427,7 @@ module Of_sexp = struct
|
|||
let enum cstrs sexp =
|
||||
match sexp with
|
||||
| List _ -> of_sexp_error sexp "Atom expected"
|
||||
| Atom (_, s) | String (_, s) ->
|
||||
| Atom (_, s) | Quoted_string (_, s) ->
|
||||
match
|
||||
List.find cstrs ~f:(fun (name, _) ->
|
||||
equal_cstr_name name s)
|
||||
|
|
|
@ -40,7 +40,7 @@ end with type sexp := t
|
|||
module Of_sexp : sig
|
||||
type ast = Ast.t =
|
||||
| Atom of Loc.t * string
|
||||
| String of Loc.t * string
|
||||
| Quoted_string of Loc.t * string
|
||||
| List of Loc.t * ast list
|
||||
|
||||
include Combinators with type 'a t = Ast.t -> 'a
|
||||
|
|
|
@ -70,7 +70,7 @@ let unquoted_var t =
|
|||
|
||||
let t : Sexp.Of_sexp.ast -> t = function
|
||||
| Atom(loc, s) -> of_string ~loc s
|
||||
| String(loc, s) ->
|
||||
| Quoted_string (loc, s) ->
|
||||
(* If [unquoted_var], then add [""] at the end (see [type t]). *)
|
||||
let t = of_string ~loc s in
|
||||
(match t.items with
|
||||
|
|
|
@ -344,7 +344,7 @@ let push_quoted_atom state _char stack =
|
|||
Buffer.clear state.atom_buffer;
|
||||
let stack =
|
||||
if state.ignoring = 0 then
|
||||
Sexp (String (make_loc state ~delta:1, str), stack)
|
||||
Sexp (Quoted_string (make_loc state ~delta:1, str), stack)
|
||||
else
|
||||
stack
|
||||
in
|
||||
|
|
|
@ -7,5 +7,5 @@ end
|
|||
|
||||
type t =
|
||||
| Atom of Loc.t * string
|
||||
| String of Loc.t * string
|
||||
| Quoted_string of Loc.t * string
|
||||
| List of Loc.t * t list
|
||||
|
|
|
@ -87,20 +87,20 @@ end
|
|||
|
||||
type t =
|
||||
| Atom of string
|
||||
| String of string
|
||||
| Quoted_string of string
|
||||
| List of t list
|
||||
|
||||
type sexp = t
|
||||
|
||||
let rec to_string = function
|
||||
| Atom s -> Atom.serialize s
|
||||
| String s -> Atom.quote s
|
||||
| Quoted_string s -> Atom.quote s
|
||||
| List l -> Printf.sprintf "(%s)" (List.map l ~f:to_string |> String.concat ~sep:" ")
|
||||
|
||||
let rec pp ppf = function
|
||||
| Atom s ->
|
||||
Format.pp_print_string ppf (Atom.serialize s)
|
||||
| String s ->
|
||||
| Quoted_string s ->
|
||||
Format.pp_print_string ppf (Atom.serialize s)
|
||||
| List [] ->
|
||||
Format.pp_print_string ppf "()"
|
||||
|
@ -128,7 +128,7 @@ let split_string s ~on =
|
|||
loop 0 0
|
||||
|
||||
let rec pp_split_strings ppf = function
|
||||
| Atom s | String s ->
|
||||
| Atom s | Quoted_string s ->
|
||||
if Atom.must_escape s then begin
|
||||
if String.contains s '\n' then begin
|
||||
match split_string s ~on:'\n' with
|
||||
|
@ -204,14 +204,14 @@ module Loc = Sexp_ast.Loc
|
|||
module Ast = struct
|
||||
type t = Sexp_ast.t =
|
||||
| Atom of Loc.t * string
|
||||
| String of Loc.t * string
|
||||
| Quoted_string of Loc.t * string
|
||||
| List of Loc.t * t list
|
||||
|
||||
let loc (Atom (loc, _) | String (loc, _) | List (loc, _)) = loc
|
||||
let loc (Atom (loc, _) | Quoted_string (loc, _) | List (loc, _)) = loc
|
||||
|
||||
let rec remove_locs : t -> sexp = function
|
||||
| Atom (_, s) -> Atom s
|
||||
| String (_, s) -> String s
|
||||
| Quoted_string (_, s) -> Quoted_string s
|
||||
| List (_, l) -> List (List.map l ~f:remove_locs)
|
||||
|
||||
module Token = struct
|
||||
|
@ -226,7 +226,7 @@ module Ast = struct
|
|||
let rec loop acc t =
|
||||
match t with
|
||||
| Atom (loc, s) -> Token.Atom (loc, s) :: acc
|
||||
| String (loc, s) -> Token.String (loc, s) :: acc
|
||||
| Quoted_string (loc, s) -> Token.String (loc, s) :: acc
|
||||
| List (loc, l) ->
|
||||
let shift (pos : Lexing.position) delta =
|
||||
{ pos with pos_cnum = pos.pos_cnum + delta }
|
||||
|
@ -244,7 +244,7 @@ end
|
|||
let rec add_loc t ~loc : Ast.t =
|
||||
match t with
|
||||
| Atom s -> Atom (loc, s)
|
||||
| String s -> String (loc, s)
|
||||
| Quoted_string s -> Quoted_string (loc, s)
|
||||
| List l -> List (loc, List.map l ~f:(add_loc ~loc))
|
||||
|
||||
module Parser = struct
|
||||
|
|
|
@ -24,7 +24,7 @@ end
|
|||
(** The S-expression type *)
|
||||
type t =
|
||||
| Atom of Atom.t
|
||||
| String of string (** Quoted string *)
|
||||
| Quoted_string of string
|
||||
| List of t list
|
||||
|
||||
(** Serialize a S-expression *)
|
||||
|
@ -47,7 +47,7 @@ module Ast : sig
|
|||
type sexp = t
|
||||
type t =
|
||||
| Atom of Loc.t * Atom.t
|
||||
| String of Loc.t * string (** Quoted string *)
|
||||
| Quoted_string of Loc.t * string
|
||||
| List of Loc.t * t list
|
||||
|
||||
val loc : t -> Loc.t
|
||||
|
|
Loading…
Reference in New Issue