Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sleep calls without parentheses #1461

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion DMCompiler/Compiler/DM/DMParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,20 @@ public DMASTFile File() {
if (expression != null) {
switch (expression) {
case DMASTIdentifier identifier:
Check(TokenType.DM_Colon);
// This could be a sleep without parentheses
if (!Check(TokenType.DM_Colon) && !leadingColon && identifier.Identifier == "sleep") {
var procIdentifier = new DMASTCallableProcIdentifier(expression.Location, "sleep");
var sleepTime = Expression();
if (sleepTime == null) // The argument is optional
sleepTime = new DMASTConstantNull(Location.Internal);

// TODO: Make sleep an opcode
expression = new DMASTProcCall(expression.Location, procIdentifier,
new[] { new DMASTCallParameter(sleepTime.Location, sleepTime) });
break;
}

// But it was a label
return Label(identifier);
case DMASTRightShift rightShift:
// A right shift on its own becomes a special "input" statement
Expand Down