Prexonite, a .NET hosted scripting language with a focus on meta-programming and embedded DSLs
0

Configure Feed

Select the types of activity you want to include in your feed.

PRX-65: support `(var x) = 5`

The grammar excluding that scenario was a leftover from the time when the rules around GetSetComplex were more strict.

Fixes PRX-65

Christian Klauser (Apr 5, 2022, 10:37 PM +0200) 2e806f14 6e0fc51b

+33 -8
-1
Prexonite/Compiler/Grammar/Parser.Expression.atg
··· 296 296 .) 297 297 = IF(isLambdaExpression()) 298 298 LambdaExpression<out expr> 299 - | lpar Expr<out expr> rpar 300 299 | HashLiteral<out expr> 301 300 | CoroutineCreation<out expr> 302 301 | LoopExpr<out expr>
+9 -1
Prexonite/Compiler/Grammar/Parser.Statement.atg
··· 171 171 List<AstExpr> args = new List<AstExpr>(); 172 172 string id; 173 173 int placeholderIndex = -1; 174 + bool missingArg = false; 174 175 .) 175 176 = 176 177 //Actual value ··· 180 181 (. complex = actualComplex; .) 181 182 | StaticCall<out staticCall> 182 183 | lpar Expr<out expr> (. args.Add(expr); .) 183 - { comma Expr<out expr> (. args.Add(expr); .) //multiple expressions can only be used as arguments 184 + { WEAK comma (. if(missingArg) SemErr("Missing expression (two consecutive commas)."); .) 185 + ( Expr<out expr> (. args.Add(expr); .) //multiple expressions can only be used as arguments 186 + | (. missingArg = true; .) 187 + ) 184 188 } 185 189 rpar 186 190 ( GetSetExtension<expr, out member> ··· 191 195 GetCall<out actualComplex> (. _appendRight(args,actualComplex); 192 196 complex = actualComplex; 193 197 .) 198 + | (. if(args.Count > 1) 199 + SemErr("Expression in parentheses cannot have more than 1 value."); 200 + complex = args[0]; 201 + .) 194 202 ) 195 203 ) 196 204 (. complex =
+3 -3
Prexonite/Compiler/Macro/Commands/Unpack.cs
··· 102 102 public override PValue Run(StackContext sctx, PValue[] args) 103 103 { 104 104 MacroContext context; 105 - if (args.Length < 2 || !(args[0].Type is ObjectPType) || 105 + if (args.Length < 2 || args[0].Type is not ObjectPType || 106 106 (context = args[0].Value as MacroContext) == null) 107 107 throw new PrexoniteException(_getUsage()); 108 108 ··· 110 110 return context.RetrieveFromTransport(id); 111 111 112 112 AstConstant constant; 113 - if (!(args[1].Type is ObjectPType) || 114 - (constant = args[1].Value as AstConstant) == null || !(constant.Constant is int)) 113 + if (args[1].Type is not ObjectPType || 114 + (constant = args[1].Value as AstConstant) == null || constant.Constant is not int) 115 115 throw new PrexoniteException(_getUsage()); 116 116 117 117 return context.RetrieveFromTransport((int) constant.Constant);
+1 -1
PrexoniteTests/Tests/BuiltInTypesTest.cs
··· 41 41 42 42 namespace PrexoniteTests.Tests; 43 43 44 - public class BuiltInTypeTests : VMTestsBase 44 + public abstract class BuiltInTypeTests : VMTestsBase 45 45 { 46 46 [Test] 47 47 public void HashStaticMethodCreate()
+1 -1
PrexoniteTests/Tests/Configurations/V2UnitTestContainer.cs
··· 138 138 } 139 139 } 140 140 141 - private static readonly PValue[] Empty = new PValue[0]; 141 + private static readonly PValue[] Empty = Array.Empty<PValue>(); 142 142 143 143 private static (string Id, Application ParentApplication) extract(StackContext sctx, PValue funcValue) 144 144 {
+1
PrexoniteTests/Tests/Configurations/VMTestConfigurations.tt
··· 157 157 "PrexoniteTests.Tests.PartialApplication", 158 158 "PrexoniteTests.Tests.Lazy", 159 159 "PrexoniteTests.Tests.Translation", 160 + "PrexoniteTests.Tests.BuiltInTypeTests", 160 161 "PrexoniteTests.Tests.ShellExtensions" 161 162 }; 162 163 }
+18 -1
PrexoniteTests/Tests/Translation.cs
··· 41 41 42 42 namespace PrexoniteTests.Tests; 43 43 44 - public class Translation : VMTestsBase 44 + public abstract class Translation : VMTestsBase 45 45 { 46 46 [Test] 47 47 public void SimpleSwitchMetaEntry() ··· 1598 1598 function main = println(?*); 1599 1599 "); 1600 1600 Assert.That(ldr.Errors.Where(m => m.MessageClass == MessageClasses.IncompleteBinaryOperation), Is.Not.Empty); 1601 + } 1602 + 1603 + [Test] 1604 + public void LhsInParentheses() 1605 + { 1606 + Compile(@" 1607 + function f(x) = 2*x; 1608 + function main(x,y) { 1609 + (var z) = x; 1610 + ((var u)) = y; 1611 + (x)++; 1612 + ((y))--; 1613 + var v = (z) >> f; 1614 + return ""x=$x y=$y z=$z u=$u v=$v""; 1615 + } 1616 + "); 1617 + Expect("x=6 y=8 z=5 u=9 v=10", 5, 9); 1601 1618 } 1602 1619 1603 1620 [ContractAnnotation("value:null=>halt")]