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-8 Copy interpreter directive into output

If an application has an interpreter directive, it will get copied into the final output.

This probably won't get used much, but it's easy to add.

Also:
- Make newline used for output configurable
- Change newline used for output to be just `\n` on all platforms. Part of my ongoing crusade to ban all use or `\r\n` :P But it's also crucial to make the interpreter directive work out of the box. `\r` gets interpreted as part of the command line on Linux.

Christian Klauser (Apr 26, 2021, 12:52 PM +0200) d853c65d f8bb9131

+53 -5
+12 -4
Prexonite/Compiler/Loader.cs
··· 1114 1114 StoreCompressed(fstr); 1115 1115 else 1116 1116 #endif 1117 - using var writer = new StreamWriter(path, false); 1117 + using var writer = new StreamWriter(path, false) {NewLine = Options.StoreNewLine}; 1118 1118 Store(writer); 1119 1119 } 1120 1120 1121 1121 public string StoreInString() 1122 1122 { 1123 - var writer = new StringWriter(); 1123 + using var writer = new StringWriter {NewLine = Options.StoreNewLine}; 1124 1124 Store(writer); 1125 1125 return writer.ToString(); 1126 1126 } 1127 1127 1128 1128 public void Store(StringBuilder builder) 1129 1129 { 1130 - using var writer = new StringWriter(builder); 1130 + using var writer = new StringWriter(builder) {NewLine = Options.StoreNewLine}; 1131 1131 Store(writer); 1132 1132 } 1133 1133 ··· 1139 1139 throw new ArgumentNullException("str"); 1140 1140 1141 1141 using (GZipStream zip = new GZipStream(str, CompressionMode.Compress, true)) 1142 - using (StreamWriter writer = new StreamWriter(zip, Encoding.UTF8)) 1142 + using (StreamWriter writer = new StreamWriter(zip, Encoding.UTF8){NewLine = Options.StoreNewLine}) 1143 1143 { 1144 1144 writer.WriteLine("//PXSC"); 1145 1145 Store(writer); ··· 1152 1152 { 1153 1153 var app = ParentApplication; 1154 1154 1155 + // Interpreter line (if defined; nothing by default) 1156 + var interpreterLine = app.Meta[Application.InterpreterLineKey].Text; 1157 + if (!string.IsNullOrEmpty(interpreterLine)) 1158 + { 1159 + writer.Write("#!"); 1160 + writer.WriteLine(interpreterLine); 1161 + } 1162 + 1155 1163 //Header 1156 1164 writer.WriteLine("//PXS_"); 1157 1165 writer.WriteLine("//--GENERATED");
+16
Prexonite/Compiler/LoaderOptions.cs
··· 140 140 set => _flagLiteralsEnabled = value; 141 141 } 142 142 143 + [CanBeNull] 144 + private string? _storeNewLine; 145 + 146 + /// <summary> 147 + /// The line separator to use when storing a compiled Prexonite program. 148 + /// </summary> 149 + /// <see cref="Loader.Store(System.Text.StringBuilder)"/> 150 + [PublicAPI] 151 + [NotNull] 152 + public string StoreNewLine 153 + { 154 + get => _storeNewLine ?? "\n"; 155 + set => _storeNewLine = value; 156 + } 157 + 143 158 #endregion 144 159 145 160 public void InheritFrom([NotNull] LoaderOptions options) ··· 155 170 _storeSourceInformation ??= options._storeSourceInformation; 156 171 _preflightModeEnabled ??= options._preflightModeEnabled; 157 172 _flagLiteralsEnabled ??= options._flagLiteralsEnabled; 173 + _storeNewLine ??= options._storeNewLine; 158 174 } 159 175 } 160 176 }
+23
PrexoniteTests/Tests/Compiler.Global.cs
··· 344 344 Assert.That(ldr.ParentApplication.Meta["SomeOtherSettings"], 345 345 Is.EqualTo(new MetaEntry("Are Valid"))); 346 346 } 347 + 348 + [Test] 349 + public void InterpreterLineIncludedInStoredRepresentation() 350 + { 351 + const string previousInterpreterLine = "/usr/bin/prx"; 352 + target.Meta[Application.InterpreterLineKey] = previousInterpreterLine; 353 + var loader1 = _compile(@" 354 + SomeOtherSettings ""Are Valid""; 355 + "); 356 + var storedRepr = loader1.StoreInString(); 357 + Assert.That(storedRepr, Does.StartWith($"#!{previousInterpreterLine}\n")); 358 + 359 + var loader2 = new Loader(engine, new Application()); 360 + loader2.LoadFromString(storedRepr); 361 + Assert.That(loader2.Errors, Is.Empty); 362 + Assert.That(loader2.ParentApplication.Meta, Does.ContainKey(Application.InterpreterLineKey)); 363 + Assert.That(loader2.ParentApplication.Meta, Does.ContainKey("SomeOtherSettings")); 364 + 365 + Assert.That(loader2.ParentApplication.Meta[Application.InterpreterLineKey], 366 + Is.EqualTo(new MetaEntry(previousInterpreterLine))); 367 + Assert.That(loader2.ParentApplication.Meta["SomeOtherSettings"], 368 + Is.EqualTo(new MetaEntry("Are Valid"))); 369 + } 347 370 348 371 [Test] 349 372 public void InterpreterLineAfterNoise()
+2 -1
prx.sln.DotSettings
··· 1 1 <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> 2 2 <s:Boolean x:Key="/Default/UserDictionary/Words/=fctx/@EntryIndexedValue">True</s:Boolean> 3 - <s:Boolean x:Key="/Default/UserDictionary/Words/=predef/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> 3 + <s:Boolean x:Key="/Default/UserDictionary/Words/=predef/@EntryIndexedValue">True</s:Boolean> 4 + <s:Boolean x:Key="/Default/UserDictionary/Words/=Repr/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>