| 1 |
Require Import PrimInt63. |
| 2 |
|
| 3 |
Definition char63 := int. |
| 4 |
|
| 5 |
Primitive string := #string_type. |
| 6 |
|
| 7 |
Primitive max_length : int := #string_max_length. |
| 8 |
|
| 9 |
Primitive make : int -> char63 -> string := #string_make. |
| 10 |
|
| 11 |
Primitive length : string -> int := #string_length. |
| 12 |
|
| 13 |
Primitive get : string -> int -> char63 := #string_get. |
| 14 |
|
| 15 |
Primitive sub : string -> int -> int -> string := #string_sub. |
| 16 |
|
| 17 |
Primitive cat : string -> string -> string := #string_cat. |
| 18 |
|
| 19 |
Primitive compare : string -> string -> comparison := #string_compare. |
| 20 |
|
| 21 |
Definition eqb (s1 s2 : string) := match compare s1 s2 with |
| 22 |
| Eq => true |
| 23 |
| Lt | Gt => false |
| 24 |
end. |
| 25 |
|
| 26 |
Register eqb as strings.pstring.eqb. |
| 27 |
|
| 28 |
Module Export PStringNotations. |
| 29 |
Record string_wrapper := wrap_string {string_wrap : string}. |
| 30 |
Definition id_string (s : string) : string := s. |
| 31 |
Register string as strings.pstring.type. |
| 32 |
Register string_wrapper as strings.pstring.string_wrapper. |
| 33 |
Register wrap_string as strings.pstring.wrap_string. |
| 34 |
|
| 35 |
Declare Scope pstring_scope. |
| 36 |
Delimit Scope pstring_scope with pstring. |
| 37 |
Bind Scope pstring_scope with string. |
| 38 |
String Notation string id_string id_string : pstring_scope. |
| 39 |
End PStringNotations. |
| 40 |
|
| 41 |
Record char63_wrapper := wrap_char63 { char63_wrap : char63 }. |
| 42 |
|
| 43 |
Module Export Char63Notations. |
| 44 |
Coercion char63_wrap : char63_wrapper >-> char63. |
| 45 |
Definition parse (s : string) : option char63_wrapper := |
| 46 |
if PrimInt63.eqb (length s) 1%uint63 then Some (wrap_char63 (get s 0)) else None. |
| 47 |
Definition print (i : char63_wrapper) : option string := |
| 48 |
if PrimInt63.ltb i.(char63_wrap) 256%uint63 then Some (make 1 i.(char63_wrap)) else None. |
| 49 |
|
| 50 |
Declare Scope char63_scope. |
| 51 |
Delimit Scope char63_scope with char63. |
| 52 |
Bind Scope char63_scope with char63. |
| 53 |
String Notation char63_wrapper parse print : char63_scope. |
| 54 |
End Char63Notations. |