Merge branch 'feature/literal-bytes-again' into 'dev'
Fix literal bytes See merge request ligolang/ligo!325
This commit is contained in:
commit
8a683e1a69
@ -145,7 +145,7 @@ let proj_token = function
|
|||||||
| Bytes Region.{region; value = s,b} ->
|
| Bytes Region.{region; value = s,b} ->
|
||||||
region,
|
region,
|
||||||
sprintf "Bytes (\"%s\", \"0x%s\")"
|
sprintf "Bytes (\"%s\", \"0x%s\")"
|
||||||
s (Hex.to_string b)
|
s (Hex.show b)
|
||||||
| Begin region -> region, "Begin"
|
| Begin region -> region, "Begin"
|
||||||
| Else region -> region, "Else"
|
| Else region -> region, "Else"
|
||||||
| End region -> region, "End"
|
| End region -> region, "End"
|
||||||
@ -378,7 +378,7 @@ let mk_string lexeme region =
|
|||||||
|
|
||||||
let mk_bytes lexeme region =
|
let mk_bytes lexeme region =
|
||||||
let norm = Str.(global_replace (regexp "_") "" lexeme) in
|
let norm = Str.(global_replace (regexp "_") "" lexeme) in
|
||||||
let value = lexeme, Hex.of_string norm
|
let value = lexeme, `Hex norm
|
||||||
in Bytes Region.{region; value}
|
in Bytes Region.{region; value}
|
||||||
|
|
||||||
let mk_int lexeme region =
|
let mk_int lexeme region =
|
||||||
|
@ -105,7 +105,7 @@ let print_bytes state {region; value} =
|
|||||||
let line =
|
let line =
|
||||||
sprintf "%s: Bytes (\"%s\", \"0x%s\")\n"
|
sprintf "%s: Bytes (\"%s\", \"0x%s\")\n"
|
||||||
(compact state region) lexeme
|
(compact state region) lexeme
|
||||||
(Hex.to_string abstract)
|
(Hex.show abstract)
|
||||||
in Buffer.add_string state#buffer line
|
in Buffer.add_string state#buffer line
|
||||||
|
|
||||||
let print_int state {region; value} =
|
let print_int state {region; value} =
|
||||||
@ -712,7 +712,7 @@ and pp_ne_injection :
|
|||||||
|
|
||||||
and pp_bytes state {value=lexeme,hex; region} =
|
and pp_bytes state {value=lexeme,hex; region} =
|
||||||
pp_loc_node (state#pad 2 0) lexeme region;
|
pp_loc_node (state#pad 2 0) lexeme region;
|
||||||
pp_node (state#pad 2 1) (Hex.to_string hex)
|
pp_node (state#pad 2 1) (Hex.show hex)
|
||||||
|
|
||||||
and pp_int state {value=lexeme,z; region} =
|
and pp_int state {value=lexeme,z; region} =
|
||||||
pp_loc_node (state#pad 2 0) lexeme region;
|
pp_loc_node (state#pad 2 0) lexeme region;
|
||||||
|
@ -126,7 +126,7 @@ let proj_token = function
|
|||||||
| Bytes Region.{region; value = s,b} ->
|
| Bytes Region.{region; value = s,b} ->
|
||||||
region,
|
region,
|
||||||
sprintf "Bytes (\"%s\", \"0x%s\")"
|
sprintf "Bytes (\"%s\", \"0x%s\")"
|
||||||
s (Hex.to_string b)
|
s (Hex.show b)
|
||||||
|
|
||||||
| Int Region.{region; value = s,n} ->
|
| Int Region.{region; value = s,n} ->
|
||||||
region, sprintf "Int (\"%s\", %s)" s (Z.to_string n)
|
region, sprintf "Int (\"%s\", %s)" s (Z.to_string n)
|
||||||
@ -443,7 +443,7 @@ let mk_string lexeme region = String Region.{region; value=lexeme}
|
|||||||
|
|
||||||
let mk_bytes lexeme region =
|
let mk_bytes lexeme region =
|
||||||
let norm = Str.(global_replace (regexp "_") "" lexeme) in
|
let norm = Str.(global_replace (regexp "_") "" lexeme) in
|
||||||
let value = lexeme, Hex.of_string norm
|
let value = lexeme, `Hex norm
|
||||||
in Bytes Region.{region; value}
|
in Bytes Region.{region; value}
|
||||||
|
|
||||||
type int_err = Non_canonical_zero
|
type int_err = Non_canonical_zero
|
||||||
|
@ -90,7 +90,7 @@ let print_bytes state {region; value} =
|
|||||||
let line =
|
let line =
|
||||||
sprintf "%s: Bytes (\"%s\", \"0x%s\")\n"
|
sprintf "%s: Bytes (\"%s\", \"0x%s\")\n"
|
||||||
(compact state region) lexeme
|
(compact state region) lexeme
|
||||||
(Hex.to_string abstract)
|
(Hex.show abstract)
|
||||||
in Buffer.add_string state#buffer line
|
in Buffer.add_string state#buffer line
|
||||||
|
|
||||||
let print_int state {region; value} =
|
let print_int state {region; value} =
|
||||||
@ -1093,7 +1093,7 @@ and pp_pattern state = function
|
|||||||
|
|
||||||
and pp_bytes state {value=lexeme,hex; region} =
|
and pp_bytes state {value=lexeme,hex; region} =
|
||||||
pp_loc_node (state#pad 2 0) lexeme region;
|
pp_loc_node (state#pad 2 0) lexeme region;
|
||||||
pp_node (state#pad 2 1) (Hex.to_string hex)
|
pp_node (state#pad 2 1) (Hex.show hex)
|
||||||
|
|
||||||
and pp_int state {value=lexeme,z; region} =
|
and pp_int state {value=lexeme,z; region} =
|
||||||
pp_loc_node (state#pad 2 0) lexeme region;
|
pp_loc_node (state#pad 2 0) lexeme region;
|
||||||
|
@ -140,7 +140,7 @@ let proj_token = function
|
|||||||
| Bytes Region.{region; value = s,b} ->
|
| Bytes Region.{region; value = s,b} ->
|
||||||
region,
|
region,
|
||||||
sprintf "Bytes (\"%s\", \"0x%s\")"
|
sprintf "Bytes (\"%s\", \"0x%s\")"
|
||||||
s (Hex.to_string b)
|
s (Hex.show b)
|
||||||
| Else region -> region, "Else"
|
| Else region -> region, "Else"
|
||||||
| False region -> region, "False"
|
| False region -> region, "False"
|
||||||
| If region -> region, "If"
|
| If region -> region, "If"
|
||||||
@ -361,7 +361,7 @@ let mk_string lexeme region = String Region.{region; value=lexeme}
|
|||||||
|
|
||||||
let mk_bytes lexeme region =
|
let mk_bytes lexeme region =
|
||||||
let norm = Str.(global_replace (regexp "_") "" lexeme) in
|
let norm = Str.(global_replace (regexp "_") "" lexeme) in
|
||||||
let value = lexeme, Hex.of_string norm
|
let value = lexeme, `Hex norm
|
||||||
in Bytes Region.{region; value}
|
in Bytes Region.{region; value}
|
||||||
|
|
||||||
let mk_int lexeme region =
|
let mk_int lexeme region =
|
||||||
|
@ -356,7 +356,7 @@ let rec simpl_expression :
|
|||||||
return @@ e_literal ~loc Literal_unit
|
return @@ e_literal ~loc Literal_unit
|
||||||
| EBytes x ->
|
| EBytes x ->
|
||||||
let (x , loc) = r_split x in
|
let (x , loc) = r_split x in
|
||||||
return @@ e_literal ~loc (Literal_bytes (Bytes.of_string @@ fst x))
|
return @@ e_literal ~loc (Literal_bytes (Hex.to_bytes @@ snd x))
|
||||||
| ETuple tpl -> simpl_tuple_expression @@ (npseq_to_list tpl.value)
|
| ETuple tpl -> simpl_tuple_expression @@ (npseq_to_list tpl.value)
|
||||||
| ERecord r ->
|
| ERecord r ->
|
||||||
let (r , loc) = r_split r in
|
let (r , loc) = r_split r in
|
||||||
|
@ -326,7 +326,7 @@ let rec simpl_expression (t:Raw.expr) : expr result =
|
|||||||
return @@ e_literal ~loc Literal_unit
|
return @@ e_literal ~loc Literal_unit
|
||||||
| EBytes x ->
|
| EBytes x ->
|
||||||
let (x' , loc) = r_split x in
|
let (x' , loc) = r_split x in
|
||||||
return @@ e_literal ~loc (Literal_bytes (Bytes.of_string @@ fst x'))
|
return @@ e_literal ~loc (Literal_bytes (Hex.to_bytes @@ snd x'))
|
||||||
| ETuple tpl ->
|
| ETuple tpl ->
|
||||||
let (tpl' , loc) = r_split tpl in
|
let (tpl' , loc) = r_split tpl in
|
||||||
simpl_tuple_expression ~loc @@ npseq_to_list tpl'.inside
|
simpl_tuple_expression ~loc @@ npseq_to_list tpl'.inside
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
function concat_op (const s : bytes) : bytes is
|
function concat_op (const s : bytes) : bytes is
|
||||||
begin skip end with bytes_concat(s , ("7070" : bytes))
|
begin skip end with bytes_concat(s , 0x7070)
|
||||||
|
|
||||||
function slice_op (const s : bytes) : bytes is
|
function slice_op (const s : bytes) : bytes is
|
||||||
begin skip end with bytes_slice(1n , 2n , s)
|
begin skip end with bytes_slice(1n , 2n , s)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
let concat_op (s : bytes) : bytes =
|
let concat_op (s : bytes) : bytes =
|
||||||
Bytes.concat s ("7070" : bytes)
|
Bytes.concat s 0x7070
|
||||||
|
|
||||||
let slice_op (s : bytes) : bytes =
|
let slice_op (s : bytes) : bytes =
|
||||||
Bytes.slice 1n 2n s
|
Bytes.slice 1n 2n s
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
let concat_op = (s: bytes): bytes => Bytes.concat(s, "7070": bytes);
|
let concat_op = (s: bytes): bytes => Bytes.concat(s, 0x7070);
|
||||||
|
|
||||||
let slice_op = (s: bytes): bytes => Bytes.slice(1n, 2n, s);
|
let slice_op = (s: bytes): bytes => Bytes.slice(1n, 2n, s);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user