diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index c8baf76..a547b45 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -148,17 +148,17 @@ }, "active": "af9edaf1541aa592", "lastOpenFiles": [ - "codemirror-lang-rockstar/pnpm-lock.yaml.3042434986", - "codemirror-lang-rockstar/_tmp_46436_89968ddaabae1b280b8a0168b939c989", - "codemirror-lang-rockstar/package.json.902345379", - "codemirror-lang-rockstar/pnpm-lock.yaml.3146977705", - "codemirror-lang-rockstar/_tmp_10912_1fe8be06afbd0bb33b1e1728551a1d95", - "codemirror-lang-rockstar/src/highlight.js", - "codewithrockstar.com/_site/wasm/wwwroot/framework/System.Text.RegularExpressions.wasm.gz", - "codewithrockstar.com/_site/wasm/wwwroot/framework/System.Text.RegularExpressions.wasm.br", - "codewithrockstar.com/_site/wasm/wwwroot/framework/System.Text.RegularExpressions.wasm", - "codewithrockstar.com/_site/wasm/wwwroot/framework/System.Runtime.wasm.gz", - "codewithrockstar.com/_site/wasm/wwwroot/framework/System.Runtime.wasm.br", + "Starship/Rockstar.Test/ParserTests.cs~RF12443f04.TMP", + "Starship/Rockstar.Engine/rockstar.peg~RF124412d4.TMP", + "Starship/Rockstar.Engine/rockstar.peg~RF12438411.TMP", + "Starship/Rockstar.Engine/obj/Debug/net8.0/nCrunchTemp_f5669261-0dd5-4eda-8f98-23a933a271fd.csproj.AssemblyReference.cache", + "Starship/Rockstar.Engine/obj/Debug/net8.0/nCrunchTemp_f5669261-0dd5-4eda-8f98-23a933a271fd.GlobalUsings.g.cs", + "Starship/Rockstar.Engine/obj/Debug/net8.0/nCrunchTemp_f5669261-0dd5-4eda-8f98-23a933a271fd.assets.cache", + "Starship/Rockstar.Engine/nCrunchTemp_f5669261-0dd5-4eda-8f98-23a933a271fd.csproj", + "Starship/Rockstar.Engine/obj/nCrunchTemp_f5669261-0dd5-4eda-8f98-23a933a271fd.csproj.nuget.g.targets", + "Starship/Rockstar.Engine/obj/nCrunchTemp_f5669261-0dd5-4eda-8f98-23a933a271fd.csproj.nuget.g.props", + "Starship/Rockstar.Wasm/obj/Debug/net8.0/Rockstar.E1D2EFD7.Up2Date", + "Starship/Rockstar.Engine/rockstar.peg~RF1242aa89.TMP", "codewithrockstar.com/getting-started.md", "codewithrockstar.com/index copy.md" ] diff --git a/Starship/Rockstar.Engine/Rockstar.Engine.v3.ncrunchproject b/Starship/Rockstar.Engine/Rockstar.Engine.v3.ncrunchproject new file mode 100644 index 0000000..8a3f889 --- /dev/null +++ b/Starship/Rockstar.Engine/Rockstar.Engine.v3.ncrunchproject @@ -0,0 +1,7 @@ + + + + rockstar.peg + + + \ No newline at end of file diff --git a/Starship/Rockstar.Engine/Values/Value.cs b/Starship/Rockstar.Engine/Values/Value.cs index 5051e01..472b7b7 100644 --- a/Starship/Rockstar.Engine/Values/Value.cs +++ b/Starship/Rockstar.Engine/Values/Value.cs @@ -49,10 +49,16 @@ public abstract class Value(Source source) }; public Value Equäls(Value that) => (Booleän)((this, that) switch { + (Booleän a, _) => a.Truthy == that.Truthy, + (_, Booleän b) => this.Truthy == b.Truthy, (Number a, Number b) => a.Value == b.Value, + (Strïng s, Null b) => ! s.Truthy, (Strïng s, _) => s.Value.Equals(that.ToStrïng().Value), - (Booleän a, _) => a.Truthy == that.Truthy, - _ => throw new NotImplementedException() + (Number a, Null b) => a.Value == 0, + (Null a, Null b) => true, + (Number a, Strïng b) => Decimal.TryParse(b.Value, out var d) && d == a.Value, + (_, Strïng s) => s.Value.Equals(this.ToStrïng().Value), + _ => throw new NotImplementedException($"Equality not implemented for {this.GetType()} {that.GetType()}") }); public Value NotEquäls(Value that) diff --git a/Starship/Rockstar.Engine/rockstar.peg b/Starship/Rockstar.Engine/rockstar.peg index 5a324a6..b0adf38 100644 --- a/Starship/Rockstar.Engine/rockstar.peg +++ b/Starship/Rockstar.Engine/rockstar.peg @@ -10,14 +10,14 @@ program = __ EOF { new Progräm() } - / __ stmt:statement EOS* EOF + / __ stmt:statement __ EOF { new Progräm(stmt) } / __ head:statement EOS+ tail:program { tail.Insert(head) } / #error{ "Program error at line " + state.Line + ", col " + state.Column } __ = _? EOS* -EOS = _? EOL _? +EOS = EOL _? EOL = '\r'? '\n' EOF = !. diff --git a/Starship/Rockstar.Test/FixtureTests.cs b/Starship/Rockstar.Test/FixtureTests.cs index c4d87f8..7a82c50 100644 --- a/Starship/Rockstar.Test/FixtureTests.cs +++ b/Starship/Rockstar.Test/FixtureTests.cs @@ -25,10 +25,9 @@ public void RunFile(string filePath) { var line = source.Split('\n')[cursor.Line - 1].TrimEnd('\r'); testOutput.WriteLine(line); testOutput.WriteLine(String.Empty.PadLeft(cursor.Column - 1) + "^ error is here!"); - throw; - } finally { var ncrunchOutputMessage = $" at in {originalRockFilePath}:line {outputLine}"; testOutput.WriteLine(ncrunchOutputMessage); + throw; } try { var env = new TestEnvironment(); diff --git a/Starship/Rockstar.Test/ParserTests.cs b/Starship/Rockstar.Test/ParserTests.cs index 419e0a9..3662243 100644 --- a/Starship/Rockstar.Test/ParserTests.cs +++ b/Starship/Rockstar.Test/ParserTests.cs @@ -28,6 +28,9 @@ public void ParserParsesEmptyPrograms(string source) { [InlineData(" () say 1 \r\n")] [InlineData("(start with a comment line)\nsay 1 \r\n")] [InlineData("(start with a comment line)\r\n\r\nsay 1 \r\n")] + [InlineData(""" + say "pass" + """)] public void ParserParsesWeirdPrograms(string source) { var parser = new Parser(); var result = parser.Parse(source); diff --git a/Starship/Rockstar.Test/fixtures/equality/nothing.rock b/Starship/Rockstar.Test/fixtures/equality/nothing.rock index c6d55c3..ee3c466 100644 --- a/Starship/Rockstar.Test/fixtures/equality/nothing.rock +++ b/Starship/Rockstar.Test/fixtures/equality/nothing.rock @@ -1,9 +1,9 @@ -Say 0 is nothing -Say false is nothing -Say nobody is nothing -Say null is nothing -Say "" is nothing +Say 0 is nothing (prints: true) +Say false is nothing (prints: true) +Say nobody is nothing (prints: true) +Say null is nothing (prints: true) +Say "" is nothing (prints: true) -Say 1 is nothing -Say true is nothing -Say "hello" is nothing +Say 1 is nothing (prints: false) +Say true is nothing (prints: false) +Say "hello" is nothing (prints: false) diff --git a/Starship/Rockstar.Test/fixtures/equality/nothing.rock.out b/Starship/Rockstar.Test/fixtures/equality/nothing.rock.out deleted file mode 100644 index aabb84c..0000000 --- a/Starship/Rockstar.Test/fixtures/equality/nothing.rock.out +++ /dev/null @@ -1,8 +0,0 @@ -true -true -true -true -true -false -false -false diff --git a/Starship/Rockstar.Test/fixtures/equality/null.rock b/Starship/Rockstar.Test/fixtures/equality/null.rock index 3e6ce2c..907e9d6 100644 --- a/Starship/Rockstar.Test/fixtures/equality/null.rock +++ b/Starship/Rockstar.Test/fixtures/equality/null.rock @@ -1,5 +1,5 @@ -say true is null -say false is null -say null is null -say 0 is null -say 1 is null +say true is null (prints: false) +say false is null (prints: true) +say null is null (prints: true) +say 0 is null (prints: true) +say 1 is null (prints: false) diff --git a/Starship/Rockstar.Test/fixtures/equality/null.rock.out b/Starship/Rockstar.Test/fixtures/equality/null.rock.out deleted file mode 100644 index 8ef5add..0000000 --- a/Starship/Rockstar.Test/fixtures/equality/null.rock.out +++ /dev/null @@ -1,5 +0,0 @@ -false -true -true -true -false diff --git a/Starship/Rockstar.Test/fixtures/equality/numbers.rock b/Starship/Rockstar.Test/fixtures/equality/numbers.rock index 2a60652..0b58188 100644 --- a/Starship/Rockstar.Test/fixtures/equality/numbers.rock +++ b/Starship/Rockstar.Test/fixtures/equality/numbers.rock @@ -1,17 +1,17 @@ -say true is 5 -say 5 is true -say 0 is false -say false is 0 -say 0 is null -say 5 is 5 -say 5 is 5.0 -say 0.26 is 0.26 -say "5" is 5 -say 5 is "05.0" -say "" -say true is 0 -say 0 is true -say 1 is false -say false is 1 -say 1 is null -say 5 is 4 +say true is 5 (prints: true) +say 5 is true (prints: true) +say 0 is false (prints: true) +say false is 0 (prints: true) +say 0 is null (prints: true) +say 5 is 5 (prints: true) +say 5 is 5.0 (prints: true) +say 0.26 is 0.26 (prints: true) +say "5" is 5 (prints: true) +say 5 is "05.0" (prints: true) + +say true is 0 (prints: false) +say 0 is true (prints: false) +say 1 is false (prints: false) +say false is 1 (prints: false) +say 1 is null (prints: false) +say 5 is 4 (prints: false) diff --git a/Starship/Rockstar.Test/fixtures/equality/numbers.rock.out b/Starship/Rockstar.Test/fixtures/equality/numbers.rock.out deleted file mode 100644 index e31029f..0000000 --- a/Starship/Rockstar.Test/fixtures/equality/numbers.rock.out +++ /dev/null @@ -1,17 +0,0 @@ -true -true -true -true -true -true -true -true -true -true - -false -false -false -false -false -false diff --git a/Starship/Rockstar.Test/fixtures/equality/strings.rock b/Starship/Rockstar.Test/fixtures/equality/strings.rock index 2dca845..944d425 100644 --- a/Starship/Rockstar.Test/fixtures/equality/strings.rock +++ b/Starship/Rockstar.Test/fixtures/equality/strings.rock @@ -1,27 +1,28 @@ -say "true" is true -say "yes" is true -say "OK" is true -say "" -say true is "true" -say true is "RIGht" -say "yes" is true -say "OK" is true -say false is "false" -say false is "WROng" -say "lies" is false -say "" -say true is "hello" -say "true" is true -say "" -say 5 is "3" -say 5 is "hello" -say "" -say true is "lies" -say "lies" is true -say false is "true" -say false is "hello" -say "false" is false -say "true" is false -say "" -say "hello" is "hello" -say "hello" is "world" +(non-empty strings are true) +say "true" is true (prints: true) +say "yes" is true (prints: true) +say "OK" is true (prints: true) +say true is "true" (prints: true) +say true is "RIGht" (prints: true) +say "yes" is true (prints: true) +say "OK" is true (prints: true) + +say false is "false" (prints: false) +say false is "WROng" (prints: false) +say "lies" is false (prints: false) + +say true is "hello" (prints: true) +say "true" is true (prints: true) + +say 5 is "3" (prints: false) +say 5 is "hello" (prints: false) + +say true is "lies" (prints: true) +say "lies" is true (prints: true) +say false is "true" (prints: false) +say false is "hello" (prints: false) +say "false" is false (prints: false) +say "true" is false (prints: false) + +say "hello" is "hello" (prints: true) +say "hello" is "world" (prints: false) diff --git a/Starship/Rockstar.Test/fixtures/equality/strings.rock.out b/Starship/Rockstar.Test/fixtures/equality/strings.rock.out deleted file mode 100644 index 8283a82..0000000 --- a/Starship/Rockstar.Test/fixtures/equality/strings.rock.out +++ /dev/null @@ -1,27 +0,0 @@ -true -true -true - -true -true -true -true -false -false -false - -true -true - -false -false - -true -true -false -false -false -false - -true -false diff --git a/Starship/Rockstar.Wasm/Rockstar.Wasm.v3.ncrunchproject b/Starship/Rockstar.Wasm/Rockstar.Wasm.v3.ncrunchproject new file mode 100644 index 0000000..319cd52 --- /dev/null +++ b/Starship/Rockstar.Wasm/Rockstar.Wasm.v3.ncrunchproject @@ -0,0 +1,5 @@ + + + True + + \ No newline at end of file diff --git a/Starship/Rockstar/Rockstar.v3.ncrunchproject b/Starship/Rockstar/Rockstar.v3.ncrunchproject index 8a3f889..dce36fa 100644 --- a/Starship/Rockstar/Rockstar.v3.ncrunchproject +++ b/Starship/Rockstar/Rockstar.v3.ncrunchproject @@ -1,7 +1,5 @@  - - rockstar.peg - + \ No newline at end of file diff --git a/Starship/Starship.v3.ncrunchsolution b/Starship/Starship.v3.ncrunchsolution new file mode 100644 index 0000000..fe9b070 --- /dev/null +++ b/Starship/Starship.v3.ncrunchsolution @@ -0,0 +1,8 @@ + + + True + False + True + True + + \ No newline at end of file diff --git a/codemirror-lang-rockstar/src/rockstar-editor.mjs b/codemirror-lang-rockstar/src/rockstar-editor.mjs index 93fc3e9..c463cf0 100644 --- a/codemirror-lang-rockstar/src/rockstar-editor.mjs +++ b/codemirror-lang-rockstar/src/rockstar-editor.mjs @@ -1,6 +1,6 @@ import { EditorView, basicSetup } from "codemirror" import { Rockstar } from "./codemirror-lang-rockstar.ts" -import {coolGlow} from 'thememirror'; +import { coolGlow } from 'thememirror'; export function replaceElementWithEditor(element, RunRockstarProgram) { let view = new EditorView({