Skip to content
This repository has been archived by the owner on Oct 12, 2024. It is now read-only.

Commit

Permalink
Equality for numbers, strings, booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanbeattie committed Jul 4, 2024
1 parent bc24624 commit b19ae75
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 135 deletions.
22 changes: 11 additions & 11 deletions .obsidian/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
7 changes: 7 additions & 0 deletions Starship/Rockstar.Engine/Rockstar.Engine.v3.ncrunchproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ProjectConfiguration>
<Settings>
<AdditionalFilesToIncludeForProject>
<Value>rockstar.peg</Value>
</AdditionalFilesToIncludeForProject>
</Settings>
</ProjectConfiguration>
10 changes: 8 additions & 2 deletions Starship/Rockstar.Engine/Values/Value.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Starship/Rockstar.Engine/rockstar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
program <Progräm>
= __ 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 = !.

Expand Down
3 changes: 1 addition & 2 deletions Starship/Rockstar.Test/FixtureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Rockstar code> in {originalRockFilePath}:line {outputLine}";
testOutput.WriteLine(ncrunchOutputMessage);
throw;
}
try {
var env = new TestEnvironment();
Expand Down
3 changes: 3 additions & 0 deletions Starship/Rockstar.Test/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions Starship/Rockstar.Test/fixtures/equality/nothing.rock
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 0 additions & 8 deletions Starship/Rockstar.Test/fixtures/equality/nothing.rock.out

This file was deleted.

10 changes: 5 additions & 5 deletions Starship/Rockstar.Test/fixtures/equality/null.rock
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 0 additions & 5 deletions Starship/Rockstar.Test/fixtures/equality/null.rock.out

This file was deleted.

34 changes: 17 additions & 17 deletions Starship/Rockstar.Test/fixtures/equality/numbers.rock
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 0 additions & 17 deletions Starship/Rockstar.Test/fixtures/equality/numbers.rock.out

This file was deleted.

55 changes: 28 additions & 27 deletions Starship/Rockstar.Test/fixtures/equality/strings.rock
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 0 additions & 27 deletions Starship/Rockstar.Test/fixtures/equality/strings.rock.out

This file was deleted.

5 changes: 5 additions & 0 deletions Starship/Rockstar.Wasm/Rockstar.Wasm.v3.ncrunchproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely>
</Settings>
</ProjectConfiguration>
4 changes: 1 addition & 3 deletions Starship/Rockstar/Rockstar.v3.ncrunchproject
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<ProjectConfiguration>
<Settings>
<AdditionalFilesToIncludeForProject>
<Value>rockstar.peg</Value>
</AdditionalFilesToIncludeForProject>
<AdditionalFilesToIncludeForProject />
</Settings>
</ProjectConfiguration>
8 changes: 8 additions & 0 deletions Starship/Starship.v3.ncrunchsolution
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<SolutionConfiguration>
<Settings>
<AllowParallelTestExecution>True</AllowParallelTestExecution>
<EnableRDI>False</EnableRDI>
<RdiConfigured>True</RdiConfigured>
<SolutionConfigured>True</SolutionConfigured>
</Settings>
</SolutionConfiguration>
2 changes: 1 addition & 1 deletion codemirror-lang-rockstar/src/rockstar-editor.mjs
Original file line number Diff line number Diff line change
@@ -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({
Expand Down

0 comments on commit b19ae75

Please sign in to comment.