Skip to content

Commit

Permalink
fix: some error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nawetimebomb committed Sep 24, 2024
1 parent fa44636 commit 0f49a22
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 54 deletions.
8 changes: 4 additions & 4 deletions compiler/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func newConstant(token Token) {
constant.value = tokens[0].value.(int)
}

consume(TOKEN_PAREN_CLOSE, MsgParseConstMissingDot)
consume(TOKEN_PAREN_CLOSE, MsgParseConstMissingCloseStmt)
} else {
advance()
constant.value = parser.previous.value.(int)
Expand Down Expand Up @@ -275,7 +275,7 @@ func newFunction(token Token) {
}
}

consume(TOKEN_PAREN_OPEN, MsgParseFunctionMissingDo)
consume(TOKEN_PAREN_OPEN, MsgParseFunctionMissingOpenStmt)

frontend.sLevel++
frontend.scope[1].tt = TOKEN_FN
Expand Down Expand Up @@ -721,7 +721,7 @@ func parseToken(token Token) {
code.op = OP_JUMP_IF_FALSE
emit(code)
} else {
errorAt(&token, MsgParseDoOrphanTokenFound)
errorAt(&token, MsgParseOpenStmtOrphanTokenFound)
}
case TOKEN_PAREN_CLOSE:
if *sLevel > 0 {
Expand All @@ -746,7 +746,7 @@ func parseToken(token Token) {

*sLevel--
} else {
errorAt(&token, MsgParseDotOrphanTokenFound)
errorAt(&token, MsgParseCloseStmtOrphanTokenFound)
}
}
}
Expand Down
78 changes: 38 additions & 40 deletions compiler/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ const (
"\t\t ^^^"
MsgParseReserveMissingValue =
"invalid or missing value\n" +
"\t\treserve mem 1024 .\n" +
"\t\treserve mem 1024\n" +
"\t\t ^^^^"
MsgParseReserveMissingDot =
MsgParseReserveMissingCloseStmt =
"missing '.'\n" +
"\t\treserve mem 1024 .\n" +
"\t\t ^"
"\t\treserve mem ( 1024 )\n" +
"\t\t ^"

MsgParseBindAlreadyBound =
"function has bindings already"
MsgParseBindEmptyBody =
"missing or invalid bind content\n" +
"\t\tbind a b c .\n" +
"\t\t ^^^^^"
"\t\tbind ( a b c )\n" +
"\t\t ^^^^^"
MsgParseBindMissingCloseStmt =
"missing ')'\n" +
"\t\tbind ( a b c )\n" +
Expand All @@ -65,26 +65,24 @@ const (
"\t\tbind ( a b c )\n" +
"\t\t ^"

MsgParseSyscallMissingCloseStmt =
"missing ')'\n" +
"\t\tsyscall ( int int )\n" +
"\t\t ^"
MsgParseSyscallMissingOpenStmt =
"missing '('\n" +
"\t\tsyscall ( int int )\n" +
"\t\t ^"

MsgParseDoOrphanTokenFound =
"only use 'do' when starting a block statement\nE.g.:\n\tif [condition] do [...] else [...] .\n\t^^ ^^\n'do' can be used in other blocks like function and loops"
MsgParseOpenStmtOrphanTokenFound =
"only use '(' when starting a block statement\n" +
"E.g.:\n" +
"\tif [condition] ( [...] else [...] )\n" +
"\t^^ ^\n" +
"'(' can be used in other blocks like function and loops."

MsgParseElseOrphanTokenFound =
"only use 'else' after starting an 'if' statement\nE.g.:\n\tif [condition] do [...] else [...] .\n\t^^ ^^^^"
"only use 'else' after starting an 'if' statement\n" +
"E.g.:\n" +
"\tif [condition] ( [...] else [...] )\n" +
"\t^^ ^^^^"

MsgParseDotOrphanTokenFound =
"'.' must have an associated block\n" +
MsgParseCloseStmtOrphanTokenFound =
"')' must have an associated block\n" +
"E.g.:\n" +
"\t\tif [condition] do [...] else [...] .\n" +
"\t\t^^ ^\n"
"\t\tif [condition] ( [...] else [...] )\n" +
"\t\t^^ ^\n"

MsgParseCallMainFunctionMissing =
"entry point is not defined\n" +
Expand All @@ -98,43 +96,43 @@ const (

MsgParseFunctionMissingName =
"invalid or missing function name\n" +
"\t\tfunction my-func do [...] .\n" +
"\t\t ^^^^^^^"
"\t\fn my-func ( [...] )\n" +
"\t\t ^^^^^^^"
MsgParseFunctionUnknownType =
"type '%s' is unknown"
MsgParseFunctionNoReturnSpecified =
"no return values specified after '->'\n" +
"\t\tfunction my-func -> do [...] .\n" +
"\t\t ^^"
MsgParseFunctionMissingDo =
"missing 'do' keyword\n" +
"\t\tfunction my-func do [...] .\n" +
"\t\t ^^"
MsgParseFunctionMissingDot =
"missing '.'\n" +
"\t\tfunction my-func do [...] .\n" +
"\t\t ^"
"\t\fn my-func -> ( [...] )\n" +
"\t\t ^^"
MsgParseFunctionMissingOpenStmt =
"missing '(' keyword\n" +
"\t\fn my-func ( [...] )\n" +
"\t\t ^"
MsgParseFunctionMissingCloseStmt =
"missing ')'\n" +
"\t\fn my-func ( [...] )\n" +
"\t\t ^"
MsgParseFunctionMainAlreadyDefined =
"function main already defined at %s:%d"
MsgParseFunctionNotPolymorphic =
"function %s is not polymorphic and has a non-polymorphic variant"

MsgParseConstMissingWord =
"invalid or missing word\n" +
"\t\tconst my-const [...] .\n" +
"\t\tconst my-const [...]\n" +
"\t\t ^^^^^^^^"
MsgParseConstMissingContent =
"const cannot be empty\n" +
"\t\tconst my-const [...] .\n" +
"\t\tconst my-const [...]\n" +
"\t\t ^^^^^"
MsgParseConstInvalidContent =
"const %s can only have int or simple arithmetic operations (+ or *)\n" +
"\t\tconst my-const 32 1024 * .\n" +
"\t\t ^^^^^^^^^"
MsgParseConstMissingDot =
"missing '.'\n" +
"\t\tconst my-const [...] .\n" +
"\t\t ^"
MsgParseConstMissingCloseStmt =
"missing ')'\n" +
"\t\tconst my-const ( [...] )\n" +
"\t\t ^"
MsgParseConstOverrideNotAllowed =
"const %s already exists\n"

Expand Down
22 changes: 12 additions & 10 deletions demo/03-fibonacci.sk
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
function fib int -> int do
if dup 2 < do
ret
else
dup 1 - fib swap 2 - fib + ret
.
.
using io

function main do
30 fib print
.
fn fib int -> int (
if dup 2 < (
ret
else
dup 1 - fib swap 2 - fib + ret
)
)

fn main (
30 fib println
)

0 comments on commit 0f49a22

Please sign in to comment.