Skip to content

Commit 10e96d8

Browse files
committed
Turn all tokens as _case
1 parent 946cf0c commit 10e96d8

File tree

4 files changed

+54
-62
lines changed

4 files changed

+54
-62
lines changed

source/Ast.ml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type literal =
55
| Null (* null *)
66
[@@deriving show { with_path = false }]
77

8-
type builtin = Add | Abs [@@deriving show { with_path = false }]
8+
type builtin = Add | Absolute [@@deriving show { with_path = false }]
99

1010
type op =
1111
| Add
@@ -52,13 +52,13 @@ type expression =
5252
| All (* all *)
5353
| In of expression (* in *)
5454
| Recurse (* recurse *)
55-
| RecurseDown (* recurse_down *)
56-
| ToEntries (* to_entries *)
57-
| ToString (* to_string *)
58-
| FromEntries (* from_entries *)
59-
| WithEntries
55+
| Recurse_down (* recurse_down *)
56+
| To_entries (* to_entries *)
57+
| To_string (* to_string *)
58+
| From_entries (* from_entries *)
59+
| With_entries (* with_entries *)
6060
| Nan
61-
| IsNan
61+
| Is_nan
6262
(* Array *)
6363
| Index of int (* .[1] *)
6464
| Iterator (* .[] *)
@@ -71,16 +71,16 @@ type expression =
7171
(* map(x) *)
7272
| Slice of int option * int option
7373
(* slice(Some 1, Some 10), slice(None, Some 10), slice(Some 1, None) *)
74-
| FlatMap of expression (* flat_map(x) *)
74+
| Flat_map of expression (* flat_map(x) *)
7575
| Reduce of expression (* reduce(x) *)
7676
| Select of expression (* select(x) *)
77-
| SortBy of expression (* sort_by(x) *)
78-
| GroupBy of expression (* group_by(x) *)
79-
| UniqueBy of expression (* unique_by(x) *)
80-
| MinBy of expression (* min_by(x) *)
81-
| MaxBy of expression (* max_by(x) *)
82-
| AllWithCondition of expression (* all(c) *)
83-
| AnyWithCondition of expression (* any(c) *)
77+
| Sort_by of expression (* sort_by(x) *)
78+
| Group_by of expression (* group_by(x) *)
79+
| Unique_by of expression (* unique_by(x) *)
80+
| Min_by of expression (* min_by(x) *)
81+
| Max_by of expression (* max_by(x) *)
82+
| All_with_condition of expression (* all(c) *)
83+
| Any_with_condition of expression (* any(c) *)
8484
| Some_ of expression (* some, Some_ to not collide with option *)
8585
| Find of expression (* find(x) *)
8686
(* operations *)
@@ -91,14 +91,14 @@ type expression =
9191
(* Strings *)
9292
| Test of string
9393
(* this string is a regex, we could validate it in the parser and have a Regexp.t type here *)
94-
| ToNumber (* to_num *)
95-
| StartsWith of expression (* starts_with *)
96-
| EndsWith of expression (* ends_with *)
94+
| To_number (* to_num *)
95+
| Starts_with of expression (* starts_with *)
96+
| Ends_with of expression (* ends_with *)
9797
| Split of expression (* split *)
9898
| Join of expression (* join *)
9999
| Path of expression (* path(x) *)
100100
(* Logic *)
101-
| IfThenElse of
101+
| If_then_else of
102102
expression * expression * expression (* If then (elseif) else end *)
103103
| Break (* break *)
104104
(* Conditionals *)

source/Compiler.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ let rec compile expression json : (Json.t list, string) result =
390390
| Split expr -> split expr json
391391
| Join expr -> join expr json
392392
| Fun builtin -> builtin_functions builtin json
393-
| IfThenElse (cond, if_branch, else_branch) -> (
393+
| If_then_else (cond, if_branch, else_branch) -> (
394394
let* cond = compile cond json in
395395
match cond with
396396
| `Bool b ->
@@ -445,11 +445,11 @@ and objects list json =
445445

446446
and builtin_functions builtin json =
447447
match builtin with
448-
| Abs -> (
448+
| Absolute -> (
449449
match json with
450-
| `Int n -> Output.return (`Int (if n < 0 then -n else n))
451-
| `Float j -> Output.return (`Float (if j < 0. then -.j else j))
452-
| _ -> Error (make_error "reverse" json))
450+
| `Int n -> Output.return (`Int (abs n))
451+
| `Float j -> Output.return (`Float (abs_float j))
452+
| _ -> Error (make_error "absolute" json))
453453
| Add -> (
454454
match json with
455455
| `List [] -> Output.return `Null

source/Parser.mly

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -138,29 +138,29 @@ term:
138138
{ match f with
139139
| "filter" -> Map (Select cb) (* for backward compatibility *)
140140
| "map" -> Map cb
141-
| "flat_map" -> FlatMap cb
141+
| "flat_map" -> Flat_map cb
142142
| "select" -> Select cb
143-
| "sort_by" -> SortBy cb
144-
| "min_by" -> MinBy cb
145-
| "max_by" -> MaxBy cb
146-
| "group_by" -> GroupBy cb
147-
| "unique_by" -> UniqueBy cb
143+
| "sort_by" -> Sort_by cb
144+
| "min_by" -> Min_by cb
145+
| "max_by" -> Max_by cb
146+
| "group_by" -> Group_by cb
147+
| "unique_by" -> Unique_by cb
148148
| "find" -> Find cb
149149
| "some" -> Some_ cb
150150
| "path" -> Path cb
151-
| "any" -> AnyWithCondition cb
152-
| "all" -> AllWithCondition cb
151+
| "any" -> Any_with_condition cb
152+
| "all" -> All_with_condition cb
153153
| "walk" -> Walk cb
154154
| "transpose" -> Transpose cb
155155
| "has" -> Has cb
156156
| "in" -> In cb
157-
| "starts_with" -> StartsWith cb
158-
| "ends_with" -> EndsWith cb
157+
| "startswith" (* for backward compatibility *)
158+
| "starts_with" -> Starts_with cb
159+
| "endswith" (* for backward compatibility *)
160+
| "ends_with" -> Ends_with cb
159161
| "split" -> Split cb
160162
| "join" -> Join cb
161163
| "contains" -> Contains cb
162-
| "startswith" -> failwith @@ Console.Errors.renamed f "starts_with"
163-
| "endswith" -> failwith @@ Console.Errors.renamed f "ends_with"
164164
| _ -> failwith @@ Console.Errors.missing f
165165
}
166166
| f = IDENTIFIER;
@@ -171,44 +171,38 @@ term:
171171
| "head" -> Head
172172
| "tail" -> Tail
173173
| "length" -> Length
174-
| "to_string" -> ToString
175-
| "to_num" -> ToNumber
174+
| "tostring" (* for backward compatibility *)
175+
| "to_string" -> To_string
176+
| "tonumber" (* for backward compatibility *)
177+
| "to_num" -> To_number
176178
| "type" -> Type
177179
| "sort" -> Sort
178-
| "uniq" -> Unique
180+
| "uniq"
181+
| "unique" -> Unique
179182
| "reverse" -> Reverse
180183
| "floor" -> Floor
181184
| "sqrt" -> Sqrt
182185
| "min" -> Min
183186
| "max" -> Max
184-
| "unique" -> Unique
185187
| "explode" -> Explode
186188
| "implode" -> Implode
187189
| "any" -> Any
188190
| "all" -> All
189191
| "recurse" -> Recurse
190-
| "recurse_down" -> RecurseDown
191-
| "to_entries" -> ToEntries
192-
| "from_entries" -> FromEntries
193-
| "with_entries" -> WithEntries
192+
| "recurse_down" -> Recurse_down
193+
| "to_entries" -> To_entries
194+
| "from_entries" -> From_entries
195+
| "with_entries" -> With_entries
194196
| "nan" -> Nan
195-
| "is_nan" -> IsNan
197+
| "is_nan" -> Is_nan
196198
| "not" -> Not
197-
| "abs" -> Fun (Abs)
199+
| "abs" -> Fun (Absolute)
198200
| "add" -> Fun (Add)
199201
(* TODO: remove failwiths once we have implemented the functions *)
200-
| "if" -> failwith @@ Console.Errors.not_implemented f
201-
| "then" -> failwith @@ Console.Errors.not_implemented f
202-
| "else" -> failwith @@ Console.Errors.not_implemented f
203-
| "break" -> failwith @@ Console.Errors.not_implemented f
204-
(* TODO: remove failwiths once we have implemented the functions *)
205202
| "isnan" -> failwith @@ Console.Errors.renamed f "is_nan"
206-
| "reduce" -> failwith @@ Console.Errors.renamed f "reduce()"
207-
| "tonumber" -> failwith @@ Console.Errors.renamed f "to_number"
208203
| "isinfinite" -> failwith @@ Console.Errors.renamed f "is_infinite"
209204
| "isfinite" -> failwith @@ Console.Errors.renamed f "is_finite"
210205
| "isnormal" -> failwith @@ Console.Errors.renamed f "is_normal"
211-
| "tostring" -> failwith @@ Console.Errors.renamed f "to_string"
212206
| _ -> failwith @@ Console.Errors.missing f
213207
}
214208
| OPEN_BRACKET; CLOSE_BRACKET;
@@ -269,7 +263,7 @@ term:
269263
let rec fold_elif elifs else_branch =
270264
match elifs with
271265
| [] -> else_branch
272-
| (cond, branch) :: rest -> IfThenElse(cond, branch, fold_elif rest else_branch)
266+
| (cond, branch) :: rest -> If_then_else(cond, branch, fold_elif rest else_branch)
273267
in
274-
IfThenElse(cond, e1, fold_elif elifs e2)
268+
If_then_else(cond, e1, fold_elif elifs e2)
275269
}

test/Test_parse.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
let assert_string left right =
22
Alcotest.check Alcotest.string "should be equal" right left
33

4-
let debug = false
5-
64
let case input expected =
75
let fn () =
86
let result =
9-
match Core.parse ~debug input with
7+
match Core.parse ~debug:false input with
108
| Ok r -> r
119
| Error err -> Alcotest.fail err
1210
in
@@ -73,15 +71,15 @@ let tests =
7371
case "range(1;2)" (Range (1, Some 2, None));
7472
case "range(1;2;3)" (Range (1, Some 2, Some 3));
7573
case "if true then \"Hello\" else \"Welcome\" end"
76-
(IfThenElse
74+
(If_then_else
7775
( Literal (Bool true),
7876
Literal (String "Hello"),
7977
Literal (String "Welcome") ));
8078
case "if true then \"Hello\" elif false then \"Welcome\" else \"Real\" end"
81-
(IfThenElse
79+
(If_then_else
8280
( Literal (Bool true),
8381
Literal (String "Hello"),
84-
IfThenElse
82+
If_then_else
8583
( Literal (Bool false),
8684
Literal (String "Welcome"),
8785
Literal (String "Real") ) ));

0 commit comments

Comments
 (0)