This repository has been archived by the owner on Oct 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented loops and empty string constants,
- Loading branch information
1 parent
7cfb871
commit 67c28aa
Showing
29 changed files
with
223 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Rockstar.Engine.Expressions; | ||
|
||
public class CommonVariable(string name, Source source) : Variable(name, source) { | ||
public CommonVariable(string name) : this(name, Source.None) { } | ||
public override string Key => NormalizedName.ToLowerInvariant(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Text; | ||
|
||
namespace Rockstar.Engine.Expressions; | ||
|
||
public class Pronoun(string name, Source source) : Variable(name, source) { | ||
public Pronoun() : this(String.Empty) { } | ||
public Pronoun(string name) : this(name, Source.None) { } | ||
public override string Key => Name.ToLowerInvariant(); | ||
public override void Print(StringBuilder sb, int depth) { | ||
sb.Indent(depth).AppendLine($"pronoun: {Name}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Rockstar.Engine.Expressions; | ||
|
||
public class ProperVariable(string name, Source source) : Variable(name, source) { | ||
public ProperVariable(string name) : this(name, Source.None) { } | ||
public override string Key => NormalizedName.ToUpperInvariant(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Rockstar.Engine.Expressions; | ||
|
||
public class SimpleVariable(string name, Source source) : Variable(name, source) { | ||
public SimpleVariable(string name) : this(name, Source.None) { } | ||
public override string Key => Name.ToLowerInvariant(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Text.RegularExpressions; | ||
using Pegasus.Common; | ||
|
||
namespace Rockstar.Engine; | ||
|
||
public static class PegasusParserExtensions { | ||
public static Source Source(this Cursor cursor, string lexeme = "") | ||
=> new(cursor.Line, cursor.Column, lexeme); | ||
|
||
public static string Error(this Cursor cursor, string unexpected) | ||
=> "Unexpected '" + Regex.Escape(unexpected) + "' at line " + cursor.Line + ", col " + (cursor.Column - 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Rockstar.Engine; | ||
|
||
public class Result { | ||
public static readonly Result Ok = new(); | ||
public static readonly Result Unknown = new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Text; | ||
using Rockstar.Engine.Expressions; | ||
|
||
namespace Rockstar.Engine.Statements; | ||
|
||
public class Decrement(Variable v, int multiple, Source source) : Statement(source) { | ||
public Variable Variable => v; | ||
public int Multiple => multiple; | ||
public override void Print(StringBuilder sb, int depth = 0) { | ||
sb.Indent(depth).AppendLine($"decrement x {multiple}"); | ||
v.Print(sb, depth + 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Text; | ||
using Rockstar.Engine.Expressions; | ||
|
||
namespace Rockstar.Engine.Statements; | ||
|
||
public class Increment(Variable v, int multiple, Source source) : Statement(source) { | ||
public Variable Variable => v; | ||
public int Multiple => multiple; | ||
public override void Print(StringBuilder sb, int depth = 0) { | ||
sb.Indent(depth).AppendLine($"increment x {multiple}"); | ||
v.Print(sb, depth + 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Text; | ||
using Rockstar.Engine.Expressions; | ||
using Rockstar.Engine.Values; | ||
|
||
namespace Rockstar.Engine.Statements; | ||
|
||
public abstract class Loop(Expression condition, bool compareTo, Block body, Source source) | ||
: Statement(source) { | ||
public bool CompareTo => compareTo; | ||
public Expression Condition => condition; | ||
public Block Body => body; | ||
protected abstract string LoopType { get; } | ||
public override void Print(StringBuilder sb, int depth = 0) { | ||
sb.Indent(depth).AppendLine($"{LoopType}:"); | ||
sb.Indent(depth + 1).AppendLine("test:"); | ||
condition.Print(sb, depth + 2); | ||
sb.Indent(depth + 1).AppendLine("then:"); | ||
body.Print(sb, depth + 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Rockstar.Engine.Expressions; | ||
|
||
namespace Rockstar.Engine.Statements; | ||
|
||
public class UntilLoop(Expression condition, Block body, Source source) | ||
: Loop(condition, false, body, source) { | ||
protected override string LoopType => "until"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Rockstar.Engine.Expressions; | ||
|
||
namespace Rockstar.Engine.Statements; | ||
|
||
public class WhileLoop(Expression condition, Block body, Source source) | ||
: Loop(condition, true, body, source) { | ||
protected override string LoopType => "while"; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace Rockstar.Engine.Values; | ||
|
||
public interface IHaveANumber { | ||
decimal NumericValue { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.