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-40: make `{}` optional for namespace re-export

You can now write

```
namespace target export source(*);
```

instead of

```
namespace target { } export source(*);
```

If you omit the braces, an export clause or a semicolon are mandatory (e.g., `namespace ns` alone is not legal)

Christian Klauser (Apr 6, 2022, 10:06 PM +0200) fc1e738b 6a0b2172

+74 -46
+19 -4
Prexonite/Compiler/Grammar/Parser.GlobalScope.atg
··· 1113 1113 1114 1114 NamespaceDeclaration (. QualifiedId? fullNsId = null; 1115 1115 DeclarationScope scope = null; 1116 - ISourcePosition qualIdPos,exportPos; 1116 + ISourcePosition qualIdPos; 1117 + ISourcePosition exportPos = GetNextPosition(); // fallback for errors 1117 1118 List<SymbolTransferDirective> directives; 1118 1119 SymbolOrigin origin; 1119 1120 var implicitSelfImport = true; 1121 + var hasBody = false; 1120 1122 .) 1121 1123 = (. .) 1122 1124 namespace (. qualIdPos = GetPosition(); .) ··· 1167 1169 } 1168 1170 Loader.PushScope(declBuilder.ToDeclarationScope()); 1169 1171 .) 1170 - lbrace 1171 - DeclarationLevel (. exportPos = GetPosition(); // this position is used when there is no export-spec 1172 + ( 1173 + lbrace 1174 + DeclarationLevel (. exportPos = GetPosition(); // this position is used when there is no export-spec 1175 + hasBody = true; 1172 1176 .) 1173 - rbrace (. scope = _popDeclScope(); 1177 + rbrace 1178 + | (. exportPos = GetPosition(); .) 1179 + ) (. scope = _popDeclScope(); 1174 1180 var exportBuilder = SymbolStoreBuilder.Create(); .) 1175 1181 ( (. _pushLexerState(Lexer.Transfer); .) 1176 1182 export ··· 1204 1210 _indexExportedSymbols(scope.Store), 1205 1211 SymbolTransferDirective.CreateWildcard(exportPos).Singleton()); 1206 1212 .) 1213 + ( semicolon 1214 + | (. if(!hasBody) 1215 + Loader.ReportMessage(Message.Error( 1216 + Resources.Parser_SkeletonNamespaceRequiresSemicolon, 1217 + GetPosition(), 1218 + MessageClasses.SkeletonNamespaceRequiresSemicolon) 1219 + ); 1220 + .) 1221 + ) 1207 1222 ) (. _updateNamespace(scope, exportBuilder); .) 1208 1223 .
+1
Prexonite/Compiler/MessageClasses.cs
··· 67 67 public const string IncompleteBinaryOperation = "P.IncompleteBinaryOperation"; 68 68 public const string ShiftedSymbolRequired = "P.ShiftedSymbolRequired"; 69 69 public const string TypeArgumentsNotSupported = "P.TypeArgumentsNotSupported"; 70 + public const string SkeletonNamespaceRequiresSemicolon = "P.SkeletonNamespaceRequiresSemicolon"; 70 71 71 72 #endregion 72 73
+3
Prexonite/Properties/Resources.resx
··· 472 472 <data name="TypeCheck_ExpectedTypeExpression" xml:space="preserve"> 473 473 <value>Expected type expression after `is [not]`.</value> 474 474 </data> 475 + <data name="Parser_SkeletonNamespaceRequiresSemicolon" xml:space="preserve"> 476 + <value>Semicolon `;` required after namespace without definitons.</value> 477 + </data> 475 478 </root>
+8 -35
Prexonite/prxlib/prx.core.pxs
··· 7 7 8 8 namespace prx.core 9 9 { 10 - namespace seq 11 - { 12 - 13 - } 14 - export(*),prx.prim( 10 + namespace seq export(*), prx.prim( 15 11 map,flat_map,foldl,foldr,sort,all => to_list, where => filter, skip,take, 16 12 count,distinct,union,unique,frequency,groupby,intersect,each,exists,forall, 17 13 takewhile,except,range, reverse, headtail, append, sum, contains, 18 14 create_enumerator,seqconcat); 19 15 20 - namespace nonstrict 21 - { 22 - 23 - } 24 - export(*),prx.prim(thunk,asthunk => to_thunk,force,toseq => to_seq); 16 + namespace nonstrict export(*),prx.prim(thunk,asthunk => to_thunk,force,toseq => to_seq); 25 17 26 18 namespace rt 27 19 { 28 - namespace builtin 29 - { 30 - 31 - } 32 - export(*),prx.prim( 20 + namespace builtin export(*),prx.prim( 33 21 // constructor (new T) 34 22 create_Bool, 35 23 create_Char, ··· 78 66 } 79 67 export(*),prx.prim(caller,LoadAssembly => load_assembly,debug, CompileToCil => compile_to_cil,boxed); 80 68 81 - namespace text 82 - { 69 + namespace text export(*),prx.prim(setcenter,setleft,setright); 83 70 84 - } 85 - export(*),prx.prim(setcenter,setleft,setright); 71 + namespace math export(*),prx.prim(abs,ceiling,exp,floor,log,max,min,pi,round,sin,cos,sqrt,tan); 86 72 87 - namespace math 88 - { 89 - 90 - } 91 - export(*),prx.prim(abs,ceiling,exp,floor,log,max,min,pi,round,sin,cos,sqrt,tan); 92 - 93 - namespace ct 94 - { 95 - 96 - } 97 - export(*),prx.prim(create_source_position, get_unscoped_ast_factory, 73 + namespace ct export(*),prx.prim( 74 + create_source_position, get_unscoped_ast_factory, 98 75 macro\pack => pack, macro\unpack => unpack, macro\reference => macro_reference, call\macro, 99 76 entityref_to); 100 77 } ··· 130 107 131 108 namespace prx.experimental 132 109 { 133 - namespace csp 134 - { 135 - 136 - } 137 - export(*), prx.prim(chan,async_seq,call\async,select); 110 + namespace csp export(*), prx.prim(chan,async_seq,call\async,select); 138 111 }
+23
PrexoniteTests/Tests/Compiler.Parser.cs
··· 3912 3912 Assert.That(ldr.Errors.Select(m => m.MessageClass), Contains.Item(MessageClasses.TypeExpressionExpected)); 3913 3913 } 3914 3914 3915 + [Test] 3916 + public void SkeletonNamespaceRequiresSemicolon() 3917 + { 3918 + var ldr = _justCompile(@" 3919 + namespace target 3920 + 3921 + function main() = ""f""; 3922 + "); 3923 + 3924 + Assert.That(ldr.Errors, Is.Not.Empty); 3925 + Assert.That(ldr.Errors.Select(m => m.MessageClass), Contains.Item(MessageClasses.SkeletonNamespaceRequiresSemicolon)); 3926 + } 3927 + 3928 + [Test] 3929 + public void SkeletonNamespaceTolerated() 3930 + { 3931 + _compile(@" 3932 + namespace target; 3933 + 3934 + function main() = ""f""; 3935 + "); 3936 + } 3937 + 3915 3938 }
+16
PrexoniteTests/Tests/Translation.cs
··· 1617 1617 Expect("x=6 y=8 z=5 u=9 v=10", 5, 9); 1618 1618 } 1619 1619 1620 + [Test] 1621 + public void NamespaceReExportBracesOptional() 1622 + { 1623 + Compile(@" 1624 + namespace source { 1625 + function f = ""f""; 1626 + } 1627 + 1628 + namespace target export source(*); 1629 + 1630 + function main() = target.f; 1631 + "); 1632 + 1633 + Expect("f"); 1634 + } 1635 + 1620 1636 [ContractAnnotation("value:null=>halt")] 1621 1637 private static void _assumeNotNull(object value) 1622 1638 {
+3 -6
Prx/psr/_2/psr/ast.pxs
··· 142 142 var no_location = Prexonite::Compiler::NoSourcePosition.Instance; 143 143 } 144 144 145 - namespace SI 146 - { 147 - } 148 - export(*), SI.ret(exit => ret\exit, set => ret\set, $continue => ret\continue, $break => ret\break); 145 + namespace SI export(*), SI.ret(exit => ret\exit, set => ret\set, $continue => ret\continue, $break => ret\break); 149 146 150 147 151 148 // Internal ··· 243 240 244 241 namespace SI 245 242 { 246 - namespace e {} export EntityRef(*); 247 - namespace s {} export Symbol(*); 243 + namespace e export EntityRef(*); 244 + namespace s export Symbol(*); 248 245 } 249 246 } 250 247 export(*), psr.ast.v1(
+1 -1
Prx/psr/_2/psr/struct.pxs
··· 14 14 build does add("../../impl/struct.pxs"); 15 15 } 16 16 17 - namespace psr {} export psr.struct.v1.struct; 17 + namespace psr export psr.struct.v1.struct;