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

Commit

Permalink
Wow.
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanbeattie committed Jul 9, 2024
1 parent bd7d545 commit 2c65764
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
29 changes: 15 additions & 14 deletions Starship/Rockstar.Engine/rockstar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@
@ignorecase true

program <Block>
= __ head:block tail:program
= __ head:statements tail:program
{ head.Concat(tail) }
/ __ EOF
{ new Block() }

__ = ("" _ / EOL)*

block <Block>
= head:statement EOS tail:block
statements <Block>
= head:statement EOS tail:statements
{ tail.Insert(head) }
/ s:statement EOS
{ new Block(s) }

EOS = _? EOL _?
/ EOF
/ _? EOF

EOL = '\r'? '\n'
EOF = !.
/ unexpected:("" [^ \t\r\n]+)
Expand All @@ -48,31 +49,31 @@ decrement <Decrement>
= 'knock'i _ v:variable _ t:('down' noise*)+
{ new Decrement(v, t.Count, state.Source()) }

chonk <Block>
= EOS b:block
{ b }
/ _ s:statement
block <Block>
= _ s:statement
{ new Block(s) }

/ EOS b:statements
{ b }

alternate <Conditional>
= c:conditional _? 'else' a:chonk
= c:conditional _? 'else' a:block
{ c.Else(a) }
/ c:conditional EOS 'else' a:chonk
/ c:conditional EOS 'else' a:block
{ c.Else(a) }
/ c:conditional { c }

conditional <Conditional>
= 'if' _ e:expression c:chonk
= 'if' _ e:expression c:block
{ new Conditional(e, c, state.Source()) }

loop <Loop>
= 'while' _ e:expression _ s:statement
{ new WhileLoop(e, new Block(s), state.Source()) }
/ 'while' _ e:expression EOS b:block
/ 'while' _ e:expression EOS b:statements
{ new WhileLoop(e, b, state.Source()) }
/ 'until' _ e:expression _ s:statement
{ new UntilLoop(e, new Block(s), state.Source()) }
/ 'until' _ e:expression EOS b:block
/ 'until' _ e:expression EOS b:statements
{ new UntilLoop(e, b, state.Source()) }

assign_stmt <Statement>
Expand Down
2 changes: 2 additions & 0 deletions Starship/Rockstar.Test/ConditionalTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Pegasus.Common.Tracing;

namespace Rockstar.Test;

public class LoopTests(ITestOutputHelper output) : ParserTestBase(output) {
Expand Down
3 changes: 2 additions & 1 deletion Starship/Rockstar.Test/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public void ParserParsesEmptyPrograms(string source) {
[InlineData("""
say "pass"
""")]
[InlineData("say \"pass\" (prints: pass)")]
public void ParserParsesWeirdPrograms(string source) {
var parser = new Parser();
var parser = new Parser() { Tracer = DiagnosticsTracer.Instance };
var result = parser.Parse(source);
result.Statements.Count.ShouldBe(1);
}
Expand Down
3 changes: 3 additions & 0 deletions Starship/Rockstar.Test/Rockstar.Test.v3.ncrunchproject
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<FixtureTestSelector>
<FixtureName>Rockstar.Test.FixturePreTests</FixtureName>
</FixtureTestSelector>
<FixtureTestSelector>
<FixtureName>Rockstar.Test.FixtureTests</FixtureName>
</FixtureTestSelector>
</IgnoredTests>
</Settings>
</ProjectConfiguration>

0 comments on commit 2c65764

Please sign in to comment.