-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assertion violation errors currently report the location of the falsy expression, but we'd prefer to print the actual expression (#16)
- Loading branch information
Showing
11 changed files
with
28 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 10 additions & 11 deletions
21
...itk/xplang/lang/ErrorStatementParser.java → ...tk/xplang/lang/AssertStatementParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,28 @@ | ||
package ppke.itk.xplang.lang; | ||
|
||
import ppke.itk.xplang.ast.RValue; | ||
import ppke.itk.xplang.ast.ErrorRaising; | ||
import ppke.itk.xplang.ast.Assertion; | ||
import ppke.itk.xplang.common.Location; | ||
import ppke.itk.xplang.parser.*; | ||
import ppke.itk.xplang.type.Archetype; | ||
|
||
class ErrorStatementParser { | ||
static ErrorRaising parse(Parser parser) throws ParseError { | ||
Location startLoc = parser.accept(parser.symbol(PlangSymbol.ERROR)).location(); | ||
parser.accept(parser.symbol(PlangSymbol.COLON)); | ||
class AssertStatementParser { | ||
static Assertion parse(Parser parser) throws ParseError { | ||
Location startLoc = parser.accept(parser.symbol(PlangSymbol.ASSERT)).location(); | ||
|
||
Expression messageExpression = parser.parseExpression(); | ||
Location endLoc = messageExpression.getLocation(); | ||
Expression assertion = parser.parseExpression(); | ||
Location endLoc = assertion.getLocation(); | ||
RValue message = TypeChecker.in(parser.context()) | ||
.checking(messageExpression) | ||
.expecting(Archetype.STRING_TYPE) | ||
.checking(assertion) | ||
.expecting(Archetype.BOOLEAN_TYPE) | ||
.withCustomErrorMessage( | ||
node -> new ParseError(node.location(), ErrorCode.TYPE_MISMATCH_ERROR_MESSAGE, node.getType()) | ||
node -> new ParseError(node.location(), ErrorCode.TYPE_MISMATCH_ASSERTION, node.getType()) | ||
) | ||
.build() | ||
.resolve(); | ||
|
||
Location location = Location.between(startLoc, endLoc); | ||
|
||
return new ErrorRaising(location, message); | ||
return new Assertion(location, message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ enum PlangSymbol { | |
LOOP, | ||
WHILE, | ||
END_LOOP, | ||
ERROR, | ||
ASSERT, | ||
ASSIGNMENT, | ||
IN, | ||
OUT, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters