Skip to content

Commit

Permalink
Merge pull request #1355 from informalsystems/1073/poly-types
Browse files Browse the repository at this point in the history
Add support for parsing polymorphic type declarations
  • Loading branch information
Shon Feder authored Jan 26, 2024
2 parents 5f28689 + eca5e83 commit dd4a887
Show file tree
Hide file tree
Showing 28 changed files with 2,263 additions and 1,617 deletions.
16 changes: 4 additions & 12 deletions quint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
"name": "@informalsystems/quint",
"version": "0.18.1",
"description": "Core tool for the Quint specification language",
"keywords": [
"temporal",
"logic",
"formal",
"specification",
"verification"
],
"keywords": ["temporal", "logic", "formal", "specification", "verification"],
"homepage": "https://github.com/informalsystems/quint",
"bugs": "https://github.com/informalsystems/quint/issues",
"license": "Apache 2.0",
Expand All @@ -35,11 +29,7 @@
"bin": {
"quint": "dist/src/cli.js"
},
"files": [
"README.md",
"dist/**/*",
"test/**/*.ts"
],
"files": ["README.md", "dist/**/*", "test/**/*.ts"],
"engines": {
"node": ">=18"
},
Expand Down Expand Up @@ -72,6 +62,8 @@
"compile": "genversion -e src/version.ts && tsc && copyfiles -u 1 ./src/reflection.proto ./src/builtin.qnt ./dist/src/",
"prepare": "rm -rf ./dist && npm run compile && chmod +x ./dist/src/cli.js",
"test": "mocha --reporter-option maxDiffSize=0 -r ts-node/register test/*.test.ts test/**/*.test.ts",
"test-w": "while inotifywait -r -e close_write ./ ; do npm run test; done",
"test-f": "mocha --reporter-option maxDiffSize=0 -r ts-node/register",
"coverage": "nyc npm run test",
"integration": "txm cli-tests.md && txm io-cli-tests.md",
"apalache-integration": "txm apalache-tests.md",
Expand Down
50 changes: 29 additions & 21 deletions quint/src/generated/Quint.g4
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ operDef : qualifier normalCallName
;

typeDef
: 'type' qualId # typeAbstractDef
| 'type' qualId '=' type # typeAliasDef
| 'type' typeName=qualId '=' '|'? typeSumVariant ('|' typeSumVariant)* # typeSumDef
: 'type' qualId # typeAbstractDef
| 'type' typeDefHead '=' type # typeAliasDef
| 'type' typeDefHead '=' sumTypeDefinition # typeSumDef
;

typeDefHead : typeName=qualId ('[' typeVars+=typeVar(',' typeVars+=typeVar)* ']')?;

sumTypeDefinition : '|'? typeSumVariant ('|' typeSumVariant)* ;

// A single variant case in a sum type definition or match statement.
// E.g., `A(t)` or `A`.
typeSumVariant : sumLabel=simpleId["variant label"] ('(' type ')')? ;
Expand Down Expand Up @@ -96,28 +100,32 @@ qualifiedName : qualId;
fromSource: STRING;

// Types in Type System 1.2 of Apalache
type : <assoc=right> type '->' type # typeFun
| <assoc=right> type '=>' type # typeOper
| '(' (type (',' type)*)? ','? ')' '=>' type # typeOper
| SET '[' type ']' # typeSet
| LIST '[' type ']' # typeList
| '(' type ',' type (',' type)* ','? ')' # typeTuple
| '{' row '}' # typeRec
| 'int' # typeInt
| 'str' # typeStr
| 'bool' # typeBool
| LOW_ID # typeVar
| qualId # typeConst
| '(' type ')' # typeParen
;
type
: <assoc=right> type '->' type # typeFun
| <assoc=right> type '=>' type # typeOper
| '(' (type (',' type)*)? ','? ')' '=>' type # typeOper
// TODO: replace Set with general type application
| SET '[' type ']' # typeSet
// TODO: replace List with general type application
| LIST '[' type ']' # typeList
| '(' type ',' type (',' type)* ','? ')' # typeTuple
| '{' row? '}' # typeRec
| 'int' # typeInt
| 'str' # typeStr
| 'bool' # typeBool
| typeVar # typeVarCase
| qualId # typeConst
| '(' type ')' # typeParen
| typeCtor=type ('[' typeArg+=type (',' typeArg+=type)* ']') # typeApp
;

row : (rowLabel ':' type ',')* ((rowLabel ':' type) (',' | '|' (rowVar=identifier))?)?
typeVar: LOW_ID;
row : (rowLabel ':' type) (',' rowLabel ':' type)* (',' | '|' (rowVar=identifier))?
| '|' (rowVar=identifier)
;

rowLabel : simpleId["record"] ;


// A Quint expression. The order matters, it defines the priority.
// Wherever possible, we keep the same order of operators as in TLA+.
// We are also trying to be consistent with mainstream languages, e.g.,
Expand Down Expand Up @@ -269,8 +277,6 @@ AND : 'and' ;
OR : 'or' ;
IFF : 'iff' ;
IMPLIES : 'implies' ;
SET : 'Set' ;
LIST : 'List' ;
MAP : 'Map' ;
MATCH : 'match' ;
PLUS : '+' ;
Expand All @@ -287,6 +293,8 @@ EQ : '==' ;
ASGN : '=' ;
LPAREN : '(' ;
RPAREN : ')' ;
SET : 'Set';
LIST : 'List';

// An identifier starting with lowercase
LOW_ID : ([a-z][a-zA-Z0-9_]*|[_][a-zA-Z0-9_]+) ;
Expand Down
17 changes: 10 additions & 7 deletions quint/src/generated/Quint.interp

Large diffs are not rendered by default.

106 changes: 53 additions & 53 deletions quint/src/generated/Quint.tokens

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions quint/src/generated/QuintLexer.interp

Large diffs are not rendered by default.

106 changes: 53 additions & 53 deletions quint/src/generated/QuintLexer.tokens

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dd4a887

Please sign in to comment.