Skip to content
Snippets Groups Projects
Commit 1844a78e authored by Ralf Jung's avatar Ralf Jung
Browse files

Merge branch 'robbert/string_notation' into 'master'

Notation for string literals in `stdpp_scope`.

See merge request !568
parents 80267a5e 1c845125
Branches
Tags
1 merge request!568Notation for string literals in `stdpp_scope`.
Pipeline #106649 passed
...@@ -43,6 +43,8 @@ API-breaking change is listed. ...@@ -43,6 +43,8 @@ API-breaking change is listed.
strengthened to only require commutativity w.r.t. the operation being strengthened to only require commutativity w.r.t. the operation being
pulled out of the accumulator, not commutativity of pulled out of the accumulator, not commutativity of
the folded function itself. the folded function itself.
- Add string literal notation "my string" to `std_scope`, and no longer globally
open `string_scope`.
The following `sed` script should perform most of the renaming The following `sed` script should perform most of the renaming
(on macOS, replace `sed` by `gsed`, installed via e.g. `brew install gnu-sed`). (on macOS, replace `sed` by `gsed`, installed via e.g. `brew install gnu-sed`).
......
...@@ -4,15 +4,16 @@ From stdpp Require Export list. ...@@ -4,15 +4,16 @@ From stdpp Require Export list.
From stdpp Require Import countable. From stdpp Require Import countable.
From stdpp Require Import options. From stdpp Require Import options.
(* To avoid randomly ending up with String.length because this module is (** To avoid randomly ending up with [String.length] because this module is
imported hereditarily somewhere. *) imported hereditarily somewhere. *)
Notation length := List.length. Notation length := List.length.
(** * Fix scopes *) (** Enable the string literal and append notation in [stdpp_scope], making it
Global Open Scope string_scope. possible to write string literals as "foo" instead of "foo"%string.
(* Make sure [list_scope] has priority over [string_scope], so that One could also enable the string literal notation via [Open Scope string_scope]
the "++" notation designates list concatenation. *) but that overrides various notations (e.g, [++] on [list], [=?] on [nat]) with
Global Open Scope list_scope. the version for strings. *)
String Notation string string_of_list_byte list_byte_of_string : stdpp_scope.
Infix "+:+" := String.append (at level 60, right associativity) : stdpp_scope. Infix "+:+" := String.append (at level 60, right associativity) : stdpp_scope.
Global Arguments String.append : simpl never. Global Arguments String.append : simpl never.
......
"foo"
: string
10 =? 10
: bool
[10] ++ [12]
: list nat
"foo" +:+ "bar"
: string
From stdpp Require Import strings.
(** Check that the string notation works without [%string]. *)
Check "foo".
(** Check that importing [strings] does not override notations for [nat] and
[list]. *)
Check (10 =? 10).
Check ([10] ++ [12]).
(** Check that append on strings is pretty printed correctly, and not as
[(_ ++ _)%string]. *)
Check ("foo" +:+ "bar").
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment