Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suffix reserved names with underscore. #3

Merged
merged 1 commit into from
May 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions piqic-ocaml/piqic_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,22 @@ let flag_cc = ref false
let flag_gen_preserve_unknown_fields = ref false


let ocaml_reserved = Hashtbl.create 83
let () = Array.iter (fun n -> Hashtbl.add ocaml_reserved n ())
[|"and"; "as"; "assert"; "asr"; "begin"; "class";
"constraint"; "do"; "done"; "downto"; "else"; "end";
"exception"; "external"; "false"; "for"; "fun"; "function";
"functor"; "if"; "in"; "include"; "inherit"; "initializer";
"land"; "lazy"; "let"; "lor"; "lsl"; "lsr";
"lxor"; "match"; "method"; "mod"; "module"; "mutable";
"new"; "object"; "of"; "open"; "or"; "private";
"rec"; "sig"; "struct"; "then"; "to"; "true";
"try"; "type"; "val"; "virtual"; "when"; "while";
"with"|]

(* ocaml name of piqi name *)
let ocaml_name n =
if Hashtbl.mem ocaml_reserved n then n ^ "_" else
let n =
if !flag_normalize_names
then U.normalize_name n
Expand Down
5 changes: 5 additions & 0 deletions piqic-ocaml/piqic_ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ let arg__normalize_names =
"--normalize-names", Arg.Bool (fun x -> C.flag_normalize_names := x),
"true|false turn CamlCase-style names into \"camel_case\" (default = true)"

let arg__reserved_name =
"--reserved-name", Arg.String (fun x -> Hashtbl.add Piqic_common.ocaml_reserved x ()),
"add a reserved name in addition to the standard OCaml keywords"

let arg__gen_defaults =
"--gen-defaults", Arg.Set flag_gen_defaults,
"(depreacted) always enabled: generate default value constructors for generated types"
Expand Down Expand Up @@ -201,6 +205,7 @@ let speclist = Piqi_compile.getopt_speclist @
[
Piqi_command.arg_C;
arg__normalize_names;
arg__reserved_name;
arg__pp;
arg__gen_defaults;
arg__gen_preserve_unknown_fields;
Expand Down