Skip to content

Commit dd4a887

Browse files
author
Shon Feder
authored
Merge pull request #1355 from informalsystems/1073/poly-types
Add support for parsing polymorphic type declarations
2 parents 5f28689 + eca5e83 commit dd4a887

28 files changed

+2263
-1617
lines changed

quint/package.json

+4-12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22
"name": "@informalsystems/quint",
33
"version": "0.18.1",
44
"description": "Core tool for the Quint specification language",
5-
"keywords": [
6-
"temporal",
7-
"logic",
8-
"formal",
9-
"specification",
10-
"verification"
11-
],
5+
"keywords": ["temporal", "logic", "formal", "specification", "verification"],
126
"homepage": "https://github.com/informalsystems/quint",
137
"bugs": "https://github.com/informalsystems/quint/issues",
148
"license": "Apache 2.0",
@@ -35,11 +29,7 @@
3529
"bin": {
3630
"quint": "dist/src/cli.js"
3731
},
38-
"files": [
39-
"README.md",
40-
"dist/**/*",
41-
"test/**/*.ts"
42-
],
32+
"files": ["README.md", "dist/**/*", "test/**/*.ts"],
4333
"engines": {
4434
"node": ">=18"
4535
},
@@ -72,6 +62,8 @@
7262
"compile": "genversion -e src/version.ts && tsc && copyfiles -u 1 ./src/reflection.proto ./src/builtin.qnt ./dist/src/",
7363
"prepare": "rm -rf ./dist && npm run compile && chmod +x ./dist/src/cli.js",
7464
"test": "mocha --reporter-option maxDiffSize=0 -r ts-node/register test/*.test.ts test/**/*.test.ts",
65+
"test-w": "while inotifywait -r -e close_write ./ ; do npm run test; done",
66+
"test-f": "mocha --reporter-option maxDiffSize=0 -r ts-node/register",
7567
"coverage": "nyc npm run test",
7668
"integration": "txm cli-tests.md && txm io-cli-tests.md",
7769
"apalache-integration": "txm apalache-tests.md",

quint/src/generated/Quint.g4

+29-21
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@ operDef : qualifier normalCallName
5252
;
5353

5454
typeDef
55-
: 'type' qualId # typeAbstractDef
56-
| 'type' qualId '=' type # typeAliasDef
57-
| 'type' typeName=qualId '=' '|'? typeSumVariant ('|' typeSumVariant)* # typeSumDef
55+
: 'type' qualId # typeAbstractDef
56+
| 'type' typeDefHead '=' type # typeAliasDef
57+
| 'type' typeDefHead '=' sumTypeDefinition # typeSumDef
5858
;
5959

60+
typeDefHead : typeName=qualId ('[' typeVars+=typeVar(',' typeVars+=typeVar)* ']')?;
61+
62+
sumTypeDefinition : '|'? typeSumVariant ('|' typeSumVariant)* ;
63+
6064
// A single variant case in a sum type definition or match statement.
6165
// E.g., `A(t)` or `A`.
6266
typeSumVariant : sumLabel=simpleId["variant label"] ('(' type ')')? ;
@@ -96,28 +100,32 @@ qualifiedName : qualId;
96100
fromSource: STRING;
97101

98102
// Types in Type System 1.2 of Apalache
99-
type : <assoc=right> type '->' type # typeFun
100-
| <assoc=right> type '=>' type # typeOper
101-
| '(' (type (',' type)*)? ','? ')' '=>' type # typeOper
102-
| SET '[' type ']' # typeSet
103-
| LIST '[' type ']' # typeList
104-
| '(' type ',' type (',' type)* ','? ')' # typeTuple
105-
| '{' row '}' # typeRec
106-
| 'int' # typeInt
107-
| 'str' # typeStr
108-
| 'bool' # typeBool
109-
| LOW_ID # typeVar
110-
| qualId # typeConst
111-
| '(' type ')' # typeParen
112-
;
103+
type
104+
: <assoc=right> type '->' type # typeFun
105+
| <assoc=right> type '=>' type # typeOper
106+
| '(' (type (',' type)*)? ','? ')' '=>' type # typeOper
107+
// TODO: replace Set with general type application
108+
| SET '[' type ']' # typeSet
109+
// TODO: replace List with general type application
110+
| LIST '[' type ']' # typeList
111+
| '(' type ',' type (',' type)* ','? ')' # typeTuple
112+
| '{' row? '}' # typeRec
113+
| 'int' # typeInt
114+
| 'str' # typeStr
115+
| 'bool' # typeBool
116+
| typeVar # typeVarCase
117+
| qualId # typeConst
118+
| '(' type ')' # typeParen
119+
| typeCtor=type ('[' typeArg+=type (',' typeArg+=type)* ']') # typeApp
120+
;
113121

114-
row : (rowLabel ':' type ',')* ((rowLabel ':' type) (',' | '|' (rowVar=identifier))?)?
122+
typeVar: LOW_ID;
123+
row : (rowLabel ':' type) (',' rowLabel ':' type)* (',' | '|' (rowVar=identifier))?
115124
| '|' (rowVar=identifier)
116125
;
117126

118127
rowLabel : simpleId["record"] ;
119128

120-
121129
// A Quint expression. The order matters, it defines the priority.
122130
// Wherever possible, we keep the same order of operators as in TLA+.
123131
// We are also trying to be consistent with mainstream languages, e.g.,
@@ -269,8 +277,6 @@ AND : 'and' ;
269277
OR : 'or' ;
270278
IFF : 'iff' ;
271279
IMPLIES : 'implies' ;
272-
SET : 'Set' ;
273-
LIST : 'List' ;
274280
MAP : 'Map' ;
275281
MATCH : 'match' ;
276282
PLUS : '+' ;
@@ -287,6 +293,8 @@ EQ : '==' ;
287293
ASGN : '=' ;
288294
LPAREN : '(' ;
289295
RPAREN : ')' ;
296+
SET : 'Set';
297+
LIST : 'List';
290298

291299
// An identifier starting with lowercase
292300
LOW_ID : ([a-z][a-zA-Z0-9_]*|[_][a-zA-Z0-9_]+) ;

quint/src/generated/Quint.interp

+10-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quint/src/generated/Quint.tokens

+53-53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quint/src/generated/QuintLexer.interp

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quint/src/generated/QuintLexer.tokens

+53-53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)