Skip to content

Commit

Permalink
Change syntax for set membership predicate
Browse files Browse the repository at this point in the history
Before: `ELEMENT in SET`; now: `SET contains ELEMENT`

Using the `in` keyword was causing conflicts and blocking #203.
Current proposal has `contient` for the French syntax, and is untranslated (`contains`) for Polish.
  • Loading branch information
AltGr committed Jul 27, 2022
1 parent 922b77a commit 6d41818
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 63 deletions.
7 changes: 7 additions & 0 deletions compiler/surface/lexer.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ module R = Re.Pcre
#ifndef MR_COLLECTION
#define MR_COLLECTION MS_COLLECTION
#endif
#ifndef MR_CONTAINS
#define MR_CONTAINS MS_CONTAINS
#endif
#ifndef MR_ENUM
#define MR_ENUM MS_ENUM
#endif
Expand Down Expand Up @@ -270,6 +273,7 @@ let token_list : (string * token) list =
(MS_INCREASING, INCREASING);
(MS_OF, OF);
(MS_COLLECTION, COLLECTION);
(MS_CONTAINS, CONTAINS);
(MS_ENUM, ENUM);
(MS_INTEGER, INTEGER);
(MS_MONEY, MONEY);
Expand Down Expand Up @@ -410,6 +414,9 @@ let rec lex_code (lexbuf : lexbuf) : token =
| MR_COLLECTION ->
L.update_acc lexbuf;
COLLECTION
| MR_CONTAINS ->
L.update_acc lexbuf;
CONTAINS
| MR_ENUM ->
L.update_acc lexbuf;
ENUM
Expand Down
1 change: 1 addition & 0 deletions compiler/surface/lexer_en.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define MS_INCREASING "increasing"
#define MS_OF "of"
#define MS_COLLECTION "collection"
#define MS_CONTAINS "contains"
#define MS_ENUM "enumeration"
#define MS_INTEGER "integer"
#define MS_MONEY "money"
Expand Down
1 change: 1 addition & 0 deletions compiler/surface/lexer_fr.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define MS_INCREASING "croissant"
#define MS_OF "de"
#define MS_COLLECTION "collection"
#define MS_CONTAINS "contient"
#define MS_ENUM "énumération"
#define MR_ENUM 0xE9, "num", 0xE9, "ration"
#define MS_INTEGER "entier"
Expand Down
1 change: 1 addition & 0 deletions compiler/surface/lexer_pl.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define MS_INCREASING "rosnacy"
#define MS_OF "z"
#define MS_COLLECTION "kolekcja"
#define MS_CONTAINS "contains"
#define MS_ENUM "enumeracja"
#define MS_INTEGER "calkowita"
#define MS_MONEY "pieniądze"
Expand Down
105 changes: 46 additions & 59 deletions compiler/surface/parser.messages

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions compiler/surface/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ base_expression:
| e = primitive_expression WITH c = constructor_binding {
(TestMatchCase (e, (c, Pos.from_lpos $sloc)), Pos.from_lpos $sloc)
}
| e1 = primitive_expression IN e2 = base_expression {
(MemCollection (e1, e2), Pos.from_lpos $sloc)
| e1 = base_expression CONTAINS e2 = primitive_expression {
(MemCollection (e2, e1), Pos.from_lpos $sloc)
}

unop:
Expand Down
2 changes: 1 addition & 1 deletion compiler/surface/tokens.mly
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
%token<string * string> MONEY_AMOUNT
%token BEGIN_CODE TEXT
%token COLON ALT DATA VERTICAL
%token OF INTEGER COLLECTION
%token OF INTEGER COLLECTION CONTAINS
%token RULE CONDITION DEFINED_AS
%token LESSER GREATER LESSER_EQUAL GREATER_EQUAL
%token LESSER_DEC GREATER_DEC LESSER_EQUAL_DEC GREATER_EQUAL_DEC
Expand Down
2 changes: 1 addition & 1 deletion tests/test_array/good/simple.catala_en
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ declaration scope B:

scope B:
definition v equals number of a.x
definition w equals 64 in a.x
definition w equals a.x contains 64
definition y equals exists m in a.x such that m = 9
definition z equals for all m in a.x we have m > 0
```
Expand Down

0 comments on commit 6d41818

Please sign in to comment.