mirror of
https://github.com/irmen/prog8.git
synced 2024-10-18 16:24:26 +00:00
don't throw basic AstException but SyntaxError instead
This commit is contained in:
parent
367a2a4cee
commit
71a9a84211
@ -345,7 +345,7 @@ internal fun Prog8ANTLRParser.DirectiveContext.toAst() : Directive =
|
|||||||
private fun Prog8ANTLRParser.DirectiveargContext.toAst() : DirectiveArg {
|
private fun Prog8ANTLRParser.DirectiveargContext.toAst() : DirectiveArg {
|
||||||
val str = stringliteral()
|
val str = stringliteral()
|
||||||
if(str?.ALT_STRING_ENCODING() != null)
|
if(str?.ALT_STRING_ENCODING() != null)
|
||||||
throw AstException("${toPosition()} can't use alternate string s for directive arguments")
|
throw SyntaxError("can't use alternate string s for directive arguments", toPosition())
|
||||||
|
|
||||||
return DirectiveArg(stringliteral()?.text, identifier()?.text, integerliteral()?.toAst()?.number?.toInt(), toPosition())
|
return DirectiveArg(stringliteral()?.text, identifier()?.text, integerliteral()?.toAst()?.number?.toInt(), toPosition())
|
||||||
}
|
}
|
||||||
@ -359,7 +359,7 @@ private fun Prog8ANTLRParser.IntegerliteralContext.toAst(): NumericLiteral {
|
|||||||
integer = try {
|
integer = try {
|
||||||
text.toInt()
|
text.toInt()
|
||||||
} catch(x: NumberFormatException) {
|
} catch(x: NumberFormatException) {
|
||||||
throw AstException("${toPosition()} invalid decimal literal ${x.message}")
|
throw SyntaxError("invalid decimal literal ${x.message}", toPosition())
|
||||||
}
|
}
|
||||||
datatype = when(integer) {
|
datatype = when(integer) {
|
||||||
in 0..255 -> DataType.UBYTE
|
in 0..255 -> DataType.UBYTE
|
||||||
@ -375,7 +375,7 @@ private fun Prog8ANTLRParser.IntegerliteralContext.toAst(): NumericLiteral {
|
|||||||
try {
|
try {
|
||||||
integer = text.toInt(2)
|
integer = text.toInt(2)
|
||||||
} catch(x: NumberFormatException) {
|
} catch(x: NumberFormatException) {
|
||||||
throw AstException("${toPosition()} invalid binary literal ${x.message}")
|
throw SyntaxError("invalid binary literal ${x.message}", toPosition())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
16 -> {
|
16 -> {
|
||||||
@ -384,7 +384,7 @@ private fun Prog8ANTLRParser.IntegerliteralContext.toAst(): NumericLiteral {
|
|||||||
try {
|
try {
|
||||||
integer = text.toInt(16)
|
integer = text.toInt(16)
|
||||||
} catch(x: NumberFormatException) {
|
} catch(x: NumberFormatException) {
|
||||||
throw AstException("${toPosition()} invalid hexadecimal literal ${x.message}")
|
throw SyntaxError("invalid hexadecimal literal ${x.message}", toPosition())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> throw FatalAstException("invalid radix")
|
else -> throw FatalAstException("invalid radix")
|
||||||
|
@ -2,9 +2,14 @@ package prog8.ast.base
|
|||||||
|
|
||||||
import prog8.ast.expressions.IdentifierReference
|
import prog8.ast.expressions.IdentifierReference
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A severe problem in the Ast (such as internal inconsistency or failed invariant)
|
||||||
|
* It is not useful to continue processing, this aborts the compiler immediately
|
||||||
|
*/
|
||||||
open class FatalAstException (override var message: String) : Exception(message)
|
open class FatalAstException (override var message: String) : Exception(message)
|
||||||
|
|
||||||
open class AstException (override var message: String) : Exception(message)
|
|
||||||
|
abstract class AstException (override var message: String) : Exception(message)
|
||||||
|
|
||||||
open class SyntaxError(override var message: String, val position: Position) : AstException(message) {
|
open class SyntaxError(override var message: String, val position: Position) : AstException(message) {
|
||||||
override fun toString() = "${position.toClickableStr()} Syntax error: $message"
|
override fun toString() = "${position.toClickableStr()} Syntax error: $message"
|
||||||
|
Loading…
Reference in New Issue
Block a user