Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented cast as, try as and force as high-level type cast expressions for advanced type manipulation #693

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6b3b307
minor (#685): Added parser rules and ast nodes for convert, cast, try…
Luna-Klatzer Aug 22, 2024
a8e3f99
Merged dev-next into 685-feature-implement-cast-as-try-as-and-force-as
Luna-Klatzer Sep 2, 2024
816be70
minor (#685): Implemented basic cast, try-as-cast and force-as-cast s…
Luna-Klatzer Sep 7, 2024
9bec36b
other: Prettified code and optimised imports
Luna-Klatzer Sep 7, 2024
77820a1
other: Added additional compile and run scripts
Luna-Klatzer Sep 7, 2024
f6152ce
minor (#685): Implemented code generation for the new casts
Luna-Klatzer Sep 7, 2024
223fb69
Merged dev-next into 685-feature-implement-cast-as-try-as-and-force-as
Luna-Klatzer Sep 18, 2024
d71f5c2
Merge branch 'dev-next' into 685-feature-implement-cast-as-try-as-and…
Luna-Klatzer Oct 3, 2024
2ec75d3
major (#685): Implemented basic internal `accepts` function for built…
Luna-Klatzer Oct 3, 2024
6a5d966
other: Fixed broken test due to the last commit 2ec75d30bf959f1ab639b…
Luna-Klatzer Oct 4, 2024
a7a0028
major (#685): Added new module `runtime` in js target for better code…
Luna-Klatzer Oct 4, 2024
492008d
other: Prettified project files and cleaned up project
Luna-Klatzer Nov 29, 2024
2003cbd
other: Split core functionality tests into separate files
Luna-Klatzer Nov 29, 2024
8592311
other: Fixed invalid docstrings in `cast-or-convert-expression`
Luna-Klatzer Nov 30, 2024
8a3edb8
fix (#685): Fixed invalid typescript cast in code-generator.ts
Luna-Klatzer Nov 30, 2024
56e430b
other: Added basic cast-or-convert tests
Luna-Klatzer Nov 30, 2024
c8cf6dc
fix: Removed code duplication in `RootASTNode.semanticAnalysis()` in …
Luna-Klatzer Jan 18, 2025
a273ddd
other: Fixed invalid test for `cast as` in cast-or-convert.test.ts
Luna-Klatzer Feb 16, 2025
8b69f04
fix (#685): Fixed invalid direction of duck typing checks
Luna-Klatzer Feb 16, 2025
9b7ddd5
fix (#685): Fixed `PropertyNotFoundTypeError` not being properly mark…
Luna-Klatzer Feb 16, 2025
5afec01
other: Added error tests for `PropertyAssignmentTypeError` and `Prope…
Luna-Klatzer Feb 16, 2025
f0a5dc3
other: Updated CHANGELOG.md
Luna-Klatzer Feb 16, 2025
4be0733
fix: Fixed naming scheme violation by adding `TypeError` to error `Va…
Luna-Klatzer Feb 16, 2025
c0b2b3e
other: Updated CHANGELOG.md
Luna-Klatzer Feb 16, 2025
0565504
major (#685): Restructured create-kipper.ts and finished implementati…
Luna-Klatzer Feb 17, 2025
ed1925e
other: Added tests for `force as` casts
Luna-Klatzer Feb 17, 2025
9f0df36
fix: Fixed typo in `__createKipper()` in create-kipper.ts
Luna-Klatzer Feb 17, 2025
91bc67d
other: Updated .gitignore to ignore root test files which are often u…
Luna-Klatzer Feb 17, 2025
ff74e75
other: Prettified code
Luna-Klatzer Feb 17, 2025
c56674d
major (#685): Finished implementation of `try as` casts and its runti…
Luna-Klatzer Feb 17, 2025
0e23549
other: Added tests for `try as` in cast-or-convert.test.ts
Luna-Klatzer Feb 17, 2025
f5e0b5e
other: UPDATED CHANGELOG.md
Luna-Klatzer Feb 17, 2025
cf7e354
other: Prettified files in kipper
Luna-Klatzer Feb 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,8 @@ typings/

# Nix
.direnv

# Root tmp tests
/test.js
/test.ts
/test.kip
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,26 @@ To use development versions of Kipper download the

### Added

- New cast keywords `cast as`, `force as` and `try as`, which allow for various type-safe cast operations.
([#685](https://github.com/Kipper-Lang/Kipper/issues/685))

### Changed

- Renamed:
- Error `MismatchingArgCountBetweenFuncTypesError` to `MismatchingArgCountBetweenFuncTypesTypeError`.
- Error `UnknownTypeError` to `UnknownTypeTypeError`.
- Error `PropertyNotFoundError` to `PropertyNotFoundTypeError`.
- Error `ValueTypeNotIndexableWithGivenAccessor` to `ValueTypeNotIndexableWithGivenAccessorTypeError`.

### Fixed

- `PropertyNotFoundTypeError` being thrown as a stand-alone error instead of being set as the cause for any parent
assignment operation failure.
- `PropertyNotFoundTypeError` being checked for in the wrong direction i.e. that `otherT` had to have all the properties
of `thisT` instead of the other way around (which is the correct way).
- Indexable checks for `str` and `Array<T>` being accidentally turned off by incorrect logic. This caused
`ValueTypeNotIndexableWithGivenAccessorTypeError` to be only thrown for objects and not for arrays and strings.

### Deprecated

### Removed
Expand Down
3 changes: 3 additions & 0 deletions kipper/core/KipperLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Var : 'var';

// conversion
As : 'as';
CastAs : 'cast as';
ForceAs : 'force as';
TryAs : 'try as';

// spread operator
Spread : '...';
Expand Down
306 changes: 156 additions & 150 deletions kipper/core/KipperLexer.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -6,157 +6,163 @@ InstanceOf=5
Const=6
Var=7
As=8
Spread=9
Switch=10
Case=11
Default=12
Break=13
Continue=14
Do=15
While=16
If=17
Else=18
For=19
Enum=20
DefFunc=21
Return=22
CallFunc=23
RetIndicator=24
Class=25
Interface=26
Constructor=27
New=28
True=29
False=30
Matches=31
Typeof=32
Void=33
Null=34
Undefined=35
Comma=36
SemiColon=37
QuestionMark=38
Colon=39
LeftParen=40
RightParen=41
LeftBracket=42
RightBracket=43
FStringExpEnd=44
LeftBrace=45
RightBrace=46
Plus=47
PlusPlus=48
Minus=49
MinusMinus=50
Star=51
Div=52
Mod=53
PowerTo=54
AndAnd=55
OrOr=56
Not=57
Assign=58
PlusAssign=59
MinusAssign=60
StarAssign=61
DivAssign=62
ModAssign=63
Equal=64
NotEqual=65
Less=66
LessEqual=67
Greater=68
GreaterEqual=69
BitwiseAnd=70
BitwiseOr=71
BitwiseXor=72
BitwiseNot=73
BitwiseZeroFillLeftShift=74
BitwiseSignedRightShift=75
BitwiseZeroFillRightShift=76
Dot=77
Identifier=78
IntegerConstant=79
SingleQuoteStringLiteral=80
DoubleQuoteStringLiteral=81
FloatingConstant=82
Whitespace=83
Newline=84
FStringSingleQuoteStart=85
FStringDoubleQuoteStart=86
FStringSingleQuoteEnd=87
FStringSingleQuoteAtom=88
FStringDoubleQuoteEnd=89
FStringDoubleQuoteAtom=90
CastAs=9
ForceAs=10
TryAs=11
Spread=12
Switch=13
Case=14
Default=15
Break=16
Continue=17
Do=18
While=19
If=20
Else=21
For=22
Enum=23
DefFunc=24
Return=25
CallFunc=26
RetIndicator=27
Class=28
Interface=29
Constructor=30
New=31
True=32
False=33
Matches=34
Typeof=35
Void=36
Null=37
Undefined=38
Comma=39
SemiColon=40
QuestionMark=41
Colon=42
LeftParen=43
RightParen=44
LeftBracket=45
RightBracket=46
FStringExpEnd=47
LeftBrace=48
RightBrace=49
Plus=50
PlusPlus=51
Minus=52
MinusMinus=53
Star=54
Div=55
Mod=56
PowerTo=57
AndAnd=58
OrOr=59
Not=60
Assign=61
PlusAssign=62
MinusAssign=63
StarAssign=64
DivAssign=65
ModAssign=66
Equal=67
NotEqual=68
Less=69
LessEqual=70
Greater=71
GreaterEqual=72
BitwiseAnd=73
BitwiseOr=74
BitwiseXor=75
BitwiseNot=76
BitwiseZeroFillLeftShift=77
BitwiseSignedRightShift=78
BitwiseZeroFillRightShift=79
Dot=80
Identifier=81
IntegerConstant=82
SingleQuoteStringLiteral=83
DoubleQuoteStringLiteral=84
FloatingConstant=85
Whitespace=86
Newline=87
FStringSingleQuoteStart=88
FStringDoubleQuoteStart=89
FStringSingleQuoteEnd=90
FStringSingleQuoteAtom=91
FStringDoubleQuoteEnd=92
FStringDoubleQuoteAtom=93
'instanceof'=5
'const'=6
'var'=7
'as'=8
'...'=9
'switch'=10
'case'=11
'default'=12
'break'=13
'continue'=14
'do'=15
'while'=16
'if'=17
'else'=18
'for'=19
'enum'=20
'def'=21
'return'=22
'call'=23
'->'=24
'class'=25
'interface'=26
'constructor'=27
'new'=28
'true'=29
'false'=30
'matches'=31
'typeof'=32
'void'=33
'null'=34
'undefined'=35
','=36
';'=37
'?'=38
':'=39
'('=40
')'=41
'['=42
']'=43
'{'=45
'}'=46
'+'=47
'++'=48
'-'=49
'--'=50
'*'=51
'/'=52
'%'=53
'**'=54
'&&'=55
'||'=56
'!'=57
'='=58
'+='=59
'-='=60
'*='=61
'/='=62
'%='=63
'=='=64
'!='=65
'<'=66
'<='=67
'>'=68
'>='=69
'&'=70
'|'=71
'^'=72
'~'=73
'<<'=74
'>>'=75
'>>>'=76
'.'=77
'cast as'=9
'force as'=10
'try as'=11
'...'=12
'switch'=13
'case'=14
'default'=15
'break'=16
'continue'=17
'do'=18
'while'=19
'if'=20
'else'=21
'for'=22
'enum'=23
'def'=24
'return'=25
'call'=26
'->'=27
'class'=28
'interface'=29
'constructor'=30
'new'=31
'true'=32
'false'=33
'matches'=34
'typeof'=35
'void'=36
'null'=37
'undefined'=38
','=39
';'=40
'?'=41
':'=42
'('=43
')'=44
'['=45
']'=46
'{'=48
'}'=49
'+'=50
'++'=51
'-'=52
'--'=53
'*'=54
'/'=55
'%'=56
'**'=57
'&&'=58
'||'=59
'!'=60
'='=61
'+='=62
'-='=63
'*='=64
'/='=65
'%='=66
'=='=67
'!='=68
'<'=69
'<='=70
'>'=71
'>='=72
'&'=73
'|'=74
'^'=75
'~'=76
'<<'=77
'>>'=78
'>>>'=79
'.'=80
21 changes: 20 additions & 1 deletion kipper/core/KipperParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,28 @@ unaryOperator

castOrConvertExpression
: unaryExpression # passOnCastOrConvertExpression
| unaryExpression 'as' typeSpecifierExpression #actualCastOrConvertExpression
| convertExpression # actualConvertExpression
| castExpression #actualCastExpression
| forceCastExpression #actualForceCastExpression
| tryCastExpression #actualTryCastExpression
;

convertExpression
: unaryExpression 'as' typeSpecifierExpression
;

castExpression
: unaryExpression 'cast as' typeSpecifierExpression
;

forceCastExpression
: unaryExpression 'force as' typeSpecifierExpression
;

tryCastExpression
: unaryExpression 'try as' typeSpecifierExpression
;

multiplicativeExpression
: castOrConvertExpression # passOnMultiplicativeExpression
| multiplicativeExpression ('*'|'/'|'%'|'**') castOrConvertExpression # actualMultiplicativeExpression
Expand Down
Loading
Loading