Skip to content

Commit 2e4d664

Browse files
committed
improve error messages for top-level SLiM script syntax errors
1 parent b6440db commit 2e4d664

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

core/slim_eidos_block.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ EidosASTNode *SLiMEidosScript::Parse_SLiMEidosBlock(void)
239239
Match(EidosTokenType::kTokenIdentifier, "SLiM script block");
240240
}
241241

242+
if (current_token_->token_type_ == EidosTokenType::kTokenLBrace)
243+
EIDOS_TERMINATION << "ERROR (SLiMEidosScript::Parse_SLiMEidosBlock): unexpected token " << *current_token_ << "; expected an event declaration (first, early, late), a callback declaration (initialize, fitnessEffect, interaction, mateChoice, modifyChild, mutation, mutationEffect, recombination, reproduction, or survival), a function declaration, or a tick range specifier. Note that early() is no longer a default script block type that may be omitted; it must now be specified explicitly." << EidosTerminate(current_token_);
244+
if (current_token_->token_type_ == EidosTokenType::kTokenRBrace)
245+
EIDOS_TERMINATION << "ERROR (SLiMEidosScript::Parse_SLiMEidosBlock): unexpected token " << *current_token_ << "; expected an event declaration (first, early, late), a callback declaration (initialize, fitnessEffect, interaction, mateChoice, modifyChild, mutation, mutationEffect, recombination, reproduction, or survival), a function declaration, or a tick range specifier. An extra closing brace might be present at the end of the preceding script block." << EidosTerminate(current_token_);
246+
242247
// Next comes an optional tick X, or a tick range X:Y, X:, or :Y (a lone : is not legal).
243248
// We don't parse this as if the : were an operator, since we have to allow for a missing start or end;
244249
// for this reason, we make the : into a node of its own, with no children, so X:Y, X:, and :Y are distinct.
@@ -744,7 +749,16 @@ EidosASTNode *SLiMEidosScript::Parse_SLiMEidosBlock(void)
744749
else
745750
{
746751
if (!parse_make_bad_nodes_)
747-
EIDOS_TERMINATION << "ERROR (SLiMEidosScript::Parse_SLiMEidosBlock): unexpected token " << *current_token_ << "; expected an event declaration (first, early, late), a callback declaration (initialize, fitnessEffect, interaction, mateChoice, modifyChild, mutation, mutationEffect, recombination, reproduction, or survival), or a function declaration. Note that early() is no longer a default script block type that may be omitted; it must now be specified explicitly." << EidosTerminate(current_token_);
752+
{
753+
if (current_token_->token_type_ == EidosTokenType::kTokenLBrace)
754+
{
755+
EIDOS_TERMINATION << "ERROR (SLiMEidosScript::Parse_SLiMEidosBlock): unexpected token " << *current_token_ << "; expected an event declaration (first, early, late), a callback declaration (initialize, fitnessEffect, interaction, mateChoice, modifyChild, mutation, mutationEffect, recombination, reproduction, or survival), or a function declaration. Note that early() is no longer a default script block type that may be omitted; it must now be specified explicitly." << EidosTerminate(current_token_);
756+
}
757+
else
758+
{
759+
EIDOS_TERMINATION << "ERROR (SLiMEidosScript::Parse_SLiMEidosBlock): unexpected token " << *current_token_ << "; expected an event declaration (first, early, late), a callback declaration (initialize, fitnessEffect, interaction, mateChoice, modifyChild, mutation, mutationEffect, recombination, reproduction, or survival), or a function declaration." << EidosTerminate(current_token_);
760+
}
761+
}
748762

749763
// Consume the stray identifier, to be error-tolerant
750764
Consume();

0 commit comments

Comments
 (0)