Skip to content

Commit

Permalink
Factor Intlit expansion code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Rebours committed Dec 4, 2018
1 parent 6d5f46e commit d881658
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/expression.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ open Ppxlib

let expand_string ~loc s = [%expr `String [%e Ast_builder.Default.estring ~loc s]]

let expand_intlit ~loc s = [%expr `Intlit [%e Ast_builder.Default.estring ~loc s]]

let expand_int ~loc ~pexp_loc s =
match Ocaml_compat.int_of_string_opt s with
| Some i -> [%expr `Int [%e Ast_builder.Default.eint ~loc i]]
| None when Integer_const.is_binary s -> Raise.unsupported_payload ~loc:pexp_loc
| None when Integer_const.is_octal s -> Raise.unsupported_payload ~loc:pexp_loc
| None when Integer_const.is_hexadecimal s -> Raise.unsupported_payload ~loc:pexp_loc
| None -> [%expr `Intlit [%e Ast_builder.Default.estring ~loc s]]

let expand_intlit ~loc s = [%expr `Intlit [%e Ast_builder.Default.estring ~loc s]]
| None -> expand_intlit ~loc s

let expand_float ~loc s = [%expr `Float [%e Ast_builder.Default.efloat ~loc s]]

Expand Down
6 changes: 3 additions & 3 deletions lib/pattern.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ open Ppxlib

let expand_string ~loc s = [%pat? `String [%p Ast_builder.Default.pstring ~loc s]]

let expand_intlit ~loc s = [%pat? `Intlit [%p Ast_builder.Default.pstring ~loc s]]

let expand_int ~loc ~ppat_loc s =
match Ocaml_compat.int_of_string_opt s with
| Some i -> [%pat? `Int [%p Ast_builder.Default.pint ~loc i]]
| None when Integer_const.is_binary s -> Raise.unsupported_payload ~loc:ppat_loc
| None when Integer_const.is_octal s -> Raise.unsupported_payload ~loc:ppat_loc
| None when Integer_const.is_binary s -> Raise.unsupported_payload ~loc:ppat_loc
| None -> [%pat? `Intlit [%p Ast_builder.Default.pstring ~loc s]]

let expand_intlit ~loc s = [%pat? `Intlit [%p Ast_builder.Default.pstring ~loc s]]
| None -> expand_intlit ~loc s

let expand_float ~loc s = [%pat? `Float [%p Ast_builder.Default.pfloat ~loc s]]

Expand Down

0 comments on commit d881658

Please sign in to comment.