24
24
25
25
26
26
(* *
27
- {[
28
- _open -> open
29
- _in -> in
30
- _MAX_LENGTH -> MAX_LENGTH
31
- _Capital -> Capital
32
-
33
- _open__ -> _open
34
- open__ -> open
35
-
36
- _'x -> 'x
27
+ {[
28
+ _open -> open
29
+ _in -> in
30
+ _MAX_LENGTH -> MAX_LENGTH
31
+ _Capital -> Capital
37
32
38
- _Capital__ -> _Capital
39
- _MAX__ -> _MAX
40
- __ -> __
41
- __x -> __x
42
- ___ -> _
43
- ____ -> __
44
- _ -> _ (* error *)
45
-
33
+ _open__ -> _open
34
+ open__ -> open
35
+
36
+ _'x -> 'x
37
+
38
+ _Capital__ -> _Capital
39
+ _MAX__ -> _MAX
40
+ __ -> __
41
+ __x -> __x
42
+ ___ -> _
43
+ ____ -> __
44
+ _ -> _ (* error *)
46
45
47
- ]}
48
- First we scan '__' from end to start,
49
- If found, discard it.
50
- Otherwise, check if it is [_ + keyword] or followed by capital letter,
51
- If so, discard [_].
52
46
53
- Limitations: user can not have [_Capital__, _Capital__other] to
54
- make it all compile to [Capital].
55
- Keyword is fine [open__, open__other].
56
- So we loose polymorphism over capital letter.
57
- It is okay, otherwise, if [_Captial__] is interpreted as [Capital], then
58
- there is no way to express [_Capital]
47
+ ]}
48
+ First we scan '__' from end to start,
49
+ If found, discard it.
50
+ Otherwise, check if it is [_ + keyword] or followed by capital letter,
51
+ If so, discard [_].
52
+
53
+ Limitations: user can not have [_Capital__, _Capital__other] to
54
+ make it all compile to [Capital].
55
+ Keyword is fine [open__, open__other].
56
+ So we loose polymorphism over capital letter.
57
+ It is okay, otherwise, if [_Captial__] is interpreted as [Capital], then
58
+ there is no way to express [_Capital]
59
59
*)
60
60
61
61
(* Copied from [ocaml/parsing/lexer.mll] *)
@@ -95,7 +95,7 @@ let key_words = Hash_set_string.of_array [|
95
95
" of" ;
96
96
" open" ;
97
97
" or" ;
98
- (* "parser", PARSER; *)
98
+ (* "parser", PARSER; *)
99
99
" private" ;
100
100
" rec" ;
101
101
" sig" ;
@@ -118,14 +118,14 @@ let key_words = Hash_set_string.of_array [|
118
118
" lsl" ;
119
119
" lsr" ;
120
120
" asr" ;
121
- |]
121
+ |]
122
122
let double_underscore = " __"
123
123
124
124
(* https://caml.inria.fr/pub/docs/manual-ocaml/lex.html
125
- {[
125
+ {[
126
126
127
- label-name ::= lowercase-ident
128
- ]}
127
+ label-name ::= lowercase-ident
128
+ ]}
129
129
*)
130
130
let valid_start_char x =
131
131
match x with
@@ -139,8 +139,8 @@ let translate name =
139
139
if name.[0 ] = '_' then begin
140
140
let try_key_word = (String. sub name 1 (name_len - 1 )) in
141
141
if name_len > 1 &&
142
- (not (valid_start_char try_key_word.[0 ])
143
- || Hash_set_string. mem key_words try_key_word) then
142
+ (not (valid_start_char try_key_word.[0 ])
143
+ || Hash_set_string. mem key_words try_key_word) then
144
144
try_key_word
145
145
else
146
146
name
0 commit comments