+let separate_chars =
- CSet.of_list [','; '('; ')'; ';']
(* A token_end array indicates the few chars which are separate tokens,
- even if not surrounded by spaces, such as '(', ')', and ';'.
- It also indicates which chars are "inner" operators, i.e. those chars
@@ -54,13 +57,10 @@ let find (name : string) (Grammar (ps) : t) : int option * int option = type char_kind = | CKnormal | CKseparate | CKinner of int type token_env = char_kind array let default_stt : token_env =
- let stt = Array.make 256 CKnormal
- in stt.(Char.code ';') <- CKseparate;
stt.(Char.code ',') <- CKseparate;
stt.(Char.code '(') <- CKseparate;
stt.(Char.code ')') <- CKseparate;
stt.(Char.code '.') <- CKinner 5;
stt
- let stt = Array.make 256 CKnormal in
- CSet.iter (fun c -> stt.(Char.code c) <- CKseparate) separate_chars;
- stt.(Char.code '.') <- CKinner 5;
- stt
(* default_grammar is auto-generated from typer-smie-grammar via:
===================================== src/sexp.ml ===================================== @@ -26,6 +26,17 @@ open Prelexer let sexp_error ?print_action loc fmt = Log.log_error ~section:"SEXP" ?print_action ~loc fmt
+(** Prints an identifier in a way that reading it back will yield the same
- identifier. Spaces, inner operators like ‘.’, and separate characters like
- ‘,’ are escaped. *)
+let pp_print_id (f : Format.formatter) (name : string) : unit =
- let pp_print_escaped_char c =
- if c = '.' || c = ' ' || CSet.mem c Grammar.separate_chars then
Hmm... I think there's also `%`, `{`, `}`, `"`, and all the other chars below 32. [ Ideally, Typer would also offer the possibility to modify the "stt", just like it offers to modify the precedence table. ]
Stefan