diff --git a/Starship/Rockstar.Engine/rockstar.peg b/Starship/Rockstar.Engine/rockstar.peg index 1de6e7e..81595f9 100644 --- a/Starship/Rockstar.Engine/rockstar.peg +++ b/Starship/Rockstar.Engine/rockstar.peg @@ -10,21 +10,22 @@ @ignorecase true program - = __ head:block tail:program + = __ head:statements tail:program { head.Concat(tail) } / __ EOF { new Block() } __ = ("" _ / EOL)* -block - = head:statement EOS tail:block +statements + = 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]+) @@ -48,31 +49,31 @@ decrement = 'knock'i _ v:variable _ t:('down' noise*)+ { new Decrement(v, t.Count, state.Source()) } -chonk - = EOS b:block - { b } - / _ s:statement +block + = _ s:statement { new Block(s) } - + / EOS b:statements + { b } + alternate - = 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 - = 'if' _ e:expression c:chonk + = 'if' _ e:expression c:block { new Conditional(e, c, state.Source()) } 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 diff --git a/Starship/Rockstar.Test/ConditionalTests.cs b/Starship/Rockstar.Test/ConditionalTests.cs index 179c1f9..b084d3e 100644 --- a/Starship/Rockstar.Test/ConditionalTests.cs +++ b/Starship/Rockstar.Test/ConditionalTests.cs @@ -1,3 +1,5 @@ +using Pegasus.Common.Tracing; + namespace Rockstar.Test; public class LoopTests(ITestOutputHelper output) : ParserTestBase(output) { diff --git a/Starship/Rockstar.Test/ParserTests.cs b/Starship/Rockstar.Test/ParserTests.cs index dfb8c24..ef130e8 100644 --- a/Starship/Rockstar.Test/ParserTests.cs +++ b/Starship/Rockstar.Test/ParserTests.cs @@ -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); } diff --git a/Starship/Rockstar.Test/Rockstar.Test.v3.ncrunchproject b/Starship/Rockstar.Test/Rockstar.Test.v3.ncrunchproject index 25b1bf2..a3525f7 100644 --- a/Starship/Rockstar.Test/Rockstar.Test.v3.ncrunchproject +++ b/Starship/Rockstar.Test/Rockstar.Test.v3.ncrunchproject @@ -5,6 +5,9 @@ Rockstar.Test.FixturePreTests + + Rockstar.Test.FixtureTests + \ No newline at end of file