mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 03:35:30 -05:00
handle '\r` in CCSexpM (fixes #83)
This commit is contained in:
parent
89c63a5357
commit
269d4a7ba9
1 changed files with 8 additions and 6 deletions
|
|
@ -41,7 +41,7 @@ let _must_escape s =
|
||||||
for i = 0 to String.length s - 1 do
|
for i = 0 to String.length s - 1 do
|
||||||
let c = String.unsafe_get s i in
|
let c = String.unsafe_get s i in
|
||||||
match c with
|
match c with
|
||||||
| ' ' | ';' | ')' | '(' | '"' | '\\' | '\n' | '\t' -> raise Exit
|
| ' ' | ';' | ')' | '(' | '"' | '\\' | '\n' | '\t' | '\r' -> raise Exit
|
||||||
| _ when Char.code c > 127 -> raise Exit (* non-ascii *)
|
| _ when Char.code c > 127 -> raise Exit (* non-ascii *)
|
||||||
| _ -> ()
|
| _ -> ()
|
||||||
done;
|
done;
|
||||||
|
|
@ -176,11 +176,11 @@ module MakeDecode(M : MONAD) = struct
|
||||||
let rec expr k t =
|
let rec expr k t =
|
||||||
if t.i = t.len then _refill t (expr k) _error_eof
|
if t.i = t.len then _refill t (expr k) _error_eof
|
||||||
else match _get t with
|
else match _get t with
|
||||||
| ' ' | '\t' | '\n' -> expr k t
|
| ' ' | '\t' | '\r' | '\n' -> expr k t
|
||||||
| c -> expr_starting_with c k t
|
| c -> expr_starting_with c k t
|
||||||
|
|
||||||
and expr_starting_with c k t = match c with
|
and expr_starting_with c k t = match c with
|
||||||
| ' ' | '\t' | '\n' -> assert false
|
| ' ' | '\t' | '\r' | '\n' -> assert false
|
||||||
| ';' -> skip_comment (fun _ () -> expr k t) t
|
| ';' -> skip_comment (fun _ () -> expr k t) t
|
||||||
| '(' -> expr_list [] k t
|
| '(' -> expr_list [] k t
|
||||||
| ')' -> _error t "unexpected ')'"
|
| ')' -> _error t "unexpected ')'"
|
||||||
|
|
@ -194,7 +194,7 @@ module MakeDecode(M : MONAD) = struct
|
||||||
and expr_list acc k t =
|
and expr_list acc k t =
|
||||||
if t.i = t.len then _refill t (expr_list acc k) _error_eof
|
if t.i = t.len then _refill t (expr_list acc k) _error_eof
|
||||||
else match _get t with
|
else match _get t with
|
||||||
| ' ' | '\t' | '\n' -> expr_list acc k t
|
| ' ' | '\t' | '\r' | '\n' -> expr_list acc k t
|
||||||
| ')' -> k None (`List (List.rev acc))
|
| ')' -> k None (`List (List.rev acc))
|
||||||
| c ->
|
| c ->
|
||||||
expr_starting_with c
|
expr_starting_with c
|
||||||
|
|
@ -216,7 +216,7 @@ module MakeDecode(M : MONAD) = struct
|
||||||
else match _get t with
|
else match _get t with
|
||||||
| '\\' -> _error t "unexpected '\\' in non-quoted string"
|
| '\\' -> _error t "unexpected '\\' in non-quoted string"
|
||||||
| '"' -> _error t "unexpected '\"' in the middle of an atom"
|
| '"' -> _error t "unexpected '\"' in the middle of an atom"
|
||||||
| (' ' | '\n' | '\t' | '(' | ')') as c ->
|
| (' ' | '\r' | '\n' | '\t' | '(' | ')') as c ->
|
||||||
_return_atom (Some c) k t
|
_return_atom (Some c) k t
|
||||||
| c ->
|
| c ->
|
||||||
Buffer.add_char t.atom c;
|
Buffer.add_char t.atom c;
|
||||||
|
|
@ -277,7 +277,7 @@ module MakeDecode(M : MONAD) = struct
|
||||||
if t.i = t.len
|
if t.i = t.len
|
||||||
then _refill t (expr_or_end k) (fun _ -> M.return `End)
|
then _refill t (expr_or_end k) (fun _ -> M.return `End)
|
||||||
else match _get t with
|
else match _get t with
|
||||||
| ' ' | '\t' | '\n' -> expr_or_end k t
|
| ' ' | '\t' | '\r' | '\n' -> expr_or_end k t
|
||||||
| c -> expr_starting_with c k t
|
| c -> expr_starting_with c k t
|
||||||
|
|
||||||
(* entry point *)
|
(* entry point *)
|
||||||
|
|
@ -308,6 +308,8 @@ let parse_string s : t or_error =
|
||||||
(*$T
|
(*$T
|
||||||
CCError.to_opt (parse_string "(abc d/e/f \"hello \\\" () world\" )") <> None
|
CCError.to_opt (parse_string "(abc d/e/f \"hello \\\" () world\" )") <> None
|
||||||
CCError.to_opt (parse_string "(abc ( d e ffff ) \"hello/world\")") <> None
|
CCError.to_opt (parse_string "(abc ( d e ffff ) \"hello/world\")") <> None
|
||||||
|
(parse_string "(abc\r\n ( d e \r\tffff ))") \
|
||||||
|
= `Ok (`List [`Atom "abc"; `List [`Atom "d"; `Atom "e"; `Atom "ffff"]])
|
||||||
*)
|
*)
|
||||||
|
|
||||||
(*$inject
|
(*$inject
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue