Skip to content

Commit

Permalink
Add more error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
peachpit-site committed Jan 31, 2025
1 parent 72ba75f commit 89a5575
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 18 deletions.
204 changes: 193 additions & 11 deletions source/err/errorfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1225,12 +1225,45 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"init/assign/ident": {
"init/assign": {
Message: func(tok *token.Token, args ...any) string {
return "left-hand side of assignment should be identifier"
return "expected assignment"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "The left-hand side of an assignment operation names the things to be assigned to."
return "All you're meant to do in the 'var' and 'const' sections of " +
"the code is assign variables and constants, respectively"
},
},

"init/clone/comma": {
Message: func(tok *token.Token, args ...any) string {
return "expected comma-separated list"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "When declaring a clone type, after 'using', Pipefish expects a comma-" +
"separated list of operations that the type can use."
},
},

"init/clone/type": {
Message: func(tok *token.Token, args ...any) string {
return "can't clone type " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Only the types 'float', 'int', 'list', 'map', 'pair', 'rune', " +
"'set' and 'string' are cloneable."
},
},

"init/clone/using": {
Message: func(tok *token.Token, args ...any) string {
return "was expecting end of line or 'using' keyword"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "When defining a clone type, after giving the type of its parent " +
"you've either finished, or you can go on to request operations for it, which "+
"consists of the word 'using' followed by a comma-separated list of the " +
"operations you want to use."
},
},

Expand All @@ -1249,6 +1282,25 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"init/depend/cmd": {
Message: func(tok *token.Token, args ...any) string {
return "illegal dependency on command"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Only a command can use another command as a dependency."
},
},

"init/depend/var": {
Message: func(tok *token.Token, args ...any) string {
return "illegal dependency on global variable"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Only a command or another variable declaration can use another " +
"variable as a dependency."
},
},

"init/enum/comma": {
Message: func(tok *token.Token, args ...any) string {
return "expected comma, got " + text.DescribeTok(tok)
Expand Down Expand Up @@ -1308,6 +1360,16 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"init/external/file": {
Message: func(tok *token.Token, args ...any) string {
return "failed to open file " + emph(args[0]) + " with error " + emph(args[1])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "This error very much means what it says. Pipefish tried to open the file " +
"specified in the 'external' statement, and failed."
},
},

"init/external/path/a": {
Message: func(tok *token.Token, args ...any) string {
return "malformed path to external service"
Expand Down Expand Up @@ -1440,6 +1502,57 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"init/interface/colon": {
Message: func(tok *token.Token, args ...any) string {
return "unexpected occurrence of " + emph(tok.Literal)
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "The only thing Pipefish was expecting to see after 'interface' is a colon."
},
},

"init/interface/self": {
Message: func(tok *token.Token, args ...any) string {
return "'self' missing in clause of interface"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "The parts of an interface define what types fit it b referring to the " +
"behavior of a pseudotype called 'self'. Any clause of this definition that " +
"doesn't refer to 'self' would not in fact contribute to the definition of " +
"the interface."
},
},

"init/name/exists/a": {
Message: func(tok *token.Token, args ...any) string {
return "definition of " + emph(args[1]) + text.DescribePos((args[0]).(*token.Token)) +
" conflicts with definition"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "You can't declare the same identifier twice!"
},
},

"init/name/exists/b": {
Message: func(tok *token.Token, args ...any) string {
return "definition of " + emph(args[1]) + text.DescribePos((args[0]).(*token.Token)) +
" conflicts with definition"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "You can't declare the same identifier twice!"
},
},

"init/name/exists/c": {
Message: func(tok *token.Token, args ...any) string {
return "definition of " + emph(args[1]) + text.DescribePos((args[0]).(*token.Token)) +
" conflicts with definition"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "You can't declare the same identifier twice!"
},
},

"init/overload/a": {
Message: func(tok *token.Token, args ...any) string {
return "too much overloading: function '" + args[0].(string) + "' defined at@line " + strconv.Itoa(args[1].(int)) + "@conflicts with another version of the same function defined at"
Expand Down Expand Up @@ -1514,7 +1627,7 @@ var ErrorCreatorMap = map[string]ErrorCreator{
return "mismatching reference parameters in overloaded function"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "if you overload a function with reference parameters, then they must have the same number of reference parameters, at the start of the parameter list, or you will see this error."
return "If you overload a function with reference parameters, then they must have the same number of reference parameters, at the start of the parameter list, or you will see this error."
},
},

Expand Down Expand Up @@ -1542,21 +1655,90 @@ var ErrorCreatorMap = map[string]ErrorCreator{

"init/request/float": {
Message: func(tok *token.Token, args ...any) string {
return "clone of type " + emph("float") + " cannot request operation " + emph(args[0])
return "clone of " + emph("float") + " cannot request operation " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "A clone of " + emph("int") + " can only request the native operations suitable to that type, i.e. " +
return "A clone of " + emph("float") + " can only request the native operations suitable to that type, i.e. " +
emph("+") + ", " + emph("-") + ", " + emph("*") + ", and " + emph("/") + "."
},
},

"init/request/int": {
Message: func(tok *token.Token, args ...any) string {
return "clone of type " + emph("int") + " cannot request operation " + emph(args[0])
return "clone of " + emph("int") + " cannot request operation " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "A clone of " + emph("int") + " can only request the native operations suitable to that type, i.e. " +
emph("+") + ", " + emph("-") + ", " + emph("*") + ", " + emph("/") + ", and " + emph("%") + "."
emph("+") + ", " + emph("-") + ", " + emph("*") + emph("div") + ", " + ", and " + emph("mod") + "."
},
},

"init/request/list": {
Message: func(tok *token.Token, args ...any) string {
return "clone of " + emph("list") + " cannot request operation " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "A clone of " + emph("list") + " can only request the native operations suitable to that type, i.e. " +
emph("+") + ", " + emph("with") + ", " + emph("?>") + emph(">>") + ", " + ", and " + emph("slice") + "."
},
},

"init/request/map": {
Message: func(tok *token.Token, args ...any) string {
return "clone of " + emph("map") + " cannot request operation " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "A clone of " + emph("map") + " can only request the native operations suitable to that type, i.e. " +
emph("with") + " and " + emph("without") + "."
},
},

"init/request/pair": {
Message: func(tok *token.Token, args ...any) string {
return "clone of " + emph("pair") + " cannot request operations"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Since the " + emph("pair") + " type has no native operations besides " +
"indexing, which you get for free, there's nothing to request."
},
},

"init/request/set": {
Message: func(tok *token.Token, args ...any) string {
return "clone of " + emph("set") + " cannot request operation " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "A clone of " + emph("int") + " can only request the native operations suitable to that type, i.e. " +
emph("+") + " and " + emph("-") + "."
},
},

"init/request/string": {
Message: func(tok *token.Token, args ...any) string {
return "clone of " + emph("string") + " cannot request operation " + emph(args[0])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "A clone of " + emph("string") + " can only request the native operations suitable to that type, i.e. " +
emph("+") + " and " + emph("slice") + "."
},
},

"init/service/depends": {
Message: func(tok *token.Token, args ...any) string {
return "service variable " + emph(args[0]) + " has illegal dependencies"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "As service variables are initialized before anything else, they shouldn't" +
"depend on anything else you define in your code."
},
},

"init/service/type": {
Message: func(tok *token.Token, args ...any) string {
return "service variable " + emph(args[0]) + " should have type " + emph(args[1])
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "The fact that you can redeclare service variables doesn't mean you can change their type."
},
},

Expand Down Expand Up @@ -1641,12 +1823,12 @@ var ErrorCreatorMap = map[string]ErrorCreator{
},
},

"init/type/null": {
"init/type/defined": {
Message: func(tok *token.Token, args ...any) string {
return "type name ends in " + emph("?")
return "redefinition of type"
},
Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string {
return "Only an abstract type name can end in " + emph("?") + ", and even then only if the type contains " + emph("NULL") + "."
return "Each type can only be declared once."
},
},

Expand Down
14 changes: 7 additions & 7 deletions source/initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func (iz *initializer) MakeParserAndTokenizedProgram() {
if typeDefined != declarationType(DUMMY) {
iz.addTokenizedDeclaration(typeDefined, line, IsPrivate)
} else {
iz.Throw("init/type/form", &tok)
iz.Throw("init/type/defined", &tok)
}
default:
panic("Unhandled section type.")
Expand Down Expand Up @@ -674,7 +674,7 @@ func (iz *initializer) initializeExternals() {
// Otherwise we need to start up the service, add it to the hub, and then declare it as external.
newServiceCp, e := StartCompilerFromFilepath(path, iz.cp.Vm.Database, iz.Common.HubCompilers)
if e != nil { // Then we couldn't open the file.
iz.Throw("init/external/file", declaration.GetToken(), e)
iz.Throw("init/external/file", declaration.GetToken(), path, e.Error())
}
if len(newServiceCp.P.Common.Errors) > 0 {
newServiceCp.P.Common.IsBroken = true
Expand Down Expand Up @@ -936,7 +936,7 @@ func (iz *initializer) createClones() {
iz.Throw("init/request/map", &usingOrEof, op)
}
case values.PAIR:
iz.Throw("init/request/pair", &usingOrEof, op)
iz.Throw("init/request/pair", &usingOrEof)
case values.SET:
switch op {
case "+":
Expand Down Expand Up @@ -1790,8 +1790,8 @@ func (iz *initializer) CompileEverything() [][]labeledParsedCodeChunk {
iz.p.Throw("init/depend/cmd", dec.chunk.GetToken())
return nil
}
if rhsDec.decType == variableDeclaration {
iz.p.Throw("init/depend/const/var", dec.chunk.GetToken())
if rhsDec.decType == variableDeclaration && dec.decType != variableDeclaration{
iz.p.Throw("init/depend/var", dec.chunk.GetToken())
return nil
}
}
Expand Down Expand Up @@ -1837,12 +1837,12 @@ func (iz *initializer) CompileEverything() [][]labeledParsedCodeChunk {
decType := namesToDeclarations[svName][0].decType
decNumber := namesToDeclarations[svName][0].decNumber
if len(rhs) > 0 {
iz.p.Throw("init/service/depends", tok)
iz.p.Throw("init/service/depends", tok, svName)
return nil
}
iz.compileGlobalConstantOrVariable(decType, decNumber)
if svData.T != iz.cp.Vm.Mem[iz.cp.That()].T {
iz.p.Throw("init/service/type", tok)
iz.p.Throw("init/service/type", tok, svName, iz.cp.GetTypeNameFromNumber(svData.T))
return nil
}
delete(graph, svName)
Expand Down

0 comments on commit 89a5575

Please sign in to comment.