Progmasoft Git

tazel

A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.

Clonegit clone https://git.progmasoft.com/tazel

Let the last entry of the text files leave out its semicolon

tazel_options.txt already took its last option without a ';'; now
tazel_envs.txt and tazel_custom.txt take their last value and command the
same way. Between two entries the ';' is needed: in tazel_custom.txt the
steps of a command go on only while a step starts, '(' or s(, so a name that
follows without ';' is still error[E0305] at its place, and a value of
tazel_envs.txt followed by another is still error[E0406].

The tests that wanted a ';' at the end of the file now have a second entry
after the first, and DiagnosticTests check that each file takes its last
entry without one.
Commit
1579e5b29ee3329bf4ac6dabe9a313ac3e7dc5f3
Author
Leitwolf11 ·
Parents
6185ec224ceb

Files · Download .tar.gz

Changes

 CHANGELOG.md                                       |  3 +++
 docs/commands.md                                   |  7 ++++--
 .../Dsl/Custom/Parser/CustomParser.cs              | 14 +++++++++--
 src/Progmasoft.Tazel/Dsl/Envs/TazelEnvs.cs         |  7 +++++-
 tests/Progmasoft.Tazel.Tests/DiagnosticTests.cs    | 29 +++++++++++++++++-----
 tests/Progmasoft.Tazel.Tests/EnvsTests.cs          |  1 -
 tests/Progmasoft.Tazel.Tests/TextFileTests.cs      |  2 +-
 7 files changed, 50 insertions(+), 13 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index fd53866..78c02b8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,9 @@
 
 ## Unreleased
 
+- The last entry of `tazel_envs.txt`, `tazel_custom.txt` and `tazel_options.txt` may end the file without its `;`;
+  between two entries the `;` is needed, and its absence is still `error[E0406]` and `error[E0305]`.
+
 - Signed remote cache results: `PublicKey` and `SigningKey` of `Remote.From`, written as `ed25519:`, `rsa-4096:` or
   `ml-dsa-65:` and the key in base64. Writers sign each result; readers take only results signed with their key's
   algorithm and verified by it. `tazel cache keygen [--algorithm ed25519|rsa-4096|ml-dsa]` makes a pair; a key Tazel
diff --git a/docs/commands.md b/docs/commands.md
index 09bdbcf..0e18558 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -105,7 +105,9 @@ build with: ("tazel" "build" <1> <2>);
 A command is a name of one or more words, a colon, and steps that run in order until one fails. `("program" "arg")`
 starts a program directly; `s("line")` gives one line to the shell (CMD on Windows, `sh` elsewhere). Strings take
 double quotes, single quotes or backticks and have no escapes. `<N>` is the Nth argument after the name, `<*>` all of
-them. The longest name that fits the command line wins, and `--` ends the name.
+them. The longest name that fits the command line wins, and `--` ends the name. Each command ends with `;`, which the
+last one in the file may leave out, as may the last option of `tazel_options.txt` and the last value of
+`tazel_envs.txt`.
 
 ## Queries
 
@@ -172,7 +174,8 @@ using Progmasoft.Tazel.Dsl.Environment;
 var exampleVersion = GetEnvironment.From("example-version"); // "0.1.0"; null for a name the file does not have
 ```
 
-- It is read with the lexer of `tazel_custom.txt`: the same comments and strings; every value ends with `;`.
+- It is read with the lexer of `tazel_custom.txt`: the same comments and strings; every value ends with `;`, which
+  the last one in the file may leave out.
 - A string is the value as written. `("program" "argument")` starts a program directly, each string one argument;
   `s("line")` gives one line to `/bin/sh` on Linux, macOS and the BSDs and to `cmd.exe` on Windows. Their value is
   what they print, less the line endings at its end. A program runs when its value is first asked for, once per
diff --git a/src/Progmasoft.Tazel/Dsl/Custom/Parser/CustomParser.cs b/src/Progmasoft.Tazel/Dsl/Custom/Parser/CustomParser.cs
index 06bc521..a71c92d 100644
--- a/src/Progmasoft.Tazel/Dsl/Custom/Parser/CustomParser.cs
+++ b/src/Progmasoft.Tazel/Dsl/Custom/Parser/CustomParser.cs
@@ -57,9 +57,14 @@ public static class CustomParser
                 {
                     steps.Add(Step());
                 }
-                while (Peek() is { Kind: not TokenKind.Semicolon });
+                while (StartsAStep());
+
+                // The last command may end the file without a ';'; between two commands it is needed.
+                if (Peek() is not null)
+                {
+                    Take(TokenKind.Semicolon, "';' at the end of a command");
+                }
 
-                Take(TokenKind.Semicolon, "';' at the end of a command");
                 var joined = string.Join(' ', words);
                 if (commands.ContainsKey(joined))
                 {
@@ -160,6 +165,11 @@ public static class CustomParser
             : token.Text == "*" ? new CustomArgument.All()
             : new CustomArgument.Position(int.Parse(token.Text, CultureInfo.InvariantCulture));
 
+        /// <summary>Whether a step comes next: a '(', or the s of an s(...).</summary>
+        private bool StartsAStep() =>
+            Peek() is { Kind: TokenKind.Open } ||
+            (Peek() is { Kind: TokenKind.Name, Text: "s" } && _position + 1 < tokens.Count && tokens[_position + 1].Kind == TokenKind.Open);
+
         private CustomStep Step()
         {
             var shell = Peek() is { Kind: TokenKind.Name, Text: "s" };
diff --git a/src/Progmasoft.Tazel/Dsl/Envs/TazelEnvs.cs b/src/Progmasoft.Tazel/Dsl/Envs/TazelEnvs.cs
index 1425de3..5f9f7ad 100644
--- a/src/Progmasoft.Tazel/Dsl/Envs/TazelEnvs.cs
+++ b/src/Progmasoft.Tazel/Dsl/Envs/TazelEnvs.cs
@@ -76,7 +76,12 @@ public static class TazelEnvsFile
                 names[name.Text] = name;
                 Take(TokenKind.Colon, $"':' after {name.Text}");
                 var value = Value(name);
-                Take(TokenKind.Semicolon, $"';' after the value of {name.Text}");
+                // The last value may end the file without a ';'.
+                if (Peek is not null)
+                {
+                    Take(TokenKind.Semicolon, $"';' after the value of {name.Text}");
+                }
+
                 entries.Add(new EnvEntry(name.Text, value, name.Line));
             }
 
diff --git a/tests/Progmasoft.Tazel.Tests/DiagnosticTests.cs b/tests/Progmasoft.Tazel.Tests/DiagnosticTests.cs
index 0dc3ccf..5a0c3c4 100644
--- a/tests/Progmasoft.Tazel.Tests/DiagnosticTests.cs
+++ b/tests/Progmasoft.Tazel.Tests/DiagnosticTests.cs
@@ -16,7 +16,7 @@ namespace Progmasoft.Tazel.Tests;
 public sealed class DiagnosticTests
 {
     [Theory]
-    [InlineData("envs", "x: '1'")]
+    [InlineData("envs", "x: '1' y: '2';")]
     [InlineData("envs", "x '1';")]
     [InlineData("envs", "x: '1';\nx: '2';")]
     [InlineData("envs", "x: version;")]
@@ -28,7 +28,7 @@ public sealed class DiagnosticTests
     [InlineData("envs", "<# open")]
     [InlineData("envs", "x: @;")]
     [InlineData("custom", "build (\"tazel\");")]
-    [InlineData("custom", "build: (\"tazel\")")]
+    [InlineData("custom", "build: (\"tazel\") test: (\"tazel\");")]
     [InlineData("custom", "build: ();")]
     [InlineData("custom", "build: s(\"a\" \"b\");")]
     [InlineData("custom", "build: (<1>);")]
@@ -56,7 +56,7 @@ public sealed class DiagnosticTests
     [Fact]
     public void AMissingSemicolonIsMarkedRightAfterTheValue()
     {
-        var diagnostic = DiagnosticOf("envs", "example-version: '0.1.0'\n")!;
+        var diagnostic = DiagnosticOf("envs", "example-version: '0.1.0'\nexample-name: 'tazel';\n")!;
         Assert.Equal((1, 25), (diagnostic.Line, diagnostic.Column));
         Assert.Equal("a ';' goes here", diagnostic.Label);
         Assert.Contains("example-version: '0.1.0';", diagnostic.Help, StringComparison.Ordinal);
@@ -74,7 +74,7 @@ public sealed class DiagnosticTests
     public async Task TheErrorIsDrawnWithTheLineAMarkHelpAndAJoke()
     {
         using var module = new TemporaryModule().Write("MODULE.csx", TemporaryModule.ModuleFile)
-            .Write("tazel_envs.txt", "example-version: '0.1.0'\n");
+            .Write("tazel_envs.txt", "example-version: '0.1.0'\nexample-name: 'tazel';\n");
         var (status, output) = await module.TazelAsync(".", "build", "//...", "--quiet");
         Assert.Equal(1, status);
         Assert.Contains("error[E0406]: expected ';' after the value of example-version", output, StringComparison.Ordinal);
@@ -102,17 +102,34 @@ public sealed class DiagnosticTests
     }
 
     [Theory]
-    [InlineData("envs", "x: '1'", "E0406")]
+    [InlineData("envs", "x: '1' y: '2';", "E0406")]
     [InlineData("envs", "x '1';", "E0407")]
     [InlineData("envs", "x: version;", "E0404")]
     [InlineData("envs", "x: \"open", "E0003")]
-    [InlineData("custom", "build: (\"tazel\")", "E0305")]
+    [InlineData("custom", "build: (\"tazel\") test: (\"tazel\");", "E0305")]
     [InlineData("custom", "build: s(\"a\" \"b\");", "E0311")]
     [InlineData("options", "platform: linux-amd46;", "E0211")]
     [InlineData("options", "microvm-cpus: 99999;", "E0210")]
     public void EachProblemHasItsOwnCode(string reader, string text, string code) =>
         Assert.Equal(code, DiagnosticOf(reader, text)!.Code);
 
+    [Theory]
+    [InlineData("envs", "x: '1'")]
+    [InlineData("envs", "x: '1'; y: s(\"echo 2\")")]
+    [InlineData("custom", "build: (\"tazel\")")]
+    [InlineData("custom", "build: (\"tazel\") s(\"echo done\"); test: (\"tazel\" \"test\")")]
+    [InlineData("options", "platform: linux-amd64")]
+    public void TheLastEntryMayEndTheFileWithoutItsSemicolon(string reader, string text)
+    {
+        var entries = reader switch
+        {
+            "envs" => TazelEnvsFile.Parse(text).Count,
+            "custom" => CustomParser.Parse(text).Count,
+            _ => TazelOptionsFile.Parse(text).Platform is null ? 0 : 1,
+        };
+        Assert.True(entries >= 1);
+    }
+
     [Fact]
     public void EveryCodeIsWrittenOnceAndExplained()
     {
diff --git a/tests/Progmasoft.Tazel.Tests/EnvsTests.cs b/tests/Progmasoft.Tazel.Tests/EnvsTests.cs
index 9a71a76..f1ed7d6 100644
--- a/tests/Progmasoft.Tazel.Tests/EnvsTests.cs
+++ b/tests/Progmasoft.Tazel.Tests/EnvsTests.cs
@@ -39,7 +39,6 @@ public sealed class EnvsTests
 
     [Theory]
     [InlineData("a: 'x';\na: 'y';", "'a' is set twice")]
-    [InlineData("a: 'x'", "expected ';' after the value of a")]
     [InlineData("a: 'x' b: 'y';", "expected ';' after the value of a")]
     [InlineData("a 'x'", "expected ':' after a")]
     [InlineData("a: ();", "a program names at least itself")]
diff --git a/tests/Progmasoft.Tazel.Tests/TextFileTests.cs b/tests/Progmasoft.Tazel.Tests/TextFileTests.cs
index 424305b..85fe273 100644
--- a/tests/Progmasoft.Tazel.Tests/TextFileTests.cs
+++ b/tests/Progmasoft.Tazel.Tests/TextFileTests.cs
@@ -67,7 +67,7 @@ public sealed class CustomCommandTests
     [InlineData("x: ('a' <0>);", "<0> is not an argument")]
     [InlineData("x: ('a);", "has no closing '")]
     [InlineData("<# x", "no closing #>")]
-    [InlineData("x: ('a')", "expected ';' at the end of a command")]
+    [InlineData("x: ('a') y: ('b');", "expected ';' at the end of a command")]
     [InlineData("x -- y: ('a');", "cannot hold it")]
     public void RefusesWhatIsWrongWithItsPlace(string text, string reason)
     {