Skip to content

Commit 751ace1

Browse files
committed
v1.0.2 is out - Release Notes are wrong
1 parent 031ea0c commit 751ace1

6 files changed

Lines changed: 114 additions & 11 deletions

File tree

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.{cs,vb}]
2+
3+
# IDE0028: Simplify collection initialization
4+
dotnet_diagnostic.IDE0028.severity = none

RSML.CLI/Program.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,18 @@ static async Task Main(string[] args)
103103
description: "Fallback for error scenarios",
104104
getDefaultValue: () => null
105105
);
106+
var customRidOption = new Option<string?>(
107+
aliases: ["--custom-rid", "-r", "--rid"],
108+
description: "Custom RID to check against",
109+
getDefaultValue: () => null
110+
);
106111

107112
evaluateCommand.AddOption(printOnlyPrimaryOption);
113+
evaluateCommand.AddOption(customRidOption);
108114
evaluateCommand.AddOption(fallbackForErrorOption);
109115
evaluateCommand.AddOption(fallbackForNullOption);
110116

111-
evaluateCommand.SetHandler(void (primaryOnly, nullFallback, errorFallback) =>
117+
evaluateCommand.SetHandler(void (primaryOnly, nullFallback, errorFallback, customRid) =>
112118
{
113119

114120
string? currentInState = Console.In.ReadToEnd();
@@ -143,7 +149,9 @@ static async Task Main(string[] args)
143149
try
144150
{
145151

146-
Console.WriteLine(document.EvaluateDocument() ?? ((nullFallback ?? "") == "" ? "[WARNING] No match was found." : nullFallback!));
152+
Console.WriteLine(customRid is null
153+
? document.EvaluateDocument() ?? ((nullFallback ?? "") == "" ? "[WARNING] No match was found." : nullFallback!)
154+
: document.EvaluateDocument(customRid, null) ?? ((nullFallback ?? "") == "" ? "[WARNING] No match was found." : nullFallback!));
147155

148156
}
149157
catch (RSMLRuntimeException ex)
@@ -156,7 +164,7 @@ static async Task Main(string[] args)
156164

157165
Environment.Exit(0);
158166

159-
}, printOnlyPrimaryOption, fallbackForNullOption, fallbackForErrorOption);
167+
}, printOnlyPrimaryOption, fallbackForNullOption, fallbackForErrorOption, customRidOption);
160168

161169
evaluateCommand.AddAlias("eval");
162170
evaluateCommand.AddAlias("parse");

RSML/Parser/RSParser.cs

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,80 @@ protected byte HandleSpecialFunctionCall(string line)
217217

218218
}
219219

220+
/// <summary>
221+
/// Handles a RSML action, using a custom RID.
222+
/// </summary>
223+
/// <param name="line">The RSML line</param>
224+
/// <param name="operatorType">The operator (primary, secondary or tertiary - all of them must be defined)</param>
225+
/// <param name="customRid">A custom RID to use as system identifier</param>
226+
/// <returns>Null if there was no match or the return value/argument as a string (even if the action was not primary).</returns>
227+
/// <exception cref="UndefinedActionException">At least one action is undefined.</exception>
228+
protected string? HandleAction(string line, OperatorType operatorType, string customRid)
229+
{
230+
231+
if (secondaryAction is null || tertiaryAction is null)
232+
{
233+
234+
throw new UndefinedActionException("All actions must be defined for them to be handled, even if only primary ones are used.");
235+
236+
}
237+
238+
// split the line
239+
string[] splitLine = line.Split(operatorType == OperatorType.Primary ?
240+
primaryActionDelimiter : (operatorType == OperatorType.Secondary) ?
241+
secondaryActionDelimiter : tertiaryActionDelimiter);
242+
243+
// not enough tokens, fuckersss
244+
if (splitLine.Length < 2) return null; // ignore it like a comment
245+
246+
// get system name
247+
string systemName = splitLine[0].Trim();
248+
249+
// quick evaluation
250+
if (!Regex.IsMatch(customRid, $"^{systemName}$")) return null;
251+
252+
string returnValue = splitLine[1].Trim();
253+
254+
if (returnValue.Length < 3 || !(returnValue.StartsWith('"') && returnValue.EndsWith('"'))) // the quotes and the characters inside of it
255+
{
256+
257+
return null; // commenttttttttt
258+
259+
}
260+
261+
string trimmedArgument = returnValue[1..^1];
262+
263+
switch (operatorType)
264+
{
265+
266+
case OperatorType.Secondary:
267+
secondaryAction.Invoke(this, trimmedArgument);
268+
break;
269+
270+
case OperatorType.Tertiary:
271+
tertiaryAction.Invoke(this, trimmedArgument);
272+
break;
273+
274+
}
275+
276+
return trimmedArgument; // ignore the quotes
277+
278+
}
279+
280+
/// <summary>
281+
/// Evaluate RSML.
282+
/// </summary>
283+
/// <param name="linesepChar">The line separation string to use (defaults to system line separation)</param>
284+
/// <returns>The evaluated result (only for primary action; if there's a secondary/tertiary match, it's ignored) or null (no primary matches)</returns>
285+
public string? EvaluateRSML(string? linesepChar = null) => EvaluateRSMLWithCustomRid(RuntimeInformation.RuntimeIdentifier, linesepChar);
286+
220287
/// <summary>
221288
/// Evaluate RSML.
222289
/// </summary>
290+
/// <param name="customRid">A custom RID to check against</param>
223291
/// <param name="linesepChar">The line separation string to use (defaults to system line separation)</param>
224292
/// <returns>The evaluated result (only for primary action; if there's a secondary/tertiary match, it's ignored) or null (no primary matches)</returns>
225-
public string? EvaluateRSML(string? linesepChar = null)
293+
public string? EvaluateRSMLWithCustomRid(string customRid, string? linesepChar = null)
226294
{
227295

228296
foreach (string line in content.Split(linesepChar ?? Environment.NewLine))
@@ -260,7 +328,7 @@ protected byte HandleSpecialFunctionCall(string line)
260328
else if (line.Contains(primaryActionDelimiter))
261329
{
262330

263-
string? actionReturnValue = HandleAction(line);
331+
string? actionReturnValue = HandleAction(line, OperatorType.Primary, customRid);
264332

265333
if (actionReturnValue is not null)
266334
{
@@ -270,20 +338,24 @@ protected byte HandleSpecialFunctionCall(string line)
270338
}
271339

272340
}
341+
273342
#pragma warning disable IDE0058 // expression value unused
274343
else if (line.Contains(secondaryActionDelimiter))
275344
{
276345

277-
HandleAction(line, OperatorType.Secondary);
346+
HandleAction(line, OperatorType.Secondary, customRid);
278347

279348
}
349+
280350
else if (line.Contains(tertiaryActionDelimiter))
281351
{
282352

283-
HandleAction(line, OperatorType.Tertiary);
353+
HandleAction(line, OperatorType.Tertiary, customRid);
284354

285355
}
356+
286357
#pragma warning restore
358+
287359
else continue;
288360

289361
}

RSML/RSDocument.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ public static RSDocument NewFromFile(string filepath)
8080
/// <returns>Null if no priamry matches or a string matching the return value of the only primary match</returns>
8181
public string? EvaluateDocument(string lineSeparation) => parser.EvaluateRSML(lineSeparation);
8282

83+
/// <summary>
84+
/// Parses and evaluates the document.
85+
/// </summary>
86+
/// <param name="customRid">The custom RID to check against</param>
87+
/// <param name="lineSeparation">The custom line separation character to use</param>
88+
/// <returns>Null if no priamry matches or a string matching the return value of the only primary match</returns>
89+
public string? EvaluateDocument(string customRid, string? lineSeparation = null) => parser.EvaluateRSMLWithCustomRid(customRid, lineSeparation);
90+
8391
}
8492

8593
}

RSML/RSML.csproj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,31 @@
1818
<PackageTags>Markup;Crossroad</PackageTags>
1919
<PackageLicenseFile>LICENSE</PackageLicenseFile>
2020
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
21-
<Version>1.0.1</Version>
22-
<FileVersion>1.0.0.2</FileVersion>
21+
<Version>1.0.2</Version>
22+
<FileVersion>1.0.0.3</FileVersion>
2323
<InformationalVersion>$(Version)</InformationalVersion>
2424

2525
<!-- no source revision thank you -->
2626
<SourceRevisionId></SourceRevisionId>
2727
<Platforms>AnyCPU;x64;x86</Platforms>
28+
<PackageReleaseNotes>
29+
v1.0.3 added support for rid emulation.
30+
From an OS, you may emulate the evaluation of RSML as if you were doing it from another.
31+
32+
In CLI: RSML.CLI evaluate --custom-rid
33+
</PackageReleaseNotes>
2834
</PropertyGroup>
2935

3036
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
3137
<DebugType>none</DebugType>
3238
</PropertyGroup>
3339

3440
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
35-
<DebugType>none</DebugType>
41+
<DebugType>none</DebugType>
3642
</PropertyGroup>
3743

3844
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
39-
<DebugType>none</DebugType>
45+
<DebugType>none</DebugType>
4046
</PropertyGroup>
4147

4248
<ItemGroup>

RedSeaMarkupLanguage.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "RSML.Docs", "RSML.Docs\RSML
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RSML.CLI", "RSML.CLI\RSML.CLI.csproj", "{F365A776-5802-42A8-BF46-0A5046421B31}"
1111
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{089100B1-113F-4E66-888A-E83F3999EAFD}"
13+
ProjectSection(SolutionItems) = preProject
14+
.editorconfig = .editorconfig
15+
EndProjectSection
16+
EndProject
1217
Global
1318
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1419
Debug|Any CPU = Debug|Any CPU

0 commit comments

Comments
 (0)