-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,12 +370,14 @@ private Stmt VarDeclaration() | |
// Support optional typing on this form: | ||
// var s: String; | ||
Token typeSpecifier = null; | ||
|
||
if (Match(COLON)) | ||
{ | ||
typeSpecifier = Consume(IDENTIFIER, "Expecting type name."); | ||
} | ||
|
||
Expr initializer = null; | ||
|
||
if (Match(EQUAL)) | ||
{ | ||
initializer = Expression(); | ||
|
@@ -387,6 +389,7 @@ private Stmt VarDeclaration() | |
} | ||
|
||
return new Stmt.Var(name, initializer, new TypeReference(typeSpecifier)); | ||
|
||
} | ||
Check failure on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / test (ubuntu-22.04)
Check warning on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (linux-arm)
Check warning on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (linux-arm)
Check failure on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (linux-arm)
Check failure on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / build-website
Check failure on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (linux-arm64)
Check warning on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (linux-arm64)
Check warning on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (linux-arm64)
Check warning on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (linux-x64)
Check warning on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (linux-x64)
Check failure on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (linux-x64)
Check warning on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (osx-arm64)
Check warning on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (osx-arm64)
Check failure on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (osx-arm64)
Check warning on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (osx-x64)
Check warning on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (osx-x64)
Check failure on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (osx-x64)
Check warning on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (win-x64)
Check warning on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (win-x64)
Check failure on line 393 in src/Perlang.Parser/PerlangParser.cs GitHub Actions / publish-snapshot-packages (win-x64)
|
||
|
||
private Stmt WhileStatement() | ||
|
@@ -795,6 +798,30 @@ private Expr Primary() | |
return new Expr.Grouping(expr); | ||
} | ||
|
||
if (Match(LEFT_SQUARE_BRACKET)) | ||
{ | ||
var startToken = Previous(); | ||
var elements = new List<Expr>(); | ||
|
||
while (!Peek().Type.Equals(RIGHT_SQUARE_BRACKET) && !IsAtEnd) | ||
{ | ||
elements.Add(Expression()); | ||
|
||
if (Match(COMMA)) | ||
{ | ||
continue; | ||
} | ||
else | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
Consume(RIGHT_SQUARE_BRACKET, "Expect ']' at end of collection initializer."); | ||
|
||
return new Expr.CollectionInitializer(elements, startToken); | ||
} | ||
|
||
if (Check(SEMICOLON)) | ||
{ | ||
// Bare semicolon, no expression inside. To avoid having to handle pesky null exceptions all over | ||
|