Dear OCaml community,
For pedagogical purposes, I would like to try to modify a local version of the ocaml/ocaml source code, and change the parser so that the final
ocaml (and hopefully
ocamlopt) commands accept to read OCaml code where (some of) the keywords are translated in French. (Let’s just focus at French for the example, as it would easily be generalized to other latin-based languages).
For instance, I would like to be able to read, execute and compile a tiny program like this:
soit récursive factorielle (n : entier) = filtrer n avec | n quand n < 0 -> échoueavec "Erreur : n doit être >= 0 pour factorielle." | 0 -> 1 | n -> n * (factorielle (n-1)) ;;
Accents are not important, if it’s hard to have them, I’ll settle down with no accents. Compare to the real (English) version:
let rec fact (n : int) = match n with | n when n < 0 -> failwith "Error: n has to be >= 0 for fact." | 0 -> 1 | n -> n * (fact (n-1)) ;;
I read the parsing Hacking guide, but don’t really understand what should be modified and where. I want the parser to accept both English (real) and French (new) versions of the keywords, as I don’t want to translate anything from the codebase, I just this new parser to accept tiny files where all key-words are in French.
My main question is to know which file to modify in the parsing/ folder, and how to accept two versions of a keyword and map both to the same
From what I see in the guide, I should update
parser.mly, but my old memories from mly/mll files tell me that a
%token LET "let" %token LET "soit"
will complain that
LET token is not unique…
Thanks in advance!