diff --git a/Source/Backlang.Codeanalysis/Backlang.Codeanalysis.csproj b/NewSource/Backlang.CodeAnalysis/Backlang.CodeAnalysis.csproj
similarity index 79%
rename from Source/Backlang.Codeanalysis/Backlang.Codeanalysis.csproj
rename to NewSource/Backlang.CodeAnalysis/Backlang.CodeAnalysis.csproj
index 5470edc4..e2bc7d7d 100644
--- a/Source/Backlang.Codeanalysis/Backlang.Codeanalysis.csproj
+++ b/NewSource/Backlang.CodeAnalysis/Backlang.CodeAnalysis.csproj
@@ -7,27 +7,18 @@
True
True
$(Version)
- $(Version)
The Parser For Backlang
logo.png
https://www.backlang.org
https://github.com/Backlang-Org/Backlang
backlang,dotnet
True
+ Backlang.CodeAnalysis
-
-
-
- True
- \
-
-
-
-
@@ -44,6 +35,4 @@
Resources.Designer.cs
-
-
diff --git a/Source/Backlang.Contracts/LNodeDeconstructors.cs b/NewSource/BacklangC/Core/LNodeDeconstructors.cs
similarity index 94%
rename from Source/Backlang.Contracts/LNodeDeconstructors.cs
rename to NewSource/BacklangC/Core/LNodeDeconstructors.cs
index 1d362a4b..819d1da9 100644
--- a/Source/Backlang.Contracts/LNodeDeconstructors.cs
+++ b/NewSource/BacklangC/Core/LNodeDeconstructors.cs
@@ -1,4 +1,6 @@
-namespace Backlang.Driver;
+using Loyc.Syntax;
+
+namespace BacklangC.Core;
public static class LNodeDeconstructors
{
diff --git a/Source/Backlang.Contracts/Semantic/ImportCheck.cs b/NewSource/BacklangC/Semantic/Checks/ImportCheck.cs
similarity index 70%
rename from Source/Backlang.Contracts/Semantic/ImportCheck.cs
rename to NewSource/BacklangC/Semantic/Checks/ImportCheck.cs
index 55903c11..f447545d 100644
--- a/Source/Backlang.Contracts/Semantic/ImportCheck.cs
+++ b/NewSource/BacklangC/Semantic/Checks/ImportCheck.cs
@@ -1,10 +1,12 @@
-using Backlang.Codeanalysis.Core;
+using Backlang.Codeanalysis.Parsing;
+using Backlang.Codeanalysis.Parsing.AST;
+using Loyc.Syntax;
-namespace Backlang.Contracts.Semantic;
+namespace BacklangC.Semantic.Checks;
internal class ImportCheck : ISemanticCheck
{
- public void Check(CompilationUnit tree, CompilerContext context)
+ public void Check(CompilationUnit tree, Driver context)
{
for (var i = 0; i < tree.Body.Count; i++)
{
diff --git a/Source/Backlang.Contracts/Semantic/InterfaceNameCheck.cs b/NewSource/BacklangC/Semantic/Checks/InterfaceNameCheck.cs
similarity index 80%
rename from Source/Backlang.Contracts/Semantic/InterfaceNameCheck.cs
rename to NewSource/BacklangC/Semantic/Checks/InterfaceNameCheck.cs
index 7ad0586a..16f3fd0c 100644
--- a/Source/Backlang.Contracts/Semantic/InterfaceNameCheck.cs
+++ b/NewSource/BacklangC/Semantic/Checks/InterfaceNameCheck.cs
@@ -1,11 +1,13 @@
-using Backlang.Codeanalysis.Core;
-using Backlang.Driver;
+using Backlang.Codeanalysis.Parsing;
+using Backlang.Codeanalysis.Parsing.AST;
+using BacklangC.Core;
+using Loyc.Syntax;
-namespace Backlang.Contracts.Semantic;
+namespace BacklangC.Semantic.Checks;
internal class InterfaceNameCheck : ISemanticCheck
{
- public void Check(CompilationUnit tree, CompilerContext context)
+ public void Check(CompilationUnit tree, Driver context)
{
for (var i = 0; i < tree.Body.Count; i++)
{
diff --git a/Source/Backlang.Contracts/Semantic/ModifierCheck.cs b/NewSource/BacklangC/Semantic/Checks/ModifierCheck.cs
similarity index 82%
rename from Source/Backlang.Contracts/Semantic/ModifierCheck.cs
rename to NewSource/BacklangC/Semantic/Checks/ModifierCheck.cs
index f2fef8fd..2bc849ee 100644
--- a/Source/Backlang.Contracts/Semantic/ModifierCheck.cs
+++ b/NewSource/BacklangC/Semantic/Checks/ModifierCheck.cs
@@ -1,10 +1,12 @@
using Backlang.Codeanalysis.Core;
+using Backlang.Codeanalysis.Parsing.AST;
+using Loyc.Syntax;
-namespace Backlang.Contracts.Semantic;
+namespace BacklangC.Semantic.Checks;
internal class ModifierCheck : ISemanticCheck
{
- public void Check(CompilationUnit tree, CompilerContext context)
+ public void Check(CompilationUnit tree, Driver context)
{
var nodesWithModifiers = tree.Body
.SelectMany(_ => _.DescendantsAndSelf()).Where(IsModifiableNode).ToArray();
@@ -15,7 +17,7 @@ public void Check(CompilationUnit tree, CompilerContext context)
}
}
- private void CheckForInvalidModifierCombination(LNode node, CompilerContext context)
+ private void CheckForInvalidModifierCombination(LNode node, Driver context)
{
var attrs = node.Attrs;
var condition = (attrs.Contains(LNode.Id(CodeSymbols.Public)) && attrs.Contains(LNode.Id(CodeSymbols.Private)))
@@ -26,7 +28,7 @@ private void CheckForInvalidModifierCombination(LNode node, CompilerContext cont
if (condition)
{
- context.AddError(node, ErrorID.InvalidModifierCombination);
+ //context.AddError(node, ErrorID.InvalidModifierCombination);
}
}
diff --git a/Source/Backlang.Contracts/Semantic/ModuleDefinitionCheck.cs b/NewSource/BacklangC/Semantic/Checks/ModuleDefinitionCheck.cs
similarity index 65%
rename from Source/Backlang.Contracts/Semantic/ModuleDefinitionCheck.cs
rename to NewSource/BacklangC/Semantic/Checks/ModuleDefinitionCheck.cs
index f1d9e229..29641db3 100644
--- a/Source/Backlang.Contracts/Semantic/ModuleDefinitionCheck.cs
+++ b/NewSource/BacklangC/Semantic/Checks/ModuleDefinitionCheck.cs
@@ -1,10 +1,12 @@
-using Backlang.Codeanalysis.Core;
+using Backlang.Codeanalysis.Parsing;
+using Backlang.Codeanalysis.Parsing.AST;
+using Loyc.Syntax;
-namespace Backlang.Contracts.Semantic;
+namespace BacklangC.Semantic.Checks;
internal class ModuleDefinitionCheck : ISemanticCheck
{
- public void Check(CompilationUnit tree, CompilerContext context)
+ public void Check(CompilationUnit tree, Driver context)
{
if (tree.Body.Count(_ => _.Calls(CodeSymbols.Namespace)) > 1)
{
diff --git a/Source/Backlang.Contracts/Semantic/TypenameCheck.cs b/NewSource/BacklangC/Semantic/Checks/TypenameCheck.cs
similarity index 71%
rename from Source/Backlang.Contracts/Semantic/TypenameCheck.cs
rename to NewSource/BacklangC/Semantic/Checks/TypenameCheck.cs
index 5610db9d..42efd6e7 100644
--- a/Source/Backlang.Contracts/Semantic/TypenameCheck.cs
+++ b/NewSource/BacklangC/Semantic/Checks/TypenameCheck.cs
@@ -1,11 +1,13 @@
-using Backlang.Codeanalysis.Core;
-using Backlang.Driver;
+using Backlang.Codeanalysis.Parsing;
+using Backlang.Codeanalysis.Parsing.AST;
+using BacklangC.Core;
+using Loyc.Syntax;
-namespace Backlang.Contracts.Semantic;
+namespace BacklangC.Semantic.Checks;
internal class TypenameCheck : ISemanticCheck
{
- public void Check(CompilationUnit tree, CompilerContext context)
+ public void Check(CompilationUnit tree, Driver context)
{
for (var i = 0; i < tree.Body.Count; i++)
{
diff --git a/NewSource/BacklangC/Semantic/ISemanticCheck.cs b/NewSource/BacklangC/Semantic/ISemanticCheck.cs
new file mode 100644
index 00000000..3f381894
--- /dev/null
+++ b/NewSource/BacklangC/Semantic/ISemanticCheck.cs
@@ -0,0 +1,8 @@
+using Backlang.Codeanalysis.Parsing.AST;
+
+namespace BacklangC.Semantic;
+
+public interface ISemanticCheck
+{
+ void Check(CompilationUnit tree, Driver context);
+}
\ No newline at end of file
diff --git a/NewSource/BacklangC/Semantic/SemanticChecker.cs b/NewSource/BacklangC/Semantic/SemanticChecker.cs
new file mode 100644
index 00000000..ec82acad
--- /dev/null
+++ b/NewSource/BacklangC/Semantic/SemanticChecker.cs
@@ -0,0 +1,24 @@
+using Backlang.Codeanalysis.Parsing.AST;
+using BacklangC.Semantic.Checks;
+
+namespace BacklangC.Semantic;
+
+public static class SemanticChecker
+{
+ private static readonly List SemanticChecks =
+ [
+ new ModuleDefinitionCheck(),
+ new ImportCheck(),
+ new TypenameCheck(),
+ new ModifierCheck(),
+ new InterfaceNameCheck()
+ ];
+
+ public static void Do(CompilationUnit tree, Driver context)
+ {
+ foreach (var check in SemanticChecks)
+ {
+ check.Check(tree, context);
+ }
+ }
+}
\ No newline at end of file
diff --git a/NewSource/BacklangC/Stages/ParsingStage.cs b/NewSource/BacklangC/Stages/ParsingStage.cs
new file mode 100644
index 00000000..98015711
--- /dev/null
+++ b/NewSource/BacklangC/Stages/ParsingStage.cs
@@ -0,0 +1,42 @@
+using Backlang.Codeanalysis.Parsing;
+using Backlang.Codeanalysis.Parsing.AST;
+using Flo;
+using Loyc.Syntax;
+
+namespace BacklangC.Stages;
+
+public sealed class ParsingStage : IHandler
+{
+ public async Task HandleAsync(Driver context,
+ Func> next)
+ {
+ ParseSourceFiles(context);
+
+ return await next.Invoke(context);
+ }
+
+ private static void ParseSourceFiles(Driver context)
+ {
+ Parallel.ForEachAsync(context.Settings.Sources, (filename, ct) => {
+ if (File.Exists(filename))
+ {
+ var tree = CompilationUnit.FromFile(filename);
+
+ ApplyTree(context, tree);
+ }
+ else
+ {
+ context.Messages.Add(Message.Error($"File '{filename}' does not exists", SourceRange.Synthetic));
+ }
+
+ return ValueTask.CompletedTask;
+ }).Wait();
+ }
+
+ private static void ApplyTree(Driver context, CompilationUnit tree)
+ {
+ context.Trees.Add(tree);
+
+ context.Messages.AddRange(tree.Messages);
+ }
+}
\ No newline at end of file
diff --git a/NewSource/BacklangC/Stages/SemanticCheckStage.cs b/NewSource/BacklangC/Stages/SemanticCheckStage.cs
new file mode 100644
index 00000000..b568ab39
--- /dev/null
+++ b/NewSource/BacklangC/Stages/SemanticCheckStage.cs
@@ -0,0 +1,18 @@
+using BacklangC.Semantic;
+using Flo;
+
+namespace BacklangC.Stages;
+
+public sealed class SemanticCheckStage : IHandler
+{
+ public async Task HandleAsync(Driver context, Func> next)
+ {
+ Parallel.ForEachAsync(context.Trees, (tree, ct) => {
+ SemanticChecker.Do(tree, context);
+
+ return ValueTask.CompletedTask;
+ }).Wait();
+
+ return await next.Invoke(context);
+ }
+}
\ No newline at end of file
diff --git a/NewSource/BacklangC/compilation.back b/NewSource/BacklangC/compilation.back
new file mode 100644
index 00000000..a7cf7f6c
--- /dev/null
+++ b/NewSource/BacklangC/compilation.back
@@ -0,0 +1,4 @@
+
+func main() {
+
+}
\ No newline at end of file
diff --git a/Source/Backlang.Contracts/logo.png b/NewSource/BacklangC/logo.png
similarity index 100%
rename from Source/Backlang.Contracts/logo.png
rename to NewSource/BacklangC/logo.png
diff --git a/Source/Backlang-Compiler/compilation.back b/Source/Backlang-Compiler/compilation.back
deleted file mode 100644
index ec2c5489..00000000
--- a/Source/Backlang-Compiler/compilation.back
+++ /dev/null
@@ -1,11 +0,0 @@
-
-func main() {
- if true {
- return 1;
- }
- else {
- return 2;
- }
-
- print("after");
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Core/Attributes/BinaryOperatorInfoAttribute.cs b/Source/Backlang.Codeanalysis/Core/Attributes/BinaryOperatorInfoAttribute.cs
deleted file mode 100644
index d5f94dc4..00000000
--- a/Source/Backlang.Codeanalysis/Core/Attributes/BinaryOperatorInfoAttribute.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using Backlang.Codeanalysis.Parsing.Precedences;
-
-namespace Backlang.Codeanalysis.Core.Attributes;
-
-[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
-public sealed class BinaryOperatorInfoAttribute : OperatorInfoAttribute
-{
- public BinaryOperatorInfoAttribute(int precedence) : base(precedence, false, false)
- {
- }
-
- public BinaryOperatorInfoAttribute(BinaryOpPrecedences precedence) : this((int)precedence)
- {
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Core/Attributes/KeywordAttribute.cs b/Source/Backlang.Codeanalysis/Core/Attributes/KeywordAttribute.cs
deleted file mode 100644
index e328055c..00000000
--- a/Source/Backlang.Codeanalysis/Core/Attributes/KeywordAttribute.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-namespace Backlang.Codeanalysis.Core.Attributes;
-
-[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
-public sealed class KeywordAttribute : Attribute
-{
- public KeywordAttribute(string keyword)
- {
- Keyword = keyword;
- }
-
- public string Keyword { get; set; }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Core/Attributes/LexemeAttribute.cs b/Source/Backlang.Codeanalysis/Core/Attributes/LexemeAttribute.cs
deleted file mode 100644
index 5eccc9de..00000000
--- a/Source/Backlang.Codeanalysis/Core/Attributes/LexemeAttribute.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-namespace Backlang.Codeanalysis.Core.Attributes;
-
-[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
-public sealed class LexemeAttribute : Attribute
-{
- public LexemeAttribute(string lexeleme)
- {
- Lexeme = lexeleme;
- }
-
- public string Lexeme { get; set; }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Core/Attributes/OperatorInfoAttribute.cs b/Source/Backlang.Codeanalysis/Core/Attributes/OperatorInfoAttribute.cs
deleted file mode 100644
index 6e39a7d5..00000000
--- a/Source/Backlang.Codeanalysis/Core/Attributes/OperatorInfoAttribute.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-namespace Backlang.Codeanalysis.Core.Attributes;
-
-[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
-public class OperatorInfoAttribute : Attribute
-{
- public OperatorInfoAttribute(int precedence, bool isUnary, bool isPostUnary)
- {
- Precedence = precedence;
- IsUnary = isUnary;
- IsPostUnary = isPostUnary;
- }
-
- public bool IsPostUnary { get; set; }
- public bool IsUnary { get; set; }
- public int Precedence { get; set; }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Core/Attributes/PostUnaryOperatorInfoAttribute.cs b/Source/Backlang.Codeanalysis/Core/Attributes/PostUnaryOperatorInfoAttribute.cs
deleted file mode 100644
index 9c0c054e..00000000
--- a/Source/Backlang.Codeanalysis/Core/Attributes/PostUnaryOperatorInfoAttribute.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using Backlang.Codeanalysis.Parsing.Precedences;
-
-namespace Backlang.Codeanalysis.Core.Attributes;
-
-[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
-public sealed class PostUnaryOperatorInfoAttribute : OperatorInfoAttribute
-{
- public PostUnaryOperatorInfoAttribute(int precedence) : base(precedence, true, true)
- {
- }
-
- public PostUnaryOperatorInfoAttribute(UnaryOpPrecedences precedence) : this((int)precedence)
- {
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Core/Attributes/PreUnaryOperatorInfoAttribute.cs b/Source/Backlang.Codeanalysis/Core/Attributes/PreUnaryOperatorInfoAttribute.cs
deleted file mode 100644
index 26a95ccc..00000000
--- a/Source/Backlang.Codeanalysis/Core/Attributes/PreUnaryOperatorInfoAttribute.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using Backlang.Codeanalysis.Parsing.Precedences;
-
-namespace Backlang.Codeanalysis.Core.Attributes;
-
-[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
-public sealed class PreUnaryOperatorInfoAttribute : OperatorInfoAttribute
-{
- public PreUnaryOperatorInfoAttribute(int precedence) : base(precedence, true, false)
- {
- }
-
- public PreUnaryOperatorInfoAttribute(UnaryOpPrecedences precedence) : this((int)precedence)
- {
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Core/BaseLexer.cs b/Source/Backlang.Codeanalysis/Core/BaseLexer.cs
deleted file mode 100644
index ad4681bb..00000000
--- a/Source/Backlang.Codeanalysis/Core/BaseLexer.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-using Backlang.Codeanalysis.Parsing;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Core;
-
-public abstract class BaseLexer
-{
- protected int _column = 1;
- protected SourceFile _document;
- protected int _line = 1;
- protected int _position;
- public List Messages = new();
-
- public List Tokenize(SourceFile document)
- {
- _document = document;
-
- var tokens = new List();
-
- Token newToken;
- do
- {
- newToken = NextToken();
-
- tokens.Add(newToken);
- } while (newToken.Type != TokenType.EOF);
-
- return tokens;
- }
-
- protected int Advance()
- {
- return ++_position;
- }
-
- protected char Current()
- {
- if (_position >= _document.Text.Count)
- {
- return '\0';
- }
-
- return _document.Text[_position];
- }
-
- protected abstract Token NextToken();
-
- protected char Peek(int offset = 0)
- {
- if (_position + offset >= _document.Text.Count)
- {
- return '\0';
- }
-
- return _document.Text[_position + offset];
- }
-
- protected void ReportError()
- {
- _column++;
-
- var range = SourceRange.New(_document, new IndexRange(_position, 1));
- Messages.Add(Message.Error(new LocalizableString(ErrorID.UnknownCharacter, Current().ToString()), range));
- Advance();
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Core/ErrorID.cs b/Source/Backlang.Codeanalysis/Core/ErrorID.cs
deleted file mode 100644
index 1c164e28..00000000
--- a/Source/Backlang.Codeanalysis/Core/ErrorID.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-namespace Backlang.Codeanalysis.Core;
-
-public enum ErrorID
-{
- UnexpecedType = 0001,
- InvalidModifierCombination = 0002,
- UnknownCharacter = 0003,
- UnterminatedCharLiteral = 0004,
- UnknownExpression = 0005,
- UnknownLiteral = 0006,
- ForbiddenTrailingComma = 0007,
- BitfieldNotLiteral = 0008,
- UnexpecedTypeMember = 0009,
- ExpectedTypeLiteral = 0010,
- UnknownSwitchOption = 0011,
- NoCatchBlock = 0012,
- EmptyFile = 0013,
- ExpectedIdentifier = 0014,
- UnterminatedStringLiteral = 0015,
- NotClosedMultilineComment = 0016,
- Expected = 0017,
- DuplicateModifier = 0018,
- NamespaceAlreadyImported = 0019,
- RunnableTypeButNoEntrypoint = 0020,
- CannotBeFoundDidYouMean = 0021,
- CannotImplementTypeNotFound = 0022,
- CannotImplementUnitType = 0023,
- AlreadyDeclared = 0024,
- TypeMismatch = 0025,
- UnitTypeMismatch = 0026,
- CannotBeResolved = 0027,
- CannotFindFunction = 0028,
- TargetNotFound = 0029,
- NotDefined = 0030,
- CannotDeduceType = 31,
- DeducingTypeNotPossible = 32
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Core/LevensteinDistance.cs b/Source/Backlang.Codeanalysis/Core/LevensteinDistance.cs
deleted file mode 100644
index c0eb191b..00000000
--- a/Source/Backlang.Codeanalysis/Core/LevensteinDistance.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-namespace Backlang.Codeanalysis.Core;
-
-public static class LevensteinDistance
-{
- public static int Calculate(string source, string target)
- {
- if (string.IsNullOrEmpty(source))
- {
- return string.IsNullOrEmpty(target) ? 0 : target.Length;
- }
-
- if (string.IsNullOrEmpty(target))
- {
- return source.Length;
- }
-
- if (source.Length > target.Length)
- {
- (source, target) = (target, source);
- }
-
- var m = target.Length;
- var n = source.Length;
- var distance = new int[2, m + 1];
- // Initialize the distance matrix
- for (var j = 1; j <= m; j++)
- {
- distance[0, j] = j;
- }
-
- var currentRow = 0;
- for (var i = 1; i <= n; ++i)
- {
- currentRow = i & 1;
- distance[currentRow, 0] = i;
- var previousRow = currentRow ^ 1;
- for (var j = 1; j <= m; j++)
- {
- var cost = target[j - 1] == source[i - 1] ? 0 : 1;
- distance[currentRow, j] = Math.Min(Math.Min(
- distance[previousRow, j] + 1,
- distance[currentRow, j - 1] + 1),
- distance[previousRow, j - 1] + cost);
- }
- }
-
- return distance[currentRow, m];
- }
-
- public static string Suggest(string source, IEnumerable possibilities)
- {
- var lastDistance = 10;
- var lastSuggestion = string.Empty;
-
- foreach (var str in possibilities)
- {
- if (str == "Main")
- {
- continue;
- }
-
- var distance = Calculate(source, str);
- if (distance <= lastDistance)
- {
- lastDistance = distance;
- lastSuggestion = str;
- }
- }
-
- return lastSuggestion;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Core/LocalizableString.cs b/Source/Backlang.Codeanalysis/Core/LocalizableString.cs
deleted file mode 100644
index 3f428a44..00000000
--- a/Source/Backlang.Codeanalysis/Core/LocalizableString.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-using Backlang.Codeanalysis.Properties;
-using System.Resources;
-
-namespace Backlang.Codeanalysis.Core;
-
-public readonly struct LocalizableString
-{
- public readonly ErrorID ErrorID;
- public readonly string[] Arguments;
- public readonly string FallbackValue;
-
- private static readonly ResourceManager _resourceManager =
- new("Backlang.Codeanalysis.Properties.Resources", typeof(Resources).Assembly);
-
- public LocalizableString(ErrorID errorID, params string[] arguments)
- {
- ErrorID = errorID;
- Arguments = arguments;
- FallbackValue = null;
- }
-
- public LocalizableString(ErrorID errorID) : this()
- {
- ErrorID = errorID;
- Arguments = new[] { "NO_VALUE" };
- }
-
- public LocalizableString(string fallbackValue) : this()
- {
- FallbackValue = fallbackValue;
- }
-
- public static implicit operator string(LocalizableString lstr)
- {
- if (!string.IsNullOrEmpty(lstr.FallbackValue))
- {
- return lstr.FallbackValue;
- }
-
- var resourceID = $"BL({(int)lstr.ErrorID:D4})";
-
- return string.Format(resourceID + ": " + _resourceManager.GetString(resourceID), lstr.Arguments);
- }
-
- public static implicit operator LocalizableString(ErrorID id)
- {
- return new LocalizableString(id);
- }
-
- public static implicit operator LocalizableString(string message)
- {
- return new LocalizableString(message);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Core/ParsingHelpers.cs b/Source/Backlang.Codeanalysis/Core/ParsingHelpers.cs
deleted file mode 100644
index fb106b1f..00000000
--- a/Source/Backlang.Codeanalysis/Core/ParsingHelpers.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-using Backlang.Codeanalysis.Parsing;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Core;
-
-internal static class ParsingHelpers
-{
- public static LNodeList ParseSeperated(
- Parser parser,
- TokenType terminator,
- TokenType seperator = TokenType.Comma, bool consumeTerminator = true)
- where T : IParsePoint
- {
- if (parser.Iterator.IsMatch(terminator))
- {
- parser.Iterator.Match(terminator);
- return LNodeList.Empty;
- }
-
- var list = new LNodeList();
- do
- {
- list.Add(T.Parse(parser.Iterator, parser));
-
- if (parser.Iterator.IsMatch(seperator) && parser.Iterator.Peek(1).Type == terminator)
- {
- parser.AddError(ErrorID.ForbiddenTrailingComma);
- parser.Iterator.Match(seperator);
- }
- } while (parser.Iterator.ConsumeIfMatch(seperator));
-
- if (consumeTerminator)
- {
- parser.Iterator.Match(terminator);
- }
-
- return list;
- }
-
- public static LNodeList ParseUntil(Parser parser, TokenType terminator)
- where T : IParsePoint
- {
- var members = new LNodeList();
- while (parser.Iterator.Current.Type != terminator)
- {
- members.Add(T.Parse(parser.Iterator, parser));
- }
-
- parser.Iterator.Match(terminator);
-
- return members;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Annotation.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Annotation.cs
deleted file mode 100644
index 9bdf5fad..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Annotation.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST;
-
-public sealed class Annotation
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var atToken = iterator.Match(TokenType.At);
- var call = Expression.Parse(parser);
-
- return SyntaxTree.Annotation(call).WithRange(atToken, iterator.Prev);
- }
-
- public static bool TryParse(Parser parser, out LNodeList node)
- {
- var annotations = new LNodeList();
- var isAnnotation = () =>
- parser.Iterator.IsMatch(TokenType.At) && parser.Iterator.Peek(1).Type == TokenType.Identifier;
-
- while (isAnnotation())
- {
- annotations.Add(Parse(parser.Iterator, parser));
- }
-
- node = annotations;
-
- return annotations.Count > 0;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/CompilationUnit.cs b/Source/Backlang.Codeanalysis/Parsing/AST/CompilationUnit.cs
deleted file mode 100644
index 6c4a32d2..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/CompilationUnit.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST;
-
-public sealed class CompilationUnit
-{
- public LNodeList Body { get; set; } = new();
- public SourceFile Document { get; internal set; }
- public List Messages { get; set; } = new();
-
- public static CompilationUnit FromFile(string filename)
- {
- var document = new SourceDocument(filename);
-
- return Parser.Parse(document);
- }
-
- public static CompilationUnit FromText(string text)
- {
- var document = new SourceDocument("inline.back", text);
-
- return Parser.Parse(document);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/BitFieldDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/BitFieldDeclaration.cs
deleted file mode 100644
index cd736783..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/BitFieldDeclaration.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class BitFieldDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- var nameToken = iterator.Match(TokenType.Identifier);
-
- iterator.Match(TokenType.OpenCurly);
-
- var members = ParsingHelpers.ParseSeperated(parser, TokenType.CloseCurly);
-
- return SyntaxTree.Bitfield(nameToken, members).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/BitFieldMemberDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/BitFieldMemberDeclaration.cs
deleted file mode 100644
index 7d254481..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/BitFieldMemberDeclaration.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class BitFieldMemberDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- Token nameToken;
- if (iterator.Current.Type == TokenType.Identifier)
- {
- nameToken = iterator.Current;
-
- iterator.NextToken();
- }
- else
- {
- nameToken = iterator.NextToken();
- }
-
- iterator.Match(TokenType.EqualsToken);
-
- var value = Expression.Parse(parser);
-
- if (!value[0].HasValue)
- {
- parser.AddError(ErrorID.BitfieldNotLiteral, value.Range);
- }
-
- return SyntaxTree.Factory.Tuple(SyntaxTree.Factory.Id(nameToken.Text).WithRange(nameToken), value);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ClassDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ClassDeclaration.cs
deleted file mode 100644
index e261976e..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ClassDeclaration.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class ClassDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
-
- var nameToken = iterator.Match(TokenType.Identifier);
- var inheritances = new LNodeList();
-
- if (iterator.ConsumeIfMatch(TokenType.Colon))
- {
- inheritances = Expression.ParseList(parser, TokenType.OpenCurly, false);
- }
-
- iterator.Match(TokenType.OpenCurly);
-
- var members = ParsingHelpers.ParseUntil(parser, TokenType.CloseCurly);
-
- return SyntaxTree.Class(nameToken, inheritances, members).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ConstructorDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ConstructorDeclaration.cs
deleted file mode 100644
index a951867a..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ConstructorDeclaration.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Backlang.Codeanalysis.Parsing.AST.Statements;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public class ConstructorDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
-
- iterator.Match(TokenType.OpenParen);
-
- var parameters = ParameterDeclaration.ParseList(parser);
-
- var code = Statement.ParseBlock(parser);
-
- return SyntaxTree.Constructor(parameters, code).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/DestructorDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/DestructorDeclaration.cs
deleted file mode 100644
index ab224d4e..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/DestructorDeclaration.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Backlang.Codeanalysis.Parsing.AST.Statements;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public class DestructorDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
-
- iterator.Match(TokenType.OpenParen);
-
- var parameters = ParameterDeclaration.ParseList(parser);
-
- var code = Statement.ParseBlock(parser);
-
- return SyntaxTree.Destructor(parameters, code).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/DiscriminatedUnionDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/DiscriminatedUnionDeclaration.cs
deleted file mode 100644
index 2c344576..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/DiscriminatedUnionDeclaration.cs
+++ /dev/null
@@ -1,68 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public class DiscriminatedUnionDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- var nametoken = iterator.Match(TokenType.Identifier);
- iterator.Match(TokenType.EqualsToken);
-
- var types = new LNodeList();
-
- do
- {
- //ToDo: Refactor To Helper Method: RepeatUntil
- var from = iterator.Current;
- iterator.Match(TokenType.Pipe);
- types.Add(ParseType(iterator, parser).WithRange(from, iterator.Prev));
- } while (iterator.IsMatch(TokenType.Pipe));
-
- iterator.Match(TokenType.Semicolon);
-
- return SyntaxTree.DiscriminatedUnion(nametoken, types).WithRange(keywordToken, iterator.Prev);
- }
-
- public static LNode ParseType(TokenIterator iterator, Parser parser)
- {
- var nameToken = iterator.Match(TokenType.Identifier);
-
- iterator.Match(TokenType.OpenParen);
-
- var parameters = ParseParameterDeclarations(iterator, parser);
-
- iterator.Match(TokenType.CloseParen);
-
- return SyntaxTree.DiscriminatedType(nameToken, parameters);
- }
-
- public static LNodeList ParseParameterDeclarations(TokenIterator iterator, Parser parser)
- {
- var parameters = new LNodeList();
- while (iterator.Current.Type != TokenType.CloseParen)
- {
- while (iterator.Current.Type != TokenType.Comma && iterator.Current.Type != TokenType.CloseParen)
- {
- var isMutable = iterator.ConsumeIfMatch(TokenType.Mutable);
-
- var parameter = ParameterDeclaration.Parse(iterator, parser);
-
- if (iterator.Current.Type == TokenType.Comma)
- {
- iterator.NextToken();
- }
-
- if (isMutable)
- {
- parameter = parameter.PlusAttr(SyntaxTree.Factory.Id(Symbols.Mutable));
- }
-
- parameters.Add(parameter);
- }
- }
-
- return parameters;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/EnumDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/EnumDeclaration.cs
deleted file mode 100644
index 0294bb23..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/EnumDeclaration.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class EnumDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- var nameToken = iterator.Match(TokenType.Identifier);
-
- iterator.Match(TokenType.OpenCurly);
-
- var members = ParsingHelpers.ParseSeperated(parser, TokenType.CloseCurly);
-
- return SyntaxTree.Enum(LNode.Id(nameToken.Text), members).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/EnumMemberDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/EnumMemberDeclaration.cs
deleted file mode 100644
index 2a458b75..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/EnumMemberDeclaration.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public class EnumMemberDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- _ = Annotation.TryParse(parser, out var annotations);
-
- var memberNameToken = iterator.Match(TokenType.Identifier);
- LNode value = LNode.Missing;
-
- if (iterator.ConsumeIfMatch(TokenType.EqualsToken))
- {
- value = parser.ParsePrimary();
- }
-
- return SyntaxTree.Factory.Var(LNode.Missing, LNode.Id(memberNameToken.Text), value).PlusAttrs(annotations);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/FunctionDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/FunctionDeclaration.cs
deleted file mode 100644
index bff5f816..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/FunctionDeclaration.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using Backlang.Codeanalysis.Parsing.AST.Statements;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class FunctionDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- var signature = Signature.Parse(parser);
-
- return signature.PlusArg(Statement.ParseBlock(parser)).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ImplementationDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ImplementationDeclaration.cs
deleted file mode 100644
index 8814246c..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ImplementationDeclaration.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public class ImplementationDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- var targets = new LNodeList();
-
- while (iterator.Current.Type != TokenType.OpenCurly && !parser.Iterator.IsMatch(TokenType.EOF))
- {
- if (iterator.Peek(1).Type == TokenType.RangeOperator)
- {
- targets.Add(Expression.Parse(parser));
- }
- else
- {
- targets.Add(TypeLiteral.Parse(iterator, parser));
- }
-
- if (iterator.Current.Type != TokenType.OpenCurly)
- {
- iterator.Match(TokenType.Comma);
- }
- }
-
- LNode target;
- if (targets.Count == 1)
- {
- target = targets[0];
- }
- else
- {
- //ToDo: need to be fixed
- target = LNode.Call(Symbols.ToExpand, targets);
- }
-
- iterator.Match(TokenType.OpenCurly);
-
- LNodeList body = new();
- while (!parser.Iterator.IsMatch(TokenType.EOF) && iterator.Current.Type != TokenType.CloseCurly)
- {
- _ = Annotation.TryParse(parser, out var annotations);
- _ = Modifier.TryParse(parser, out var modifiers);
-
- body.Add(parser.InvokeParsePoint(parser.DeclarationParsePoints).PlusAttrs(annotations)
- .PlusAttrs(modifiers));
- }
-
- iterator.Match(TokenType.CloseCurly);
-
- return SyntaxTree.ImplDecl(target, body).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/InterfaceDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/InterfaceDeclaration.cs
deleted file mode 100644
index 276fe05e..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/InterfaceDeclaration.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class InterfaceDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- var nameToken = iterator.Match(TokenType.Identifier);
- var inheritances = new LNodeList();
-
- if (iterator.ConsumeIfMatch(TokenType.Colon))
- {
- inheritances = Expression.ParseList(parser, TokenType.OpenCurly, false);
- }
-
- iterator.Match(TokenType.OpenCurly);
-
- var members = ParsingHelpers.ParseUntil(parser, TokenType.CloseCurly);
-
- return SyntaxTree.Interface(nameToken, inheritances, members).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/MacroBlockDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/MacroBlockDeclaration.cs
deleted file mode 100644
index dcfb17a9..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/MacroBlockDeclaration.cs
+++ /dev/null
@@ -1,65 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class MacroBlockDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var nameExpression = LNode.Id(iterator.Prev.Text).WithRange(iterator.Current);
-
- var pp = parser.DeclarationParsePoints;
-
- foreach (var p in parser.StatementParsePoints)
- {
- if (pp.ContainsKey(p.Key))
- {
- continue;
- }
-
- pp.Add(p.Key, p.Value);
- }
-
- if (iterator.Current.Type == TokenType.OpenParen)
- {
- iterator.NextToken();
-
- var arguments = Expression.ParseList(parser, TokenType.CloseParen);
-
- if (iterator.Current.Type == TokenType.OpenCurly)
- {
- iterator.NextToken();
- //custom code block with arguments
-
- var body = parser.InvokeDeclarationParsePoints(TokenType.CloseCurly, pp);
- iterator.Match(TokenType.CloseCurly);
-
- arguments = arguments.Add(LNode.Call(CodeSymbols.Braces, body));
-
- return SyntaxTree.Factory.Call(nameExpression, arguments).SetStyle(NodeStyle.StatementBlock)
- .SetStyle(NodeStyle.Special).WithRange(nameExpression.Range.StartIndex, iterator.Prev.End);
- }
-
- parser.Iterator.Match(TokenType.Semicolon);
-
- return LNode.Call(nameExpression, arguments);
- }
-
- if (iterator.Current.Type == TokenType.OpenCurly)
- {
- iterator.NextToken();
-
- //custom code block without arguments
- var body = parser.InvokeDeclarationParsePoints(TokenType.CloseCurly, pp);
- iterator.Match(TokenType.CloseCurly);
-
- var arguments = LNode.List(LNode.Missing);
- arguments = arguments.Add(LNode.Call(CodeSymbols.Braces, body));
-
- return SyntaxTree.Factory.Call(nameExpression, arguments).SetStyle(NodeStyle.StatementBlock)
- .SetStyle(NodeStyle.Special).WithRange(nameExpression.Range.StartIndex, iterator.Prev.End);
- }
-
- return LNode.Missing;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/MacroDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/MacroDeclaration.cs
deleted file mode 100644
index 606015d4..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/MacroDeclaration.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Backlang.Codeanalysis.Parsing.AST.Statements;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class MacroDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- var signature = Signature.Parse(parser);
-
- return signature.WithTarget(Symbols.Macro).PlusArg(LNode.Call(CodeSymbols.Braces, Statement.ParseBlock(parser))
- .SetStyle(NodeStyle.StatementBlock)).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ModuleDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ModuleDeclaration.cs
deleted file mode 100644
index 0dea4c2a..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ModuleDeclaration.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class ModuleDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- //module
- //module .
- var keywordToken = iterator.Prev;
- var tree = SyntaxTree.Module(Expression.Parse(parser));
-
- iterator.Match(TokenType.Semicolon);
-
- return tree.WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ParameterDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ParameterDeclaration.cs
deleted file mode 100644
index 87440f24..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/ParameterDeclaration.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class ParameterDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- _ = Annotation.TryParse(parser, out var annotations);
-
- var keywordToken = iterator.Current;
- var name = iterator.Match(TokenType.Identifier);
-
- var assertNotNull = false;
- if (iterator.ConsumeIfMatch(TokenType.Exclamation))
- {
- assertNotNull = true;
- }
-
- iterator.Match(TokenType.Colon);
-
- var type = TypeLiteral.Parse(iterator, parser);
-
- LNode defaultValue = LNode.Missing;
-
- if (iterator.Current.Type == TokenType.EqualsToken)
- {
- iterator.NextToken();
-
- defaultValue = Expression.Parse(parser);
- }
-
- if (assertNotNull)
- {
- annotations = annotations.Add(LNode.Id(Symbols.AssertNonNull));
- }
-
- return SyntaxTree.Factory.Var(type, name.Text, defaultValue).PlusAttrs(annotations)
- .WithRange(keywordToken, iterator.Prev);
- }
-
- public static LNodeList ParseList(Parser parser)
- {
- return ParsingHelpers.ParseSeperated(parser, TokenType.CloseParen);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/StructDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/StructDeclaration.cs
deleted file mode 100644
index 90ed42a0..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/StructDeclaration.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class StructDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- var name = iterator.Match(TokenType.Identifier);
- var inheritances = new LNodeList();
-
- if (iterator.ConsumeIfMatch(TokenType.Colon))
- {
- inheritances = Expression.ParseList(parser, TokenType.OpenCurly, false);
- }
-
- iterator.Match(TokenType.OpenCurly);
-
- var members = ParsingHelpers.ParseUntil(parser, TokenType.CloseCurly);
-
- return SyntaxTree.Struct(name, inheritances, members)
- .WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/TypeAliasDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/TypeAliasDeclaration.cs
deleted file mode 100644
index 9ca344a2..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/TypeAliasDeclaration.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class TypeAliasDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- // using as
- var keywordToken = iterator.Prev;
- var expr = Expression.Parse(parser); // because 'as' is binary so i32 as int resolves to as(i32, int)
-
- iterator.Match(TokenType.Semicolon);
-
- return SyntaxTree.Using(expr).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/TypeFieldDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/TypeFieldDeclaration.cs
deleted file mode 100644
index cf1cafd5..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/TypeFieldDeclaration.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using Backlang.Codeanalysis.Parsing.AST.Statements;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class TypeFieldDeclaration
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- iterator.Match(TokenType.Let);
- return VariableStatement.Parse(iterator, parser);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/TypeFunctionDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/TypeFunctionDeclaration.cs
deleted file mode 100644
index 1c180a08..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/TypeFunctionDeclaration.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class TypeFunctionDeclaration
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Match(TokenType.Function);
- var result = Signature.Parse(parser);
- iterator.Match(TokenType.Semicolon);
-
- return result.WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/TypeMemberDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/TypeMemberDeclaration.cs
deleted file mode 100644
index 8976e7a2..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/TypeMemberDeclaration.cs
+++ /dev/null
@@ -1,143 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Backlang.Codeanalysis.Parsing.AST.Statements;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class TypeMemberDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- _ = Annotation.TryParse(parser, out var annotations);
- _ = Modifier.TryParse(parser, out var modifiers);
-
- LNode declaration = LNode.Missing;
-
- if (iterator.IsMatch(TokenType.Function))
- {
- declaration = ParseFunction(iterator, parser);
- }
- else if (iterator.IsMatch(TokenType.Property))
- {
- declaration = ParseProperty(iterator, parser);
- }
- else if (iterator.IsMatch(TokenType.Let))
- {
- declaration = ParseField(iterator, parser);
- }
- else
- {
- var range = new SourceRange(parser.Document, iterator.Current.Start, iterator.Current.Text.Length);
-
- parser.AddError(new LocalizableString(ErrorID.UnexpecedTypeMember, iterator.Current.Text), range);
- iterator.NextToken();
- }
-
- return declaration.PlusAttrs(annotations).PlusAttrs(modifiers);
- }
-
- public static LNode ParseField(TokenIterator iterator, Parser parser)
- {
- iterator.Match(TokenType.Let);
- return VariableStatement.Parse(iterator, parser);
- }
-
- public static LNode ParseFunction(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Match(TokenType.Function);
- var result = Signature.Parse(parser);
- iterator.Match(TokenType.Semicolon);
-
- return result.WithRange(keywordToken, iterator.Prev);
- }
-
- public static LNode ParseProperty(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Match(TokenType.Property);
- LNode type = LNode.Missing;
- LNode value = LNode.Missing;
- var nameToken = iterator.Match(TokenType.Identifier);
- var name = LNode.Id(nameToken.Text);
-
- if (iterator.IsMatch(TokenType.Colon))
- {
- iterator.NextToken();
-
- type = TypeLiteral.Parse(iterator, parser);
- }
-
- iterator.Match(TokenType.OpenCurly);
-
- LNode getter = LNode.Missing;
- LNode setter = LNode.Missing;
-
- var needModifier = false;
-
- _ = Modifier.TryParse(parser, out var modifier);
- if (iterator.IsMatch(TokenType.Get))
- {
- iterator.NextToken();
- var args = LNode.List();
- if (iterator.IsMatch(TokenType.Semicolon))
- {
- iterator.NextToken();
- }
- else
- {
- args.Add(Statement.ParseBlock(parser));
- }
-
- getter = LNode.Call(CodeSymbols.get, args).WithAttrs(modifier);
- needModifier = true;
- }
-
- if (needModifier)
- {
- _ = Modifier.TryParse(parser, out modifier);
- }
-
- if (iterator.IsMatch(TokenType.Set))
- {
- iterator.NextToken();
- var args = LNode.List();
- if (iterator.IsMatch(TokenType.Semicolon))
- {
- iterator.NextToken();
- }
- else
- {
- args.Add(Statement.ParseBlock(parser));
- }
-
- setter = LNode.Call(CodeSymbols.set, args).WithAttrs(modifier);
- }
- else if (iterator.IsMatch(TokenType.Init))
- {
- iterator.NextToken();
- var args = LNode.List();
- if (iterator.IsMatch(TokenType.Semicolon))
- {
- iterator.NextToken();
- }
- else
- {
- args.Add(Statement.ParseBlock(parser));
- }
-
- setter = LNode.Call(Symbols.Init, args).WithAttrs(modifier);
- }
-
- iterator.Match(TokenType.CloseCurly);
-
- if (iterator.IsMatch(TokenType.EqualsToken))
- {
- iterator.NextToken();
-
- value = Expression.Parse(parser);
-
- iterator.Match(TokenType.Semicolon);
- }
-
- return SyntaxTree.Property(type, name, getter, setter, value).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/UnionDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/UnionDeclaration.cs
deleted file mode 100644
index 6f8c4b8c..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/UnionDeclaration.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Backlang.Codeanalysis.Parsing.AST.Statements;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public sealed class UnionDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
-
- var nameToken = iterator.Match(TokenType.Identifier);
-
- iterator.Match(TokenType.OpenCurly);
-
- var members = ParsingHelpers.ParseSeperated(parser, TokenType.CloseCurly);
-
- return SyntaxTree.Union(nameToken.Text, members).WithRange(keywordToken, iterator.Current);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/UnitDeclaration.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/UnitDeclaration.cs
deleted file mode 100644
index e9a2867b..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Declarations/UnitDeclaration.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Declarations;
-
-public class UnitDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- var nameToken = iterator.Match(TokenType.Identifier);
-
- iterator.Match(TokenType.Semicolon);
-
- return SyntaxTree.UnitDeclaration(nameToken).WithRange(keywordToken, nameToken);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/DocComment.cs b/Source/Backlang.Codeanalysis/Parsing/AST/DocComment.cs
deleted file mode 100644
index 0c290c71..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/DocComment.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Loyc;
-using Loyc.Syntax;
-using System.Xml;
-
-namespace Backlang.Codeanalysis.Parsing.AST;
-
-public sealed class DocComment
-{
- public static LNode Parse(Parser parser)
- {
- var comment = parser.Iterator.Match(TokenType.DocComment);
- var xmlDocument = new XmlDocument();
- xmlDocument.LoadXml($"{comment.Text}");
-
- return LNode.Trivia(Symbol.For("DocComment"), xmlDocument);
- }
-
- public static bool TryParse(Parser parser, out LNode node)
- {
- var result = parser.Iterator.IsMatch(TokenType.DocComment);
-
- node = result ? Parse(parser) : LNode.Missing;
-
- return result;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/DefaultExpression.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/DefaultExpression.cs
deleted file mode 100644
index 61e184d6..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/DefaultExpression.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Expressions;
-
-public sealed class DefaultExpression : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- //default(i32)
- //default
- if (iterator.ConsumeIfMatch(TokenType.OpenParen))
- {
- var type = TypeLiteral.Parse(iterator, parser);
-
- iterator.Match(TokenType.CloseParen);
-
- return SyntaxTree.Default(type);
- }
-
- return SyntaxTree.Default();
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/GroupExpression.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/GroupExpression.cs
deleted file mode 100644
index b55f8e5d..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/GroupExpression.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Expressions;
-
-public sealed class GroupOrTupleExpression : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var exprs = Expression.ParseList(parser, TokenType.CloseParen);
-
- if (exprs.Count == 1)
- {
- return SyntaxTree.Factory.InParens(exprs[0]);
- }
-
- return SyntaxTree.Factory.Tuple(exprs);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/InitializerListExpression.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/InitializerListExpression.cs
deleted file mode 100644
index 72e5f5da..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/InitializerListExpression.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Expressions;
-
-public sealed class InitializerListExpression : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var elements = new LNodeList();
-
- do
- {
- if (iterator.Current.Type == TokenType.CloseSquare)
- {
- break;
- }
-
- elements.Add(Expression.Parse(parser));
-
- if (iterator.Current.Type != TokenType.CloseSquare)
- {
- iterator.Match(TokenType.Comma);
- }
- } while (iterator.Current.Type != TokenType.CloseSquare);
-
- iterator.Match(TokenType.CloseSquare);
-
- return SyntaxTree.ArrayInstantiation(elements);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/Match/MatchExpression.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/Match/MatchExpression.cs
deleted file mode 100644
index 3373de23..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/Match/MatchExpression.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Expressions.Match;
-
-public sealed class MatchExpression : IParsePoint
-{
- /*
- * match a with
- 12 => 13,
- i32 num => num + 2,
- _ => 0 + 4;
- */
-
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var matchArgument = Expression.Parse(parser);
-
- iterator.Match(TokenType.With);
-
- var conditions = new LNodeList();
-
- while (iterator.Current.Type != TokenType.Semicolon)
- {
- conditions.Add(MatchRule.Parse(iterator, parser));
-
- if (iterator.Current.Type == TokenType.Semicolon)
- {
- break;
- }
-
- iterator.Match(TokenType.Comma);
- }
-
- return SyntaxTree.Factory.Call(LNode.Id(Symbols.Match), matchArgument).WithAttrs(conditions);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/Match/MatchRule.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/Match/MatchRule.cs
deleted file mode 100644
index 0333c9df..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/Match/MatchRule.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-using Loyc;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Expressions.Match;
-
-public sealed class MatchRule
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- if (iterator.Current.Type == TokenType.Underscore) // _ => 0
- {
- iterator.NextToken();
-
- iterator.Match(TokenType.GoesTo);
-
- var result = Expression.Parse(parser);
-
- return SyntaxTree.Factory.Tuple(LNode.Literal((Symbol)"_"), result);
- }
-
- if (iterator.Peek(1).Type == TokenType.GoesTo) //12 => 13
- {
- var matcher = Expression.Parse(parser);
-
- iterator.Match(TokenType.GoesTo);
-
- var result = Expression.Parse(parser);
-
- return SyntaxTree.Factory.Tuple(matcher, result);
- }
-
- if (iterator.Current.IsOperator()) // > 12 => false
- {
- var operatorToken = iterator.Current;
- iterator.NextToken();
-
- var condition = Expression.Parse(parser);
-
- iterator.Match(TokenType.GoesTo);
-
- var result = Expression.Parse(parser);
-
- return SyntaxTree.Factory.Tuple(SyntaxTree.Unary((Symbol)operatorToken.Text, condition), result);
- }
-
- if (iterator.Current.Type == TokenType.Identifier &&
- iterator.Peek(1).Type == TokenType.Identifier) //i32 num => num + 2
- {
- var type = TypeLiteral.Parse(iterator, parser);
- var name = iterator.NextToken().Text;
-
- iterator.Match(TokenType.GoesTo);
-
- var result = Expression.Parse(parser);
-
- return SyntaxTree.Factory.Tuple(SyntaxTree.Factory.Var(type, name), result);
- }
-
- if (iterator.Current.Type == TokenType.Identifier) //i32 => 32
- {
- var type = TypeLiteral.Parse(iterator, parser);
-
- iterator.Match(TokenType.GoesTo);
-
- var result = Expression.Parse(parser);
-
- return SyntaxTree.Factory.Tuple(type, result);
- }
-
- return LNode.Missing;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/NameExpression.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/NameExpression.cs
deleted file mode 100644
index 002c0e86..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/NameExpression.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Expressions;
-
-public sealed class NameExpression : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var nameToken = iterator.Peek(-1);
- var nameExpression = SyntaxTree.Factory.Id(nameToken.Text);
-
- if (iterator.Current.Type == TokenType.OpenSquare)
- {
- iterator.NextToken();
-
- return SyntaxTree.ArrayInstantiation(nameExpression, Expression.ParseList(parser, TokenType.CloseSquare))
- .WithRange(nameToken, iterator.Prev);
- }
-
- if (iterator.Current.Type == TokenType.OpenParen)
- {
- iterator.NextToken();
-
- var arguments = Expression.ParseList(parser, TokenType.CloseParen);
-
- return SyntaxTree.Factory.Call(nameExpression, arguments).WithRange(nameToken, iterator.Prev);
- }
-
- return nameExpression.WithRange(nameToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/NoneExpression.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/NoneExpression.cs
deleted file mode 100644
index 8ae60c0e..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/NoneExpression.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Expressions;
-
-public sealed class NoneExpression : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- return SyntaxTree.None();
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/SizeOfExpression.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/SizeOfExpression.cs
deleted file mode 100644
index 3e6b08d8..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/SizeOfExpression.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Expressions;
-
-public sealed class SizeOfExpression : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- //sizeof(i32)
-
- iterator.Match(TokenType.OpenParen);
-
- var type = TypeLiteral.Parse(iterator, parser);
-
- iterator.Match(TokenType.CloseParen);
-
- return SyntaxTree.SizeOf(type);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/TypeofExpression.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/TypeofExpression.cs
deleted file mode 100644
index 7c03c22f..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Expressions/TypeofExpression.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Expressions;
-
-public sealed class TypeofExpression : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- iterator.Match(TokenType.OpenParen);
-
- var type = TypeLiteral.Parse(iterator, parser);
-
- iterator.Match(TokenType.CloseParen);
-
- return SyntaxTree.TypeOfExpression(type);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Modifier.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Modifier.cs
deleted file mode 100644
index 297cecb8..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Modifier.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Loyc;
-using Loyc.Syntax;
-using System.Collections.Immutable;
-
-namespace Backlang.Codeanalysis.Parsing.AST;
-
-public sealed class Modifier
-{
- private static readonly ImmutableDictionary _possibleModifiers =
- new Dictionary
- {
- { TokenType.Static, CodeSymbols.Static },
- { TokenType.Public, CodeSymbols.Public },
- { TokenType.Protected, CodeSymbols.Protected },
- { TokenType.Private, CodeSymbols.Private },
- { TokenType.Internal, CodeSymbols.Internal },
- { TokenType.Operator, CodeSymbols.Operator },
- { TokenType.Abstract, CodeSymbols.Abstract },
- { TokenType.Override, CodeSymbols.Override },
- { TokenType.Extern, CodeSymbols.Extern }
- }.ToImmutableDictionary();
-
- public static bool TryParse(Parser parser, out LNodeList node)
- {
- var modifiers = new LNodeList();
-
- while (_possibleModifiers.ContainsKey(parser.Iterator.Current.Type))
- {
- var modifier = ParseSingle(parser.Iterator);
- if (modifiers.Contains(modifier))
- {
- parser.AddError(new LocalizableString(ErrorID.DuplicateModifier, modifier.Name.Name), modifier.Range);
-
- continue;
- }
-
- modifiers.Add(modifier);
- }
-
- node = modifiers;
-
- return modifiers.Count > 0;
- }
-
- private static LNode ParseSingle(TokenIterator iterator)
- {
- var currentToken = iterator.Current;
- var mod = SyntaxTree.Factory.Id(_possibleModifiers[currentToken.Type]);
- iterator.NextToken();
-
- return mod.WithRange(currentToken);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Signature.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Signature.cs
deleted file mode 100644
index 87a03ed7..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Signature.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Backlang.Codeanalysis.Parsing.AST.Declarations;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST;
-
-public sealed class Signature
-{
- public static LNode Parse(Parser parser)
- {
- var iterator = parser.Iterator;
-
- if (!TypeLiteral.TryParse(parser, out var name))
- {
- var range = new SourceRange(parser.Document, iterator.Current.Start, iterator.Current.Text.Length);
-
- parser.AddError(new LocalizableString(ErrorID.ExpectedTypeLiteral, iterator.Current.Text), range);
- }
-
- LNode returnType = LNode.Missing;
- iterator.Match(TokenType.OpenParen);
-
- var parameters = ParameterDeclaration.ParseList(parser);
-
- LNodeList generics = new();
- while (iterator.IsMatch(TokenType.Where))
- {
- iterator.NextToken();
- var genericName = LNode.Id(iterator.Match(TokenType.Identifier).Text);
- iterator.Match(TokenType.Colon);
- var bases = new LNodeList();
- do
- {
- if (iterator.IsMatch(TokenType.Comma))
- {
- iterator.NextToken();
- }
-
- bases.Add(TypeLiteral.Parse(iterator, parser));
- } while (iterator.IsMatch(TokenType.Comma));
-
- generics.Add(LNode.Call(Symbols.Where, LNode.List(genericName, LNode.Call(CodeSymbols.Base, bases))));
- }
-
- if (iterator.IsMatch(TokenType.Arrow))
- {
- iterator.NextToken();
-
- returnType = TypeLiteral.Parse(iterator, parser);
- }
-
- return SyntaxTree.Signature(name, returnType, parameters, generics);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/BreakStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/BreakStatement.cs
deleted file mode 100644
index c749506d..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/BreakStatement.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements;
-
-public sealed class BreakStatement : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- iterator.Match(TokenType.Semicolon);
-
- return LNode.Call(CodeSymbols.Break).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/ExpressionStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/ExpressionStatement.cs
deleted file mode 100644
index 9518aded..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/ExpressionStatement.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements;
-
-public sealed class ExpressionStatement : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var expr = Expression.Parse(parser);
-
- iterator.Match(TokenType.Semicolon);
-
- return expr.WithRange(expr.Range.StartIndex, iterator.Prev.End);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/IfStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/IfStatement.cs
deleted file mode 100644
index af0ab559..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/IfStatement.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements;
-
-public sealed class IfStatement : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- // if cond {} else {}
- var keywordToken = iterator.Prev;
- var cond = Expression.Parse(parser);
- var body = Statement.ParseOneOrBlock(parser);
- LNode elseBlock = LNode.Missing;
-
- if (iterator.Current.Type == TokenType.Else)
- {
- iterator.NextToken();
-
- elseBlock = Statement.ParseOneOrBlock(parser);
- }
-
- return SyntaxTree.If(cond, body, elseBlock).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/ImportStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/ImportStatement.cs
deleted file mode 100644
index b6acdd3d..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/ImportStatement.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements;
-
-public sealed class ImportDeclaration : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- //import
- //import .
- var keywordToken = iterator.Prev;
- var tree = SyntaxTree.Import(Expression.Parse(parser));
-
- iterator.Match(TokenType.Semicolon);
-
- return tree.WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Loops/ContinueStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Loops/ContinueStatement.cs
deleted file mode 100644
index 02bff3ba..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Loops/ContinueStatement.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements.Loops;
-
-public sealed class ContinueStatement : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- iterator.Match(TokenType.Semicolon);
-
- return LNode.Call(CodeSymbols.Continue).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Loops/DoWhileStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Loops/DoWhileStatement.cs
deleted file mode 100644
index 394b9078..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Loops/DoWhileStatement.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements.Loops;
-
-public sealed class DoWhileStatement : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
-
- var body = Statement.ParseBlock(parser);
-
- iterator.Match(TokenType.While);
-
- var cond = Expression.Parse(parser);
-
- iterator.Match(TokenType.Semicolon);
-
- return SyntaxTree.DoWhile(body, cond).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Loops/ForStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Loops/ForStatement.cs
deleted file mode 100644
index 5a246b2c..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Loops/ForStatement.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements.Loops;
-
-public sealed class ForStatement : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- //for x : i32 in 1..12
- //for x in arr
- var keywordToken = iterator.Prev;
- var varExpr = Expression.Parse(parser);
-
- LNode type = LNode.Missing;
-
- if (iterator.Current.Type == TokenType.Colon)
- {
- iterator.NextToken();
-
- type = TypeLiteral.Parse(iterator, parser);
- }
-
- iterator.Match(TokenType.In);
-
- var collExpr = Expression.Parse(parser);
- var body = Statement.ParseOneOrBlock(parser);
-
- return SyntaxTree.For(SyntaxTree.Factory.Tuple(varExpr, type), collExpr, body)
- .WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Loops/WhileStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Loops/WhileStatement.cs
deleted file mode 100644
index af52d52d..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Loops/WhileStatement.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements.Loops;
-
-public sealed class WhileStatement : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
-
- var cond = Expression.Parse(parser);
- var body = Statement.ParseOneOrBlock(parser);
-
- return SyntaxTree.While(cond, body).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/MacroBlockStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/MacroBlockStatement.cs
deleted file mode 100644
index 1c731e8f..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/MacroBlockStatement.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements;
-
-public sealed class MacroBlockStatement : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var nameToken = iterator.Prev;
-
- var currPos = iterator.Position - 1;
-
- var nameExpression = LNode.Id(nameToken.Text);
-
- if (iterator.ConsumeIfMatch(TokenType.OpenParen))
- {
- var arguments = Expression.ParseList(parser, TokenType.CloseParen);
-
- if (iterator.Current.Type == TokenType.OpenCurly)
- {
- //custom code block with arguments
- var body = Statement.ParseBlock(parser);
- arguments = arguments.Add(body);
-
- return SyntaxTree.Factory.Call(nameExpression, arguments).SetStyle(NodeStyle.StatementBlock)
- .WithRange(nameToken, iterator.Prev);
- }
-
- iterator.Match(TokenType.Semicolon);
-
- return SyntaxTree.Factory.Call(nameExpression, arguments).WithRange(nameToken, iterator.Prev);
- }
-
- if (iterator.Current.Type == TokenType.OpenCurly)
- {
- //custom code block without arguments
- var body = Statement.ParseBlock(parser);
- var arguments = LNode.List(LNode.Missing, body);
-
- return SyntaxTree.Factory.Call(nameExpression, arguments).SetStyle(NodeStyle.StatementBlock)
- .WithRange(nameToken, iterator.Prev);
- }
-
- iterator.Position = currPos;
-
- return ExpressionStatement.Parse(iterator, parser);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/ReturnStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/ReturnStatement.cs
deleted file mode 100644
index 190afd83..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/ReturnStatement.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements;
-
-public sealed class ReturnStatement : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- var arguments = LNode.List();
-
- if (!iterator.IsMatch(TokenType.Semicolon))
- {
- arguments.Add(Expression.Parse(parser));
- }
-
- iterator.Match(TokenType.Semicolon);
-
- return SyntaxTree.Factory.Call(CodeSymbols.Return, arguments).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Statement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Statement.cs
deleted file mode 100644
index 9ca84a7e..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/Statement.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements;
-
-public static class Statement
-{
- public static LNode ParseBlock(Parser parser)
- {
- var openCurlyToken = parser.Iterator.Match(TokenType.OpenCurly);
-
- var body = new List();
- while (!parser.Iterator.IsMatch(TokenType.CloseCurly) && !parser.Iterator.IsMatch(TokenType.EOF))
- {
- body.Add(parser.InvokeStatementParsePoint());
- }
-
- parser.Iterator.Match(TokenType.CloseCurly);
-
- return SyntaxTree.Factory.Braces(body).WithStyle(NodeStyle.StatementBlock)
- .WithRange(openCurlyToken, parser.Iterator.Prev);
- }
-
- public static LNode ParseOneOrBlock(Parser parser)
- {
- if (parser.Iterator.IsMatch(TokenType.OpenCurly))
- {
- return ParseBlock(parser);
- }
-
- var node = parser.InvokeStatementParsePoint();
-
- return SyntaxTree.Factory.Braces(node).WithStyle(NodeStyle.StatementBlock).WithRange(node.Range);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/SwitchStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/SwitchStatement.cs
deleted file mode 100644
index 1d616345..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/SwitchStatement.cs
+++ /dev/null
@@ -1,167 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Loyc;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements;
-
-public sealed class SwitchStatement : IParsePoint
-{
- /*
- * switch element {
- * case cond: oneExpr;
- * case cond: { block; }
- * if boolean: oneExpr;
- * if boolean: { block; }
- * break when > value: { block; }
- * default: oneExpr;
- * default: { block; }
- * }
- */
-
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- var element = Expression.Parse(parser);
-
- parser.Iterator.Match(TokenType.OpenCurly);
-
- var cases = new LNodeList();
-
- while (!parser.Iterator.IsMatch(TokenType.CloseCurly))
- {
- var autoBreak = iterator.IsMatch(TokenType.Break);
-
- if (autoBreak)
- {
- iterator.Match(TokenType.Break);
- }
-
- if (iterator.IsMatch(TokenType.Case))
- {
- cases.Add(ParseCase(parser, autoBreak));
- }
- else if (iterator.IsMatch(TokenType.If))
- {
- cases.Add(ParseIf(parser, autoBreak));
- }
- else if (iterator.IsMatch(TokenType.When))
- {
- cases.Add(ParseWhen(parser, autoBreak));
- }
- else if (iterator.IsMatch(TokenType.Default))
- {
- cases.Add(ParseDefault(parser, autoBreak));
- }
- else
- {
- var range = new SourceRange(parser.Document, iterator.Current.Start, iterator.Current.Text.Length);
-
- parser.AddError(new LocalizableString(ErrorID.UnknownSwitchOption), range);
- return LNode.Missing;
- }
- }
-
- parser.Iterator.Match(TokenType.CloseCurly);
-
- return SyntaxTree.Switch(element, cases).WithRange(keywordToken, iterator.Prev);
- }
-
- private static LNode ParseCase(Parser parser, bool autoBreak)
- {
- var keywordToken = parser.Iterator.Match(TokenType.Case);
-
- var condition = Expression.Parse(parser);
-
- parser.Iterator.Match(TokenType.Colon);
-
- var body = Statement.ParseOneOrBlock(parser);
-
- if (autoBreak)
- {
- body = body.PlusArg(LNode.Call(CodeSymbols.Break));
- }
-
- return SyntaxTree.Case(condition, body).WithRange(keywordToken, parser.Iterator.Prev);
- }
-
- private static LNode ParseDefault(Parser parser, bool autoBreak)
- {
- parser.Iterator.Match(TokenType.Default);
-
- parser.Iterator.Match(TokenType.Colon);
-
- var body = Statement.ParseOneOrBlock(parser);
-
- if (autoBreak)
- {
- body = body.PlusArg(LNode.Call(CodeSymbols.Break));
- }
-
- return SyntaxTree.Case(LNode.Call(CodeSymbols.Default), body);
- }
-
- private static LNode ParseIf(Parser parser, bool autoBreak)
- {
- parser.Iterator.Match(TokenType.If);
-
- var condition = Expression.Parse(parser);
-
- parser.Iterator.Match(TokenType.Colon);
-
- var body = Statement.ParseOneOrBlock(parser);
-
- if (autoBreak)
- {
- body = body.PlusArg(LNode.Call(CodeSymbols.Break));
- }
-
- return SyntaxTree.If(condition, body, SyntaxTree.Factory.Braces());
- }
-
- private static LNode ParseWhen(Parser parser, bool autoBreak)
- {
- parser.Iterator.Match(TokenType.When);
-
- LNode binOp = LNode.Missing;
- LNode right;
- if (Expression.GetBinaryOperatorPrecedence(parser.Iterator.Current.Type) > 0)
- {
- // with binary expression
- var operatorToken = parser.Iterator.NextToken();
-
- right = Expression.Parse(parser);
- binOp = LNode.Call(GSymbol.Get($"'{operatorToken.Text}"));
- }
- else
- {
- // with element function
- if (!parser.Iterator.IsMatch(TokenType.Identifier))
- {
- var range = new SourceRange(parser.Document, parser.Iterator.Current.Start,
- parser.Iterator.Current.Text.Length);
-
- parser.AddError(new LocalizableString(ErrorID.ExpectedIdentifier, parser.Iterator.Current.Text), range);
-
- return LNode.Missing;
- }
-
- var name = LNode.Id(parser.Iterator.Current.Text);
- parser.Iterator.Match(TokenType.Identifier);
- parser.Iterator.Match(TokenType.OpenParen);
- var args = Expression.ParseList(parser, TokenType.CloseParen);
-
- right = LNode.Call(name, args);
- }
-
- parser.Iterator.Match(TokenType.Colon);
-
- var body = Statement.ParseOneOrBlock(parser);
-
- if (autoBreak)
- {
- body = body.PlusArg(LNode.Call(CodeSymbols.Break));
- }
-
- return SyntaxTree.When(binOp, right, body);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/ThrowStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/ThrowStatement.cs
deleted file mode 100644
index de49bfb4..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/ThrowStatement.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements;
-
-public class ThrowStatement : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
-
- LNode arg = LNode.Missing;
- if (!iterator.IsMatch(TokenType.Semicolon))
- {
- arg = Expression.Parse(parser);
- }
-
- iterator.Match(TokenType.Semicolon);
-
- return SyntaxTree.Throw(arg).WithRange(keywordToken, iterator.Prev);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/TryStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/TryStatement.cs
deleted file mode 100644
index b56f6dff..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/TryStatement.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements;
-
-public sealed class TryStatement : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
- var body = Statement.ParseOneOrBlock(parser);
- LNodeList catches = new(LNode.Missing);
-
- if (iterator.Current.Type != TokenType.Catch)
- {
- var range = new SourceRange(parser.Document, iterator.Current.Start, iterator.Current.Text.Length);
-
- parser.AddError(new LocalizableString(ErrorID.NoCatchBlock), range);
- }
-
- while (iterator.Current.Type == TokenType.Catch)
- {
- iterator.NextToken();
-
- catches.Add(ParseCatch(parser));
- }
-
- LNode finallly = LNode.Missing;
- if (iterator.IsMatch(TokenType.Finally))
- {
- iterator.Match(TokenType.Finally);
- finallly = Statement.ParseOneOrBlock(parser);
- }
-
- return SyntaxTree.Try(body, SyntaxTree.Factory.AltList(catches), finallly)
- .WithRange(keywordToken, iterator.Prev);
- }
-
- private static LNode ParseCatch(Parser parser)
- {
- parser.Iterator.Match(TokenType.OpenParen);
- var exceptionValueName = LNode.Id(parser.Iterator.Match(TokenType.Identifier).Text);
- parser.Iterator.Match(TokenType.Colon);
- var exceptionType = LNode.Id(parser.Iterator.Match(TokenType.Identifier).Text);
- parser.Iterator.Match(TokenType.CloseParen);
-
- var body = Statement.ParseOneOrBlock(parser);
-
- return SyntaxTree.Catch(exceptionType, exceptionValueName, body);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/VariableStatement.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Statements/VariableStatement.cs
deleted file mode 100644
index fbafac42..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Statements/VariableStatement.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST.Statements;
-
-public class VariableStatement : IParsePoint
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- var keywordToken = iterator.Prev;
-
- var isMutable = false;
- var type = SyntaxTree.Type("", LNode.List());
- LNode value = LNode.Missing;
-
- Token mutableToken = null;
-
- if (iterator.Current.Type == TokenType.Mutable)
- {
- isMutable = true;
- mutableToken = iterator.NextToken();
- }
-
- var nameToken = iterator.Match(TokenType.Identifier);
- var name = SyntaxTree.Factory.Id(nameToken.Text).WithRange(nameToken);
-
- if (iterator.Current.Type == TokenType.Colon)
- {
- iterator.NextToken();
-
- type = TypeLiteral.Parse(iterator, parser);
- }
-
- if (iterator.Current.Type == TokenType.EqualsToken)
- {
- iterator.NextToken();
-
- value = Expression.Parse(parser);
- }
-
- iterator.Match(TokenType.Semicolon);
-
- var node = SyntaxTree.Factory.Var(type, name, value).WithRange(keywordToken, iterator.Prev);
-
- return isMutable ? node.WithAttrs(SyntaxTree.Factory.Id(Symbols.Mutable).WithRange(mutableToken)) : node;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/Symbols.cs b/Source/Backlang.Codeanalysis/Parsing/AST/Symbols.cs
deleted file mode 100644
index d64a70b0..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/Symbols.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using Loyc;
-
-namespace Backlang.Codeanalysis.Parsing.AST;
-
-public static class Symbols
-{
- public static readonly Symbol Annotation = GSymbol.Get("#annotation");
- public static readonly Symbol Bitfield = GSymbol.Get("#bitfield");
- public static readonly Symbol ColonColon = GSymbol.Get("'::");
- public static readonly Symbol Constructor = GSymbol.Get("#constructor");
- public static readonly Symbol Destructor = GSymbol.Get("#destructor");
- public static readonly Symbol DiscriminatedType = GSymbol.Get("#discrimType");
- public static readonly Symbol DiscriminatedUnion = GSymbol.Get("#discrimUnion");
- public static readonly Symbol Float16 = GSymbol.Get("#float16");
- public static readonly Symbol Float32 = GSymbol.Get("#float32");
- public static readonly Symbol Float64 = GSymbol.Get("#float64");
- public static readonly Symbol Global = GSymbol.Get("#global");
- public static readonly Symbol Implementation = GSymbol.Get("#implement");
- public static readonly Symbol Inheritance = GSymbol.Get("#inheritance");
- public static readonly Symbol Macro = GSymbol.Get("#macro");
- public static readonly Symbol Match = GSymbol.Get("#match");
- public static readonly Symbol Mutable = GSymbol.Get("#mutable");
- public static readonly Symbol PointerType = GSymbol.Get("#type*");
- public static readonly Symbol RefType = GSymbol.Get("#type&");
- public static readonly Symbol NullableType = GSymbol.Get("#type?");
- public static readonly Symbol Range = GSymbol.Get("'..");
- public static readonly Symbol ToExpand = GSymbol.Get("'to_expand'");
- public static readonly Symbol TypeLiteral = GSymbol.Get("#type");
- public static readonly Symbol Union = GSymbol.Get("#union");
- public static readonly Symbol Where = GSymbol.Get("#where");
- public static readonly Symbol Init = GSymbol.Get("#init");
- public static readonly Symbol Unit = GSymbol.Get("#unit");
- public static readonly Symbol UnitDecl = GSymbol.Get("#unitDecl");
- public static readonly Symbol AssertNonNull = GSymbol.Get("#notnull");
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/AST/TypeLiteral.cs b/Source/Backlang.Codeanalysis/Parsing/AST/TypeLiteral.cs
deleted file mode 100644
index 8c1ba125..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/AST/TypeLiteral.cs
+++ /dev/null
@@ -1,162 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing.AST;
-
-public sealed class TypeLiteral
-{
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- LNode typeNode;
- var typeToken = iterator.Current;
-
- if (iterator.IsMatch(TokenType.Identifier))
- {
- var typename = iterator.Match(TokenType.Identifier).Text;
- var args = new LNodeList();
-
- typeNode = SyntaxTree.Type(typename, new LNodeList()).WithRange(typeToken);
-
- if (iterator.IsMatch(TokenType.Star))
- {
- iterator.NextToken();
-
- typeNode = SyntaxTree.Pointer(typeNode).WithRange(typeToken, iterator.Prev);
- }
-
- if (iterator.IsMatch(TokenType.Ampersand))
- {
- iterator.NextToken();
-
- typeNode = SyntaxTree.RefType(typeNode).WithRange(typeToken, iterator.Prev);
- }
- else if (iterator.IsMatch(TokenType.Questionmark))
- {
- iterator.NextToken();
-
- typeNode = SyntaxTree.NullableType(typeNode).WithRange(typeToken, iterator.Prev);
- }
- else if (iterator.IsMatch(TokenType.OpenSquare))
- {
- typeNode = ParseArrayType(iterator, typeNode, typeToken);
- }
- else if (iterator.IsMatch(TokenType.LessThan))
- {
- typeNode = ParseGenericType(iterator, parser, typeToken, typename, args);
- }
- }
- else if (iterator.IsMatch(TokenType.None))
- {
- typeNode = SyntaxTree.Type("none", LNode.List()).WithRange(typeToken);
- iterator.NextToken();
- }
- else if (iterator.IsMatch(TokenType.OpenParen))
- {
- typeNode = ParseFunctionOrTupleType(iterator, parser, typeToken);
- }
- else
- {
- parser.AddError(new LocalizableString(ErrorID.UnexpecedType,
- TokenIterator.GetTokenRepresentation(iterator.Current.Type))); //ToDo: Add Range
-
- typeNode = LNode.Missing;
- iterator.NextToken();
- }
-
- return typeNode;
- }
-
- public static bool TryParse(Parser parser, out LNode node)
- {
- var cursor = parser.Iterator.Position;
- node = Parse(parser.Iterator, parser);
-
- if (node == LNode.Missing)
- {
- parser.Iterator.Position = cursor;
- return false;
- }
-
- return true;
- }
-
- private static LNode ParseFunctionOrTupleType(TokenIterator iterator, Parser parser, Token typeToken)
- {
- LNode typeNode;
- iterator.Match(TokenType.OpenParen);
-
- var parameters = new LNodeList();
- while (parser.Iterator.Current.Type != TokenType.CloseParen)
- {
- parameters.Add(Parse(iterator, parser));
-
- if (parser.Iterator.Current.Type != TokenType.CloseParen)
- {
- parser.Iterator.Match(TokenType.Comma);
- }
- }
-
- parser.Iterator.Match(TokenType.CloseParen);
-
- if (iterator.Current.Type == TokenType.Arrow)
- {
- iterator.NextToken();
-
- var returnType = Parse(iterator, parser);
-
- typeNode = SyntaxTree.Factory.Call(CodeSymbols.Fn,
- LNode.List(returnType, LNode.Missing, LNode.Call(CodeSymbols.AltList, parameters)))
- .WithRange(typeToken, iterator.Prev);
- }
- else
- {
- typeNode = SyntaxTree.Factory.Tuple(parameters).WithRange(typeToken, iterator.Prev);
- }
-
- return typeNode;
- }
-
- private static LNode ParseGenericType(TokenIterator iterator, Parser parser, Token typeToken, string typename,
- LNodeList args)
- {
- LNode typeNode;
- iterator.NextToken();
-
- while (!iterator.IsMatch(TokenType.GreaterThan))
- {
- if (iterator.IsMatch(TokenType.Identifier))
- {
- args.Add(Parse(iterator, parser));
- }
-
- if (!iterator.IsMatch(TokenType.GreaterThan))
- {
- iterator.Match(TokenType.Comma);
- }
- }
-
- iterator.Match(TokenType.GreaterThan);
-
- typeNode = SyntaxTree.Type(typename, args).WithRange(typeToken, parser.Iterator.Prev);
- return typeNode;
- }
-
- private static LNode ParseArrayType(TokenIterator iterator, LNode typeNode, Token typeToken)
- {
- iterator.NextToken();
-
- var dimensions = 1;
-
- while (iterator.IsMatch(TokenType.Comma))
- {
- dimensions++;
-
- iterator.NextToken();
- }
-
- iterator.Match(TokenType.CloseSquare);
-
- typeNode = SyntaxTree.Array(typeNode, dimensions).WithRange(typeToken, iterator.Prev);
- return typeNode;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/Expression.cs b/Source/Backlang.Codeanalysis/Parsing/Expression.cs
deleted file mode 100644
index 3be40ef7..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/Expression.cs
+++ /dev/null
@@ -1,153 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Backlang.Codeanalysis.Core.Attributes;
-using Loyc;
-using Loyc.Syntax;
-using System.Reflection;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public static class Expression
-{
- public static readonly Dictionary BinaryOperators = new();
- public static readonly Dictionary PostUnaryOperators = new();
- public static readonly Dictionary PreUnaryOperators = new();
-
- static Expression()
- {
- var typeValues = (TokenType[])Enum.GetValues(typeof(TokenType));
-
- foreach (var op in typeValues)
- {
- var attributes = op.GetType().GetField(Enum.GetName(op)).GetCustomAttributes(true);
-
- if (attributes != null && attributes.Any())
- {
- foreach (var attribute in attributes)
- {
- if (attribute.IsUnary)
- {
- if (attribute.IsPostUnary)
- {
- PostUnaryOperators.Add(op, attribute.Precedence);
- }
- else
- {
- PreUnaryOperators.Add(op, attribute.Precedence);
- }
- }
- else
- {
- BinaryOperators.Add(op, attribute.Precedence);
- }
- }
- }
- }
- }
-
- public static int GetBinaryOperatorPrecedence(TokenType kind)
- {
- return BinaryOperators.GetValueOrDefault(kind);
- }
-
- public static LNode Parse(Parser parser, ParsePoints parsePoints = null, int parentPrecedence = 0)
- {
- LNode left = null;
- var preUnaryOperatorPrecedence = GetPreUnaryOperatorPrecedence(parser.Iterator.Current.Type);
-
- if (preUnaryOperatorPrecedence != 0 && preUnaryOperatorPrecedence >= parentPrecedence)
- {
- if (IsPreUnary(parser.Iterator.Current.Type))
- {
- var operatorToken = parser.Iterator.NextToken();
-
- var operand = Parse(parser, parsePoints, preUnaryOperatorPrecedence + 1);
-
- left = SyntaxTree.Unary(GSymbol.Get($"'{operatorToken.Text}"), operand)
- .WithRange(operatorToken.Start, operand.Range.EndIndex).WithStyle(NodeStyle.PrefixNotation);
- }
- }
- else
- {
- left = parser.ParsePrimary();
-
- //parsing postunarys for: hello?;
- var postUnaryOperatorPrecedence = GetPostUnaryOperatorPrecedence(parser.Iterator.Current.Type);
-
- if (postUnaryOperatorPrecedence != 0 && postUnaryOperatorPrecedence >= parentPrecedence)
- {
- if (IsPostUnary(parser.Iterator.Current.Type))
- {
- var unaryOperatorToken = parser.Iterator.NextToken();
-
- left = SyntaxTree.Unary(GSymbol.Get($"'suf{unaryOperatorToken.Text}"), left)
- .WithRange(left.Range.StartIndex, unaryOperatorToken.End).WithStyle(NodeStyle.Operator);
- }
- }
- }
-
- while (true)
- {
- var precedence = GetBinaryOperatorPrecedence(parser.Iterator.Current.Type);
- if (precedence == 0 || precedence <= parentPrecedence)
- {
- break;
- }
-
- var operatorToken = parser.Iterator.NextToken();
- var right = Parse(parser, parsePoints, precedence);
-
- left = SyntaxTree.Binary(GSymbol.Get($"'{operatorToken.Text}"), left, right)
- .WithRange(left.Range.StartIndex, right.Range.StartIndex);
-
- // parsing postunary for: Hello::new()? = false;
- var postUnaryOperatorPrecedence = GetPostUnaryOperatorPrecedence(parser.Iterator.Current.Type);
-
- if (postUnaryOperatorPrecedence != 0 && postUnaryOperatorPrecedence >= parentPrecedence)
- {
- if (IsPostUnary(parser.Iterator.Current.Type))
- {
- var unaryOperatorToken = parser.Iterator.NextToken();
-
- left = SyntaxTree.Unary(GSymbol.Get($"'suf{unaryOperatorToken.Text}"), left)
- .WithRange(left.Range.StartIndex, unaryOperatorToken.End).WithStyle(NodeStyle.Operator);
- }
- }
- }
-
- return left;
- }
-
- public static LNodeList ParseList(Parser parser, TokenType terminator, bool consumeTerminator = true)
- {
- return ParsingHelpers.ParseSeperated(parser, terminator,
- consumeTerminator: consumeTerminator);
- }
-
- private static int GetPreUnaryOperatorPrecedence(TokenType kind)
- {
- return PreUnaryOperators.GetValueOrDefault(kind);
- }
-
- private static int GetPostUnaryOperatorPrecedence(TokenType kind)
- {
- return PostUnaryOperators.GetValueOrDefault(kind);
- }
-
- private static bool IsPreUnary(TokenType kind)
- {
- return PreUnaryOperators.ContainsKey(kind);
- }
-
- private static bool IsPostUnary(TokenType kind)
- {
- return PostUnaryOperators.ContainsKey(kind);
- }
-
- private class ExpressionParser : IParsePoint
- {
- public static LNode Parse(TokenIterator iterator, Parser parser)
- {
- return Expression.Parse(parser);
- }
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/IParsePoint.cs b/Source/Backlang.Codeanalysis/Parsing/IParsePoint.cs
deleted file mode 100644
index a36d7c8e..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/IParsePoint.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public interface IParsePoint
-{
- static abstract LNode Parse(TokenIterator iterator, Parser parser);
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/LNodeExtensions.cs b/Source/Backlang.Codeanalysis/Parsing/LNodeExtensions.cs
deleted file mode 100644
index 12ebacd9..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/LNodeExtensions.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using Backlang.Codeanalysis.Parsing.AST;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public static class LNodeExtensions
-{
- public static LNode WithRange(this LNode node, int start, int end)
- {
- return node.WithRange(new SourceRange(node.Source, start, Math.Abs(start - end))).WithAttrs(node.Attrs);
- }
-
- public static LNode WithRange(this LNode node, Token token)
- {
- return WithRange(node, token.Start, token.End);
- }
-
- public static LNode WithRange(this LNode node, Token startToken, Token endtoken)
- {
- return WithRange(node, startToken.Start, endtoken.End);
- }
-
- public static LNode FromToken(this LNodeFactory factory, Token token)
- {
- return factory.Id(token.Text).WithRange(token);
- }
-
- public static bool IsNoneType(this LNode node)
- {
- return node.Name == Symbols.TypeLiteral && node.Args[0].Args[0].Name.Name == "none" &&
- node.Args[0].Args[0].IsId;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/Lexer.cs b/Source/Backlang.Codeanalysis/Parsing/Lexer.cs
deleted file mode 100644
index 34ef2465..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/Lexer.cs
+++ /dev/null
@@ -1,416 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Backlang.Codeanalysis.Core.Attributes;
-using Loyc.Syntax;
-using System.Reflection;
-using System.Text;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public sealed class Lexer : BaseLexer
-{
- private static readonly Dictionary _symbolTokens = new(StringComparer.Ordinal);
-
- static Lexer()
- {
- var typeValues = (TokenType[])Enum.GetValues(typeof(TokenType));
-
- foreach (var op in typeValues)
- {
- var attributes = op.GetType()
- .GetField(Enum.GetName(op)).GetCustomAttributes(true);
-
- if (attributes != null && attributes.Any())
- {
- foreach (var attribute in attributes)
- {
- _symbolTokens.Add(attribute.Lexeme, op);
- }
- }
- }
-
- _symbolTokens = new Dictionary(_symbolTokens.OrderByDescending(_ => _.Key.Length));
- }
-
- protected override Token NextToken()
- {
- if (IsMatch("///"))
- {
- return LexDocComment();
- }
-
- SkipWhitespaces();
- SkipComments();
-
- if (_position >= _document.Text.Count)
- {
- return new Token(TokenType.EOF, "\0", _position, _position, _line, _column);
- }
-
- if (Current() == '\'')
- {
- return LexCharLiteral();
- }
-
- if (Current() == '"')
- {
- return LexDoubleQuoteString();
- }
-
- if (IsMatch("0x"))
- {
- return LexHexNumber();
- }
-
- if (IsMatch("0b"))
- {
- return LexBinaryNumber();
- }
-
- if (char.IsDigit(Current()))
- {
- return LexDecimalNumber();
- }
-
- if (IsIdentifierStartDigit())
- {
- var identifier = LexIdentifier();
-
- if (IsOperatorIdentifier(identifier))
- {
- identifier.Type = GetOperatorKind(identifier);
- }
-
- return identifier;
- }
-
- foreach (var symbol in _symbolTokens)
- {
- if (IsMatch(symbol.Key))
- {
- return LexSymbol(symbol);
- }
- }
-
- ReportError();
-
- return Token.Invalid;
- }
-
- private Token LexDocComment()
- {
- var oldPos = _position;
- var contentBuilder = new StringBuilder();
-
- do
- {
- contentBuilder.AppendLine(ReadLine().TrimStart('/').Trim());
- } while (IsMatch("///"));
-
- return new Token(TokenType.DocComment, contentBuilder.ToString(), oldPos, _position, _line, _column);
- }
-
-
- private string ReadLine()
- {
- var sb = new StringBuilder();
-
- while (Current() != '\n')
- {
- Advance();
- _column++;
- }
-
- Advance();
- _column = 0;
- _line++;
-
- return sb.ToString();
- }
-
- private static bool IsBinaryDigit(char c)
- {
- return c == '0' || c == '1';
- }
-
- private static bool IsHex(char c)
- {
- return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
- }
-
- private TokenType GetOperatorKind(Token identifier)
- {
- foreach (var s in _symbolTokens)
- {
- if (identifier.Text == s.Key)
- {
- return s.Value;
- }
- }
-
- return TokenType.Identifier;
- }
-
- private bool IsIdentifierDigit()
- {
- return char.IsLetterOrDigit(Current()) || Current() == '_';
- }
-
- private bool IsIdentifierStartDigit()
- {
- return char.IsLetter(Current()) || Current() == '_';
- }
-
- private bool IsMatch(string token)
- {
- var result = Current() == token[0];
-
- for (var i = 1; i < token.Length; i++)
- {
- if (result)
- {
- result = result && Peek(i) == token[i];
- }
- }
-
- return result;
- }
-
- private bool IsOperatorIdentifier(Token identifier)
- {
- return _symbolTokens.ContainsKey(identifier.Text);
- }
-
- private Token LexBinaryNumber()
- {
- _position += 2;
- _column += 2;
-
- var oldpos = _position;
- var oldcolumn = _column;
-
- while (IsBinaryDigit(Current()) || Current() == '_')
- {
- Advance();
- _column++;
- }
-
- return new Token(TokenType.BinNumber,
- _document.Text.Slice(oldpos, _position - oldpos).ToString().Replace("_", string.Empty), oldpos, _position,
- _line, oldcolumn);
- }
-
- private Token LexCharLiteral()
- {
- var oldpos = ++_position;
- var oldColumn = _column;
-
- if (Current() == '\n' || Current() == '\r')
- {
- var range = new SourceRange(_document, _column, 1);
- Messages.Add(Message.Error(ErrorID.UnterminatedCharLiteral, range));
-
- return Token.Invalid;
- }
-
- while (Peek() != '\'' && Peek() != '\0')
- {
- Advance();
- _column++;
- }
-
- _column += 2;
-
- return new Token(TokenType.CharLiteral, _document.Text.Slice(oldpos, _position - oldpos).ToString(), oldpos - 1,
- ++_position, _line, oldColumn);
- }
-
- private Token LexDecimalNumber()
- {
- var oldpos = _position;
- var oldcolumn = _column;
-
- while (char.IsDigit(Current()))
- {
- _position++;
- _column++;
- }
-
- if (char.IsDigit(Peek(1)) && Current() == '.')
- {
- Advance();
- _column++;
-
- while (char.IsDigit(Current()))
- {
- Advance();
- _column++;
- }
- }
-
- return new Token(TokenType.Number, _document.Text.Slice(oldpos, _position - oldpos).ToString(), oldpos,
- _position, _line, oldcolumn);
- }
-
- private Token LexDoubleQuoteString()
- {
- var oldpos = ++_position;
- var oldColumn = _column;
-
- while (Peek() != '"' && Peek() != '\0')
- {
- if (Current() == '\n' || Current() == '\r')
- {
- var range = new SourceRange(_document, _position, 1);
- Messages.Add(Message.Error(ErrorID.UnterminatedStringLiteral, range));
-
- return new Token(TokenType.StringLiteral,
- _document.Text.Slice(oldpos, _position - oldpos - 1).ToString(), oldpos - 1, _position, _line,
- oldColumn);
- }
-
- Advance();
- _column++;
- }
-
- _column += 2;
-
- return new Token(TokenType.StringLiteral, _document.Text.Slice(oldpos, _position - oldpos).ToString(),
- oldpos - 1, ++_position, _line, oldColumn);
- }
-
- private Token LexHexNumber()
- {
- _position += 2;
- _column += 2;
-
- var oldpos = _position;
- var oldcolumn = _column;
-
- while (IsHex(Current()) || Current() == '_')
- {
- Advance();
- _column++;
- }
-
- return new Token(TokenType.HexNumber,
- _document.Text.Slice(oldpos, _position - oldpos).ToString().Replace("_", string.Empty), oldpos, _position,
- _line, oldcolumn);
- }
-
- private Token LexIdentifier()
- {
- var oldpos = _position;
-
- var oldcolumn = _column;
- while (IsIdentifierDigit())
- {
- Advance();
- _column++;
- }
-
- var tokenText = _document.Text.Slice(oldpos, _position - oldpos).ToString();
-
- return new Token(TokenUtils.GetTokenType(tokenText), tokenText, oldpos, _position, _line, oldcolumn);
- }
-
- private Token LexSymbol(KeyValuePair symbol)
- {
- var oldpos = _position;
-
- _position += symbol.Key.Length;
- _column += symbol.Key.Length;
-
- var text = _document.Text.Slice(oldpos, symbol.Key.Length).ToString();
-
- return new Token(_symbolTokens[text], text, oldpos, _position, _line, _column);
- }
-
- private void SkipComments()
- {
- while (IsMatch("/*") || IsMatch("//"))
- {
- if (IsMatch("//"))
- {
- Advance();
- Advance();
- _column++;
- _column++;
-
- while (Current() != '\n' && Current() != '\r' && Current() != '\0')
- {
- Advance();
- _column++;
- }
-
- if (Current() == '\n' || Current() == '\r')
- {
- Advance();
- _column++;
- }
-
- SkipWhitespaces();
- }
- else if (IsMatch("/*"))
- {
- var oldpos = _position;
-
- Advance();
- Advance();
- _column++;
- _column++;
-
- while (!IsMatch("*/"))
- {
- if (Current() == '\0')
- {
- break;
- }
-
- Advance();
- _column++;
- }
-
- if (IsMatch("*/"))
- {
- Advance();
- _column++;
-
- Advance();
- _column++;
- }
- else
- {
- var range = new SourceRange(_document, oldpos, _position);
- Messages.Add(Message.Error(ErrorID.NotClosedMultilineComment, range));
-
- return;
- }
-
- SkipWhitespaces();
- }
- }
- }
-
- private void SkipWhitespaces()
- {
- while (char.IsWhiteSpace(Current()) && _position <= _document.Text.Count)
- {
- if (Current() == '\r')
- {
- _line++;
- _column = 1;
- Advance();
-
- if (Current() == '\n')
- {
- Advance();
- }
- }
- else
- {
- Advance();
- _column++;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/Message.cs b/Source/Backlang.Codeanalysis/Parsing/Message.cs
deleted file mode 100644
index f145c4e1..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/Message.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public enum MessageSeverity
-{
- Error, Warning, Info, Hint
-}
-
-public sealed class Message
-{
- public Message(MessageSeverity severity, string text, SourceRange range)
- {
- if (range.Source is SourceFile doc)
- {
- Document = doc;
- }
-
- Severity = severity;
- Text = text;
- Range = range;
- }
-
- public SourceRange Range { get; set; }
-
- public SourceFile Document { get; }
-
- public MessageSeverity Severity { get; set; }
- public string Text { get; set; }
-
- public static Message Error(LocalizableString message, SourceRange range)
- {
- return new Message(MessageSeverity.Error, message, range);
- }
-
- public static Message Error(LocalizableString message)
- {
- return new Message(MessageSeverity.Error, message, SourceRange.Synthetic);
- }
-
- public static Message Info(string message, SourceRange range)
- {
- return new Message(MessageSeverity.Info, message, range);
- }
-
- public static Message Warning(string message, SourceRange range)
- {
- return new Message(MessageSeverity.Warning, message, range);
- }
-
- public override string ToString()
- {
- if (Document == null)
- {
- return Text;
- }
-
- return $"{Document.FileName}:{Range.Start.Line}:{Range.Start.Column} {Text}";
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/OperatorInfo.cs b/Source/Backlang.Codeanalysis/Parsing/OperatorInfo.cs
deleted file mode 100644
index 9c74e8b9..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/OperatorInfo.cs
+++ /dev/null
@@ -1,3 +0,0 @@
-namespace Backlang.Codeanalysis.Parsing;
-
-public record struct OperatorInfo(TokenType TokenType, int Precedence, bool IsUnary, bool IsPostUnary);
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/ParsePoints.cs b/Source/Backlang.Codeanalysis/Parsing/ParsePoints.cs
deleted file mode 100644
index fa71aaa0..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/ParsePoints.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public sealed class ParsePoints : Dictionary>
-{
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/Parser.Expressions.cs b/Source/Backlang.Codeanalysis/Parsing/Parser.Expressions.cs
deleted file mode 100644
index f9e0d816..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/Parser.Expressions.cs
+++ /dev/null
@@ -1,213 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Backlang.Codeanalysis.Parsing.AST;
-using Loyc;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public sealed partial class Parser
-{
- private readonly Dictionary _lits = new()
- {
- { "ub", CodeSymbols.UInt8 },
- { "us", CodeSymbols.UInt16 },
- { "u", CodeSymbols.UInt32 },
- { "ui", CodeSymbols.UInt32 },
- { "ul", CodeSymbols.UInt64 },
- { "b", CodeSymbols.Int8 },
- { "s", CodeSymbols.Int16 },
- { "l", CodeSymbols.Int64 },
- { "h", Symbols.Float16 },
- { "f", Symbols.Float32 },
- { "d", Symbols.Float64 }
- };
-
- public void AddError(LocalizableString message, SourceRange range)
- {
- Messages.Add(Message.Error(message, range));
- }
-
- public void AddError(LocalizableString message)
- {
- Messages.Add(Message.Error(message,
- new SourceRange(Document, Iterator.Current.Start, Iterator.Current.Text.Length)));
- }
-
- internal LNode ParsePrimary(ParsePoints parsePoints = null)
- {
- parsePoints ??= ExpressionParsePoints;
-
- return Iterator.Current.Type switch
- {
- TokenType.StringLiteral => ParseString(),
- TokenType.CharLiteral => ParseChar(),
- TokenType.Number => ParseNumber(),
- TokenType.HexNumber => ParseHexNumber(),
- TokenType.BinNumber => ParseBinNumber(),
- TokenType.TrueLiteral => ParseBooleanLiteral(true),
- TokenType.FalseLiteral => ParseBooleanLiteral(false),
- TokenType.OpenSquare => ParseArrayLiteral(),
- _ => InvokeExpressionParsePoint(parsePoints)
- };
- }
-
- private LNode ParseArrayLiteral()
- {
- var startToken = Iterator.Current;
- Iterator.NextToken();
-
- var elements = Expression.ParseList(this, TokenType.CloseSquare);
-
- return SyntaxTree.Factory.Call(CodeSymbols.Array, elements).WithRange(startToken, Iterator.Prev);
- }
-
- private LNode Invalid(LocalizableString message)
- {
- AddError(message);
-
- return LNode.Call(CodeSymbols.Error, LNode.List(LNode.Literal(message)));
- }
-
- private LNode InvokeExpressionParsePoint(ParsePoints parsePoints)
- {
- var token = Iterator.Current;
- var type = token.Type;
-
- if (parsePoints.TryGetValue(type, out var value))
- {
- Iterator.NextToken();
-
- return value(Iterator, this).WithRange(token, Iterator.Prev);
- }
-
- if (type == Token.Invalid.Type)
- {
- return LNode.Missing;
- }
-
- return Invalid(ErrorID.UnknownExpression);
- }
-
- private LNode ParseBinNumber()
- {
- var valueToken = (UString)Iterator.NextToken().Text;
-
- var success = ParseHelpers.TryParseUInt(ref valueToken, out ulong result, 2, ParseNumberFlag.SkipUnderscores);
-
- if (!success)
- {
- return LNode.Missing;
- }
-
- return SyntaxTree.Factory.Call(CodeSymbols.Int32,
- LNode.List(SyntaxTree.Factory.Literal(result).WithStyle(NodeStyle.BinaryLiteral)))
- .WithRange(Iterator.Prev);
- }
-
- private LNode ParseBooleanLiteral(bool value)
- {
- Iterator.NextToken();
-
- return SyntaxTree.Factory.Call(CodeSymbols.Bool, LNode.List(SyntaxTree.Factory.Literal(value)))
- .WithRange(Iterator.Prev);
- }
-
- private LNode ParseChar()
- {
- var text = Iterator.NextToken().Text;
- var unescaped = ParseHelpers.UnescapeCStyle(text);
-
- return SyntaxTree.Factory.Call(CodeSymbols.Char,
- LNode.List(SyntaxTree.Factory.Literal(unescaped[0]))).WithRange(Iterator.Prev);
- }
-
- private LNode ParseHexNumber()
- {
- var valueToken = Iterator.NextToken();
-
- var parseSuccess = ParseHelpers.TryParseHex(valueToken.Text, out var result);
-
- if (!parseSuccess)
- {
- return LNode.Missing;
- }
-
- return SyntaxTree.Factory.Call(CodeSymbols.Int32,
- LNode.List(SyntaxTree.Factory.Literal(result)))
- .WithRange(Iterator.Prev);
- }
-
- private LNode ParseNumber()
- {
- var text = (UString)Iterator.NextToken().Text;
-
- LNode result;
- if (text.Contains('.'))
- {
- var value = ParseHelpers.TryParseDouble(ref text, 10, ParseNumberFlag.SkipUnderscores);
-
- result = SyntaxTree.Factory.Literal(value).WithRange(Iterator.Prev);
- }
- else
- {
- var success = ParseHelpers.TryParseInt(ref text, out int value, 10, ParseNumberFlag.SkipUnderscores);
-
- if (!success)
- {
- result = LNode.Missing;
- }
- else
- {
- result = SyntaxTree.Factory.Literal(value).WithRange(Iterator.Prev);
- }
- }
-
- if (Iterator.Current.Type == TokenType.Identifier)
- {
- if (_lits.TryGetValue(Iterator.Current.Text.ToLower(), out var value))
- {
- result = SyntaxTree.Factory.Call(value,
- LNode.List(result)).WithRange(Iterator.Prev, Iterator.Current);
- }
- else
- {
- AddError(new LocalizableString(ErrorID.UnknownLiteral, Iterator.Current.Text));
-
- result = LNode.Missing;
- }
-
- Iterator.NextToken();
- }
- else if (result.Value is double)
- {
- result = SyntaxTree.Factory.Call(Symbols.Float64, LNode.List(result)).WithRange(result.Range);
- }
- else
- {
- result = SyntaxTree.Factory.Call(CodeSymbols.Int32, LNode.List(result)).WithRange(result.Range);
- }
-
- if (Iterator.IsMatch(TokenType.LessThan))
- {
- Iterator.NextToken();
-
- var unit = Iterator.Match(TokenType.Identifier);
-
- result = SyntaxTree.Unit(result, unit.Text).WithRange(result.Range.StartIndex, unit.End);
-
- Iterator.Match(TokenType.GreaterThan);
- }
-
- return result;
- }
-
- private LNode ParseString()
- {
- var valueToken = Iterator.NextToken();
-
- var unescaped = ParseHelpers.UnescapeCStyle(valueToken.Text);
-
- return SyntaxTree.Factory.Call(CodeSymbols.String, LNode.List(SyntaxTree.Factory.Literal(unescaped)))
- .WithRange(valueToken);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/Parser.ParsePoints.cs b/Source/Backlang.Codeanalysis/Parsing/Parser.ParsePoints.cs
deleted file mode 100644
index e03b0e0e..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/Parser.ParsePoints.cs
+++ /dev/null
@@ -1,137 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Backlang.Codeanalysis.Parsing.AST;
-using Backlang.Codeanalysis.Parsing.AST.Declarations;
-using Backlang.Codeanalysis.Parsing.AST.Expressions;
-using Backlang.Codeanalysis.Parsing.AST.Expressions.Match;
-using Backlang.Codeanalysis.Parsing.AST.Statements;
-using Backlang.Codeanalysis.Parsing.AST.Statements.Loops;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public sealed partial class Parser
-{
- public readonly ParsePoints DeclarationParsePoints = new();
- public readonly ParsePoints ExpressionParsePoints = new();
- public readonly ParsePoints StatementParsePoints = new();
-
- public void InitParsePoints()
- {
- AddDeclarationParsePoint(TokenType.Bitfield);
- AddDeclarationParsePoint(TokenType.Union);
- AddDeclarationParsePoint(TokenType.Class);
- AddDeclarationParsePoint(TokenType.Constructor);
- AddDeclarationParsePoint(TokenType.Destructor);
- AddDeclarationParsePoint(TokenType.Type);
- AddDeclarationParsePoint(TokenType.Enum);
- AddDeclarationParsePoint(TokenType.Function);
- AddDeclarationParsePoint(TokenType.Macro);
- AddDeclarationParsePoint(TokenType.Interface);
- AddDeclarationParsePoint(TokenType.Implement);
- AddDeclarationParsePoint(TokenType.Import);
- AddDeclarationParsePoint(TokenType.Struct);
- AddDeclarationParsePoint(TokenType.Module);
- AddDeclarationParsePoint(TokenType.Using);
- AddDeclarationParsePoint(TokenType.Unit);
- AddDeclarationParsePoint(TokenType.Identifier);
-
- AddExpressionParsePoint(TokenType.Identifier);
- AddExpressionParsePoint(TokenType.OpenParen);
- AddExpressionParsePoint(TokenType.Match);
- AddExpressionParsePoint(TokenType.Default);
- AddExpressionParsePoint(TokenType.SizeOf);
- AddExpressionParsePoint(TokenType.TypeOf);
- AddExpressionParsePoint(TokenType.None);
- AddExpressionParsePoint(TokenType.OpenSquare);
-
- AddStatementParsePoint(TokenType.Throw);
- AddStatementParsePoint(TokenType.Break);
- AddStatementParsePoint(TokenType.Continue);
- AddStatementParsePoint(TokenType.Return);
- AddStatementParsePoint(TokenType.Let);
- AddStatementParsePoint(TokenType.Switch);
- AddStatementParsePoint(TokenType.If);
- AddStatementParsePoint(TokenType.While);
- AddStatementParsePoint(TokenType.Do);
- AddStatementParsePoint(TokenType.Try);
- AddStatementParsePoint(TokenType.For);
- AddStatementParsePoint(TokenType.Identifier);
- }
-
- public void AddDeclarationParsePoint(TokenType type)
- where T : IParsePoint
- {
- DeclarationParsePoints.Add(type, T.Parse);
- }
-
- public void AddExpressionParsePoint(TokenType type)
- where T : IParsePoint
- {
- ExpressionParsePoints.Add(type, T.Parse);
- }
-
- public void AddStatementParsePoint(TokenType type)
- where T : IParsePoint
- {
- StatementParsePoints.Add(type, T.Parse);
- }
-
- public LNodeList InvokeDeclarationParsePoints(TokenType terminator = TokenType.EOF, ParsePoints parsePoints = null)
- {
- if (parsePoints == null)
- {
- parsePoints = DeclarationParsePoints;
- }
-
- var body = new LNodeList();
- while (Iterator.Current.Type != terminator)
- {
- DocComment.TryParse(this, out var docComment);
- Annotation.TryParse(this, out var annotation);
- Modifier.TryParse(this, out var modifiers);
-
- var item = InvokeParsePoint(parsePoints)?.PlusAttrs(annotation).PlusAttrs(modifiers).PlusAttr(docComment);
-
- if (item != null)
- {
- body.Add(item);
- }
- }
-
- return body;
- }
-
- public LNode InvokeParsePoint(ParsePoints parsePoints)
- {
- var type = Iterator.Current.Type;
-
- if (parsePoints.ContainsKey(type))
- {
- Iterator.NextToken();
-
- return parsePoints[type](Iterator, this);
- }
-
- var range = new SourceRange(Document, Iterator.Current.Start, Iterator.Current.Text.Length);
-
- AddError(new LocalizableString(ErrorID.UnknownExpression, Iterator.Current.Text), range);
-
- Iterator.NextToken();
-
- return default;
- }
-
- public LNode InvokeStatementParsePoint()
- {
- var type = Iterator.Current.Type;
-
- if (StatementParsePoints.ContainsKey(type))
- {
- Iterator.NextToken();
-
- return StatementParsePoints[type](Iterator, this);
- }
-
- return ExpressionStatement.Parse(Iterator, this);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/Parser.cs b/Source/Backlang.Codeanalysis/Parsing/Parser.cs
deleted file mode 100644
index 31c438de..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/Parser.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Backlang.Codeanalysis.Parsing.AST;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public sealed partial class Parser
-{
- public readonly List Messages;
-
- public Parser(SourceFile document, List tokens, List messages)
- {
- Document = document;
- Iterator = new TokenIterator(tokens, document);
- Messages = messages;
-
- InitParsePoints();
- }
-
- public SourceFile Document { get; }
-
- public TokenIterator Iterator { get; set; }
-
- public static CompilationUnit Parse(SourceDocument src)
- {
- SourceFile document = src;
-
- if (document.Text == null)
- {
- return new CompilationUnit
- {
- Body = LNode.List(LNode.Missing),
- Messages = new List { Message.Error(ErrorID.EmptyFile, SourceRange.Synthetic) },
- Document = document
- };
- }
-
- var lexer = new Lexer();
- var tokens = lexer.Tokenize(document);
-
- var parser = new Parser(document, tokens, lexer.Messages);
-
- return parser.Program();
- }
-
- public CompilationUnit Program()
- {
- var node = Start();
-
- Iterator.Match(TokenType.EOF);
-
- return node;
- }
-
- private CompilationUnit Start()
- {
- var cu = new CompilationUnit();
-
- var body = InvokeDeclarationParsePoints();
-
- cu.Messages = Messages.Concat(Iterator.Messages).ToList();
- cu.Body = body;
- cu.Document = Document;
-
- return cu;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/Precedences/BinaryOpPrecedences.cs b/Source/Backlang.Codeanalysis/Parsing/Precedences/BinaryOpPrecedences.cs
deleted file mode 100644
index 4658b0e3..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/Precedences/BinaryOpPrecedences.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-namespace Backlang.Codeanalysis.Parsing.Precedences;
-
-public enum BinaryOpPrecedences
-{
- Casting = 1, // as
-
- Hat = 2,
-
- Ampersand = 3,
-
- EqualsEquals = 4,
- DashedOps = EqualsEquals, // add, sub
- Range = DashedOps,
- And = Range, // &&
-
- DottedOps = 5, // mul, div
- Percent = DottedOps,
- Or = Percent,
- Comparisons = Or, // < <= >= >
- SwapOperator = 2,
-
- FunctionCalls = 7, // . ::
-
- PipeOperator = 8, // |>
-
- Dot = 8,
- OperationShortcuts = 2, // += -= *= /=
- Equals = OperationShortcuts
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/Precedences/UnaryOpPrecedences.cs b/Source/Backlang.Codeanalysis/Parsing/Precedences/UnaryOpPrecedences.cs
deleted file mode 100644
index e9155098..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/Precedences/UnaryOpPrecedences.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-namespace Backlang.Codeanalysis.Parsing.Precedences;
-
-public enum UnaryOpPrecedences
-{
- Literals = 3, // u ui ub us ul b s l
-
- LogicalNot = 6, // !bool
- Negate = LogicalNot, // -int
-
- Ampersand = 9,
- Hat = Ampersand,
-
- Dollar = 10
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/SourceDocument.cs b/Source/Backlang.Codeanalysis/Parsing/SourceDocument.cs
deleted file mode 100644
index 8f6f1427..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/SourceDocument.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Loyc.Syntax;
-using System.Text;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public sealed class SourceDocument
-{
- private readonly SourceFile _document;
-
- public SourceDocument(string filename)
- {
- _document = new SourceFile(new StreamCharSource(File.OpenRead(filename)), filename);
- }
-
- public SourceDocument(string filename, string content)
- {
- var filebody = Encoding.Default.GetBytes(content);
-
- _document = new SourceFile(new StreamCharSource(new MemoryStream(filebody)), filename);
- }
-
- public static implicit operator SourceFile(SourceDocument doc)
- {
- SyntaxTree.Factory = new LNodeFactory(doc._document);
-
- return doc._document;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/SyntaxTree.cs b/Source/Backlang.Codeanalysis/Parsing/SyntaxTree.cs
deleted file mode 100644
index ed71155f..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/SyntaxTree.cs
+++ /dev/null
@@ -1,271 +0,0 @@
-using Backlang.Codeanalysis.Parsing.AST;
-using Loyc;
-using Loyc.Syntax;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public static class SyntaxTree
-{
- public static LNodeFactory Factory = new(EmptySourceFile.Unknown);
-
- public static LNode Annotation(LNode call)
- {
- return Factory.Call(Symbols.Annotation).PlusAttr(call);
- }
-
- public static LNode Constructor(LNodeList parameters, LNode code)
- {
- return Factory.Call(Symbols.Constructor, LNode.List(Factory.AltList(parameters), code));
- }
-
- public static LNode DiscriminatedType(Token nameToken, LNodeList parameters)
- {
- return Factory.Call(Symbols.DiscriminatedType,
- LNode.List(Factory.FromToken(nameToken), Factory.AltList(parameters)));
- }
-
- public static LNode DiscriminatedUnion(Token nameToken, LNodeList types)
- {
- return Factory.Call(Symbols.DiscriminatedUnion,
- LNode.List(Factory.FromToken(nameToken), Factory.AltList(types)));
- }
-
- public static LNode Property(LNode type, LNode name, LNode getter, LNode setter, LNode value)
- {
- if (value != null)
- {
- return LNode.Call(CodeSymbols.Property,
- LNode.List(type, getter, setter, LNode.Call(CodeSymbols.Assign, LNode.List(name, value))));
- }
-
- return LNode.Call(CodeSymbols.Property, LNode.List(type, getter, setter, name));
- }
-
- public static LNode Destructor(LNodeList parameters, LNode code)
- {
- return Factory.Call(Symbols.Destructor, LNode.List(Factory.AltList(parameters), code));
- }
-
- public static LNode Array(LNode typeNode, int dimensions)
- {
- return Factory.Call(CodeSymbols.Array, LNode.List(typeNode, LNode.Literal(dimensions)));
- }
-
- public static LNode Throw(LNode arg)
- {
- return Factory.Call(CodeSymbols.Throw, LNode.List(arg));
- }
-
- public static LNode ArrayInstantiation(LNodeList elements)
- {
- return Factory.Call(CodeSymbols.Braces, elements);
- }
-
- public static LNode ArrayInstantiation(LNode arr, LNodeList indices)
- {
- return arr.WithArgs(indices);
- }
-
- public static LNode Binary(Symbol op, LNode left, LNode right)
- {
- return Factory.Call(op, LNode.List(left, right)).SetStyle(NodeStyle.Operator);
- }
-
- public static LNode Bitfield(Token nameToken, LNodeList members)
- {
- return Factory.Call(Symbols.Bitfield, LNode.List(Factory.FromToken(nameToken), Factory.AltList(members)));
- }
-
- public static LNode Case(LNode condition, LNode body)
- {
- return Factory.Call(CodeSymbols.Case, LNode.List(condition, body));
- }
-
- public static LNode Catch(IdNode exceptionType, IdNode exceptionValueName, LNode body)
- {
- return Factory.Call(CodeSymbols.Catch, LNode.List(exceptionType, exceptionValueName, body));
- }
-
- public static LNode Class(Token nameToken, LNodeList inheritances, LNodeList members)
- {
- return Factory.Call(CodeSymbols.Class,
- LNode.List(
- Factory.FromToken(nameToken),
- Factory.Call(Symbols.Inheritance, inheritances),
- Factory.Call(CodeSymbols.Braces, members).SetStyle(NodeStyle.StatementBlock)));
- }
-
- public static LNode Default()
- {
- return Default(LNode.Missing);
- }
-
- public static LNode Default(LNode type)
- {
- return Factory.Call(CodeSymbols.Default, LNode.List(type));
- }
-
- public static LNode Enum(LNode name, LNodeList members)
- {
- return Factory.Call(CodeSymbols.Enum, Factory.AltList(name,
- Factory.Call(CodeSymbols.AltList),
- Factory.Call(CodeSymbols.Braces,
- members)));
- }
-
- public static LNode For(LNode init, LNode arr, LNode body)
- {
- return Factory.Call(
- CodeSymbols.For,
- Factory.AltList(Factory.AltList(
- Factory.AltList(LNode.Call(CodeSymbols.In,
- Factory.AltList(init, arr)).SetStyle(NodeStyle.Operator))), LNode.Missing,
- Factory.AltList(), body));
- }
-
- public static LNode If(LNode cond, LNode ifBody, LNode elseBody)
- {
- return Factory.Call(CodeSymbols.If, Factory.AltList(cond, ifBody, elseBody));
- }
-
- public static LNode ImplDecl(LNode target, LNodeList body)
- {
- var attributes = new LNodeList();
-
- return Factory.Call(Symbols.Implementation,
- Factory.AltList(target, LNode.Call(CodeSymbols.Braces,
- body).SetStyle(NodeStyle.StatementBlock))).WithAttrs(attributes);
- }
-
- public static LNode Import(LNode expr)
- {
- return Factory.Call(CodeSymbols.Import, LNode.List(expr));
- }
-
- public static LNode Interface(Token nameToken, LNodeList inheritances, LNodeList members)
- {
- return Factory.Call(CodeSymbols.Interface,
- LNode.List(
- Factory.FromToken(nameToken),
- LNode.Call(Symbols.Inheritance, inheritances),
- LNode.Call(CodeSymbols.Braces, members).SetStyle(NodeStyle.StatementBlock)));
- }
-
- public static LNode Module(LNode ns)
- {
- return Factory.Call(CodeSymbols.Namespace, LNode.List(ns));
- }
-
- public static LNode None()
- {
- return Factory.Call(CodeSymbols.Void, LNode.Literal(null));
- }
-
- public static LNode Pointer(LNode type)
- {
- return Factory.Call(Symbols.PointerType, LNode.List(type));
- }
-
- public static LNode RefType(LNode type)
- {
- return Factory.Call(Symbols.RefType, LNode.List(type));
- }
-
- public static LNode NullableType(LNode type)
- {
- return Factory.Call(Symbols.NullableType, LNode.List(type));
- }
-
- public static LNode Signature(LNode name, LNode type, LNodeList args, LNodeList generics)
- {
- return Factory.Call(CodeSymbols.Fn, LNode.List(
- type, name,
- Factory.AltList(args))).PlusAttr(LNode.Call(Symbols.Where, generics));
- }
-
- public static LNode SizeOf(LNode type)
- {
- return Factory.Call(CodeSymbols.Sizeof, LNode.List(type));
- }
-
- public static LNode Struct(Token nameToken, LNodeList inheritances, LNodeList members)
- {
- return Factory.Call(CodeSymbols.Struct,
- LNode.List(
- Factory.FromToken(nameToken),
- Factory.Call(Symbols.Inheritance, inheritances),
- Factory.Call(CodeSymbols.Braces, members).SetStyle(NodeStyle.StatementBlock)));
- }
-
- public static LNode Switch(LNode element, LNodeList cases)
- {
- return Factory.Call(CodeSymbols.SwitchStmt,
- LNode.List(element, LNode.Call(CodeSymbols.Braces, cases).SetStyle(NodeStyle.StatementBlock)));
- }
-
- public static LNode Try(LNode body, LNode catches, LNode finallly)
- {
- return Factory.Call(CodeSymbols.Try, LNode.List(
- body,
- catches,
- Factory.Call(CodeSymbols.Finally, LNode.List(finallly))));
- }
-
- public static LNode Type(string name, LNodeList arguments)
- {
- return Factory.Call(Symbols.TypeLiteral,
- Factory.AltList(Factory.Id(name), Factory.Call(CodeSymbols.Of, arguments)));
- }
-
- public static LNode Unary(Symbol op, LNode arg)
- {
- return Factory.Call(op, LNode.List(arg)).SetStyle(NodeStyle.Operator);
- }
-
- public static LNode Union(string name, LNodeList members)
- {
- return Factory.Call(Symbols.Union, LNode.List(Factory.Id(name)).Add(Factory.AltList(members)));
- }
-
- public static LNode Using(LNode expr)
- {
- if (!expr.Calls(CodeSymbols.As)) // TODO: throw error in intermediate stage when has only one arg
- {
- return Factory.Call(CodeSymbols.UsingStmt, LNode.Missing);
- }
-
- return Factory.Call(CodeSymbols.UsingStmt, LNode.List(expr[0], expr[1]));
- }
-
- public static LNode When(LNode binOp, LNode rightHand, LNode body)
- {
- return Factory.Call(CodeSymbols.When, LNode.List(binOp, rightHand, body));
- }
-
- public static LNode While(LNode cond, LNode body)
- {
- return Factory.Call(
- CodeSymbols.While,
- LNode.List(cond, body));
- }
-
- public static LNode Unit(LNode result, string unit)
- {
- return Factory.Call(Symbols.Unit, LNode.List(result, LNode.Id(unit)));
- }
-
- public static LNode UnitDeclaration(Token nameToken)
- {
- return Factory.Call(Symbols.UnitDecl, LNode.List(Factory.FromToken(nameToken)));
- }
-
- public static LNode TypeOfExpression(LNode type)
- {
- return Factory.Call(CodeSymbols.Typeof, LNode.List(type));
- }
-
- public static LNode DoWhile(LNode body, LNode cond)
- {
- return Factory.Call(CodeSymbols.DoWhile, LNode.List(body, cond));
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/Token.cs b/Source/Backlang.Codeanalysis/Parsing/Token.cs
deleted file mode 100644
index 0f38815b..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/Token.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-namespace Backlang.Codeanalysis.Parsing;
-
-public sealed class Token
-{
- public static Token Invalid = new(TokenType.Invalid);
-
- public Token(TokenType type, string text, int start, int end, int line, int column)
- {
- Type = type;
- Text = text;
- Start = start;
- End = end;
- Line = line;
- Column = column;
- }
-
- public Token(TokenType type)
- {
- Type = type;
- Text = string.Empty;
- }
-
- public Token(TokenType type, string text)
- {
- Type = type;
- Text = text;
- }
-
- public int Column { get; }
- public int End { get; set; }
- public int Line { get; set; }
- public int Start { get; set; }
- public string Text { get; set; }
-
- public TokenType Type { get; set; }
-
- public override string ToString()
- {
- return Text;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/TokenIterator.cs b/Source/Backlang.Codeanalysis/Parsing/TokenIterator.cs
deleted file mode 100644
index b17d1c59..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/TokenIterator.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Backlang.Codeanalysis.Core.Attributes;
-using Loyc.Syntax;
-using System.Reflection;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public sealed class TokenIterator
-{
- private readonly SourceFile _document;
- private readonly List _tokens;
- public readonly List Messages = new();
-
- public TokenIterator(List tokens, SourceFile document)
- {
- _tokens = tokens;
- _document = document;
- }
-
- public Token Current => Peek(0);
- public int Position { get; set; }
- public Token Prev => Peek(-1);
-
- public static string GetTokenRepresentation(TokenType kind)
- {
- var field = kind.GetType().GetField(Enum.GetName(kind));
-
- var lexeme = field.GetCustomAttribute();
- var keyword = field.GetCustomAttribute();
-
- if (lexeme is not null)
- {
- return lexeme.Lexeme;
- }
-
- if (keyword is not null)
- {
- return keyword.Keyword;
- }
-
- return Enum.GetName(kind);
- }
-
- public bool ConsumeIfMatch(TokenType kind)
- {
- var result = false;
- if (IsMatch(kind))
- {
- result = true;
- NextToken();
- }
-
- return result;
- }
-
- public bool IsMatch(TokenType kind)
- {
- return Current.Type == kind;
- }
-
- public bool IsMatch(params TokenType[] kinds)
- {
- var result = false;
- foreach (var kind in kinds)
- {
- result |= IsMatch(kind);
- }
-
- return result;
- }
-
- public Token Match(TokenType kind)
- {
- if (Current.Type == kind)
- {
- return NextToken();
- }
-
- Messages.Add(
- Message.Error(
- new LocalizableString(ErrorID.Expected, GetTokenRepresentation(kind),
- GetTokenRepresentation(Current.Type)),
- new SourceRange(_document, Current.Start, Current.Text.Length)));
-
- NextToken();
-
- return Token.Invalid;
- }
-
- public Token NextToken()
- {
- var current = Current;
- Position++;
- return current;
- }
-
- public Token Peek(int offset)
- {
- var index = Position + offset;
- if (index >= _tokens.Count)
- {
- return _tokens[_tokens.Count - 1];
- }
-
- return _tokens[index];
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/TokenType.cs b/Source/Backlang.Codeanalysis/Parsing/TokenType.cs
deleted file mode 100644
index 707e5998..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/TokenType.cs
+++ /dev/null
@@ -1,260 +0,0 @@
-using Backlang.Codeanalysis.Core.Attributes;
-using Backlang.Codeanalysis.Parsing.Precedences;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public enum TokenType
-{
- Invalid,
- EOF,
- Identifier,
- StringLiteral,
- Number,
- HexNumber,
- BinNumber,
- CharLiteral,
-
- [Lexeme(".")] [BinaryOperatorInfo(BinaryOpPrecedences.Dot)]
- Dot,
-
- [Lexeme("::")] [BinaryOperatorInfo(BinaryOpPrecedences.FunctionCalls)]
- ColonColon,
-
- [BinaryOperatorInfo(BinaryOpPrecedences.DashedOps)] [Lexeme("+")]
- Plus,
-
- [BinaryOperatorInfo(BinaryOpPrecedences.Range)] [Lexeme("..")]
- RangeOperator,
-
- [PreUnaryOperatorInfo(UnaryOpPrecedences.Negate)] [BinaryOperatorInfo(BinaryOpPrecedences.DashedOps)] [Lexeme("-")]
- Minus,
-
- [Lexeme("&")]
- [PreUnaryOperatorInfo(UnaryOpPrecedences.Ampersand)]
- [BinaryOperatorInfo(BinaryOpPrecedences.Ampersand)]
- Ampersand,
-
- [Lexeme("|")] [BinaryOperatorInfo(BinaryOpPrecedences.Ampersand)]
- Pipe,
-
- [Lexeme("~")] [PreUnaryOperatorInfo(UnaryOpPrecedences.LogicalNot)]
- Tilde,
-
- [Lexeme("^")] [BinaryOperatorInfo(BinaryOpPrecedences.Hat)] [PreUnaryOperatorInfo(UnaryOpPrecedences.Hat)]
- Hat,
-
- [BinaryOperatorInfo(BinaryOpPrecedences.DottedOps)] [Lexeme("/")]
- Slash,
-
- [BinaryOperatorInfo(BinaryOpPrecedences.DottedOps)] [PreUnaryOperatorInfo(UnaryOpPrecedences.Hat)] [Lexeme("*")]
- Star,
-
- [PostUnaryOperatorInfo(UnaryOpPrecedences.Negate)] [Lexeme(".*")]
- DotAsterisk, // for namespace imports
-
- [BinaryOperatorInfo(BinaryOpPrecedences.Hat)] [Lexeme("**")]
- StarStar,
-
- [BinaryOperatorInfo(BinaryOpPrecedences.Percent)] [PostUnaryOperatorInfo(UnaryOpPrecedences.Literals)] [Lexeme("%")]
- Percent,
-
- [BinaryOperatorInfo(BinaryOpPrecedences.And)] [Lexeme("and")] [Lexeme("&&")]
- And,
-
- [BinaryOperatorInfo(BinaryOpPrecedences.Or)] [Lexeme("or")] [Lexeme("||")]
- Or,
-
- [PreUnaryOperatorInfo(UnaryOpPrecedences.LogicalNot)] [Lexeme("!")]
- Exclamation,
-
- [Lexeme("*=")]
- [Lexeme("/=")]
- [Lexeme("+=")]
- [Lexeme("-=")]
- [Lexeme("|=")]
- [Lexeme("&=")]
- [Lexeme("!!=")]
- [BinaryOperatorInfo(BinaryOpPrecedences.OperationShortcuts)]
- EqualsShortcutToken,
-
- [Lexeme("=")] [BinaryOperatorInfo(BinaryOpPrecedences.Equals)]
- EqualsToken,
-
- [Lexeme("<=")] [BinaryOperatorInfo(BinaryOpPrecedences.Comparisons)]
- LessThanEqual,
-
- [Lexeme("<")] [BinaryOperatorInfo(BinaryOpPrecedences.Comparisons)]
- LessThan,
-
- [Lexeme(">")] [BinaryOperatorInfo(BinaryOpPrecedences.Comparisons)]
- GreaterThan,
-
- [Lexeme(">=")] [BinaryOperatorInfo(BinaryOpPrecedences.Comparisons)]
- GreaterThanEqual,
-
- [Lexeme(":")] Colon,
-
- [Lexeme("(")] OpenParen,
-
- [Lexeme(")")] CloseParen,
-
- [Lexeme("{")] OpenCurly,
-
- [Lexeme("}")] CloseCurly,
-
- [Lexeme("->")] Arrow,
-
- [Lexeme("=>")] GoesTo,
-
- [Lexeme("|>")] [BinaryOperatorInfo(BinaryOpPrecedences.PipeOperator)]
- PipeOperator,
-
- [Lexeme(",")] Comma,
-
- [Lexeme("$")] [PreUnaryOperatorInfo(UnaryOpPrecedences.Dollar)]
- Dollar,
-
- [Lexeme("?")] [PostUnaryOperatorInfo(UnaryOpPrecedences.Negate)]
- Questionmark,
-
- [Lexeme("==")] [BinaryOperatorInfo(BinaryOpPrecedences.EqualsEquals)]
- EqualsEquals,
-
- [Lexeme("!=")] [BinaryOperatorInfo(BinaryOpPrecedences.EqualsEquals)]
- NotEquals,
-
- [Lexeme("<->")] [BinaryOperatorInfo(BinaryOpPrecedences.SwapOperator)]
- SwapOperator,
-
- [Lexeme("_")] Underscore,
-
- [Lexeme(";")] Semicolon,
-
- [Lexeme("[")] OpenSquare,
-
- [Lexeme("]")] CloseSquare,
-
- [Lexeme("@")] At,
-
- [Lexeme("as")] [BinaryOperatorInfo(BinaryOpPrecedences.Casting)]
- As,
-
- [Keyword("true")] TrueLiteral,
-
- [Keyword("false")] FalseLiteral,
-
- [Keyword("type")] Type,
-
- [Keyword("func")] Function,
-
- [Keyword("constructor")] Constructor,
-
- [Keyword("destructor")] Destructor,
-
- [Keyword("macro")] Macro,
-
- [Keyword("let")] Let,
-
- [Keyword("prop")] Property,
-
- [Keyword("mut")] Mutable,
-
- [Keyword("enum")] Enum,
-
- [Keyword("try")] Try,
-
- [Keyword("catch")] Catch,
-
- [Keyword("finally")] Finally,
-
- [Keyword("with")] With,
-
- [Keyword("match")] Match,
-
- [Keyword("struct")] Struct,
-
- [Keyword("class")] Class,
-
- [Keyword("interface")] Interface,
-
- [Keyword("bitfield")] Bitfield,
-
- [Keyword("default")] Default,
-
- [Keyword("sizeof")] SizeOf,
-
- [Keyword("typeof")] TypeOf,
-
- [Keyword("none")] None,
-
- [Keyword("get")] Get,
-
- [Keyword("set")] Set,
-
- [Keyword("init")] Init,
-
- [Keyword("switch")] Switch,
-
- [Keyword("case")] Case,
-
- [Keyword("break")] Break,
-
- [Keyword("continue")] Continue,
-
- [Keyword("return")] Return,
-
- [Keyword("when")] When,
-
- [Keyword("where")] Where,
-
- [Keyword("if")] If,
-
- [Keyword("else")] Else,
-
- [Keyword("while")] While,
-
- [Keyword("do")] Do,
-
- [Keyword("in")] In,
-
- [Keyword("for")] For,
-
- [Keyword("const")] Const,
-
- [Keyword("global")] Global,
-
- [Keyword("static")] Static,
-
- [Keyword("abstract")] Abstract,
-
- [Keyword("extern")] Extern,
-
- [Keyword("override")] Override,
-
- [Keyword("of")] Of,
-
- [Keyword("implement")] Implement,
-
- [Keyword("operator")] Operator,
-
- [Keyword("public")] Public,
-
- [Keyword("internal")] Internal,
-
- [Keyword("protected")] Protected,
-
- [Keyword("private")] Private,
-
- [Keyword("import")] Import,
-
- [Keyword("module")] Module,
-
- [Keyword("using")] Using,
-
- [Keyword("union")] Union,
-
- [Keyword("throw")] Throw,
-
- [Keyword("unit")] Unit,
- DocComment
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Parsing/TokenUtils.cs b/Source/Backlang.Codeanalysis/Parsing/TokenUtils.cs
deleted file mode 100644
index 7d382b25..00000000
--- a/Source/Backlang.Codeanalysis/Parsing/TokenUtils.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-using Backlang.Codeanalysis.Core.Attributes;
-using System.Reflection;
-
-namespace Backlang.Codeanalysis.Parsing;
-
-public static class TokenUtils
-{
- private static readonly Dictionary TokenTypeRepresentations = new(StringComparer.Ordinal);
-
- static TokenUtils()
- {
- var typeValues = (TokenType[])Enum.GetValues(typeof(TokenType));
-
- foreach (var keyword in typeValues)
- {
- var attributes = keyword.GetType().GetField(Enum.GetName(keyword))
- .GetCustomAttributes(true);
-
- if (attributes != null && attributes.Any())
- {
- foreach (var attribute in attributes)
- {
- TokenTypeRepresentations.Add(attribute.Keyword, keyword);
- }
- }
- }
- }
-
- public static TokenType GetTokenType(string text)
- {
- if (TokenTypeRepresentations.ContainsKey(text))
- {
- return TokenTypeRepresentations[text];
- }
-
- return TokenType.Identifier;
- }
-
- public static bool IsOperator(this Token token)
- {
- //var op = token.Type;
- //var attributes = op.GetType().GetField(Enum.GetName(op)).GetCustomAttributes(true);
- //return attributes != null && attributes.Any();
- if (Expression.BinaryOperators.ContainsKey(token.Type))
- {
- return true;
- }
-
- if (Expression.PreUnaryOperators.ContainsKey(token.Type))
- {
- return true;
- }
-
- return Expression.PostUnaryOperators.ContainsKey(token.Type);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Codeanalysis/Properties/Resources.Designer.cs b/Source/Backlang.Codeanalysis/Properties/Resources.Designer.cs
deleted file mode 100644
index 3d543149..00000000
--- a/Source/Backlang.Codeanalysis/Properties/Resources.Designer.cs
+++ /dev/null
@@ -1,350 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// This code was generated by a tool.
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-//
-//------------------------------------------------------------------------------
-
-namespace Backlang.Codeanalysis.Properties {
- using System;
-
-
- ///
- /// A strongly-typed resource class, for looking up localized strings, etc.
- ///
- // This class was auto-generated by the StronglyTypedResourceBuilder
- // class via a tool like ResGen or Visual Studio.
- // To add or remove a member, edit your .ResX file then rerun ResGen
- // with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Resources {
-
- private static global::System.Resources.ResourceManager resourceMan;
-
- private static global::System.Globalization.CultureInfo resourceCulture;
-
- [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Resources() {
- }
-
- ///
- /// Returns the cached ResourceManager instance used by this class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager {
- get {
- if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Backlang.Codeanalysis.Properties.Resources", typeof(Resources).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
- }
- }
-
- ///
- /// Overrides the current thread's CurrentUICulture property for all
- /// resource lookups using this strongly typed resource class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture {
- get {
- return resourceCulture;
- }
- set {
- resourceCulture = value;
- }
- }
-
- ///
- /// Looks up a localized string similar to Expected Identifier, TupleType or Function-Signature as TypeLiteral, but got {0}.
- ///
- internal static string BL_0001_ {
- get {
- return ResourceManager.GetString("BL(0001)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Invalid Modifier Combination.
- ///
- internal static string BL_0002_ {
- get {
- return ResourceManager.GetString("BL(0002)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Unknown Character '{0}'.
- ///
- internal static string BL_0003_ {
- get {
- return ResourceManager.GetString("BL(0003)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Unterminated Char-Literal.
- ///
- internal static string BL_0004_ {
- get {
- return ResourceManager.GetString("BL(0004)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Unexpected Expression {0}.
- ///
- internal static string BL_0005_ {
- get {
- return ResourceManager.GetString("BL(0005)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Unknown Literal {0}.
- ///
- internal static string BL_0006_ {
- get {
- return ResourceManager.GetString("BL(0006)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Trailing comma is forbidden.
- ///
- internal static string BL_0007_ {
- get {
- return ResourceManager.GetString("BL(0007)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Bitfield member declaration only allows literals.
- ///
- internal static string BL_0008_ {
- get {
- return ResourceManager.GetString("BL(0008)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Expected Function, Property or Field-declaration for Type, but got {0}.
- ///
- internal static string BL_0009_ {
- get {
- return ResourceManager.GetString("BL(0009)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Expected Type but got {0}.
- ///
- internal static string BL_0010_ {
- get {
- return ResourceManager.GetString("BL(0010)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Unexpected Switch Option.
- ///
- internal static string BL_0011_ {
- get {
- return ResourceManager.GetString("BL(0011)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Expected at least one catch block.
- ///
- internal static string BL_0012_ {
- get {
- return ResourceManager.GetString("BL(0012)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to SourceFile is empty.
- ///
- internal static string BL_0013_ {
- get {
- return ResourceManager.GetString("BL(0013)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Expected Identifier but got {0}.
- ///
- internal static string BL_0014_ {
- get {
- return ResourceManager.GetString("BL(0014)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Unterminated String-Literal.
- ///
- internal static string BL_0015_ {
- get {
- return ResourceManager.GetString("BL(0015)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Multiline comment is not closed.
- ///
- internal static string BL_0016_ {
- get {
- return ResourceManager.GetString("BL(0016)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Expected '{0}' but got '{1}'.
- ///
- internal static string BL_0017_ {
- get {
- return ResourceManager.GetString("BL(0017)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Duplicate Modifier '{0}'.
- ///
- internal static string BL_0018_ {
- get {
- return ResourceManager.GetString("BL(0018)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Namespace '{0}' already imported.
- ///
- internal static string BL_0019_ {
- get {
- return ResourceManager.GetString("BL(0019)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Got OutputType 'Exe' but couldn't find entry point..
- ///
- internal static string BL_0020_ {
- get {
- return ResourceManager.GetString("BL(0020)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to {0} cannot be found. Did you mean '{1}'?.
- ///
- internal static string BL_0021_ {
- get {
- return ResourceManager.GetString("BL(0021)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Cannot implement '{0}', type not found.
- ///
- internal static string BL_0022_ {
- get {
- return ResourceManager.GetString("BL(0022)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Cannot implement unit type '{0}'.
- ///
- internal static string BL_0023_ {
- get {
- return ResourceManager.GetString("BL(0023)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to '{0}' already declared.
- ///
- internal static string BL_0024_ {
- get {
- return ResourceManager.GetString("BL(0024)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Type mismatch {0} {1}.
- ///
- internal static string BL_0025_ {
- get {
- return ResourceManager.GetString("BL(0025)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Unit Type mismatch {0} {1}.
- ///
- internal static string BL_0026_ {
- get {
- return ResourceManager.GetString("BL(0026)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to {0} cannot be resolved.
- ///
- internal static string BL_0027_ {
- get {
- return ResourceManager.GetString("BL(0027)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Cannot find function '{0}'.
- ///
- internal static string BL_0028_ {
- get {
- return ResourceManager.GetString("BL(0028)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Target '{0}' cannot be found.
- ///
- internal static string BL_0029_ {
- get {
- return ResourceManager.GetString("BL(0029)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Identifier '{0}' is not defined.
- ///
- internal static string BL_0030_ {
- get {
- return ResourceManager.GetString("BL(0030)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Cannot set type.
- ///
- internal static string BL_0031_ {
- get {
- return ResourceManager.GetString("BL(0031)", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Cannot deduce Type. Declare it manually!.
- ///
- internal static string BL_0032_ {
- get {
- return ResourceManager.GetString("BL(0032)", resourceCulture);
- }
- }
- }
-}
diff --git a/Source/Backlang.Codeanalysis/Properties/Resources.resx b/Source/Backlang.Codeanalysis/Properties/Resources.resx
deleted file mode 100644
index e2246f82..00000000
--- a/Source/Backlang.Codeanalysis/Properties/Resources.resx
+++ /dev/null
@@ -1,221 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
- PublicKeyToken=b77a5c561934e089
-
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
- PublicKeyToken=b77a5c561934e089
-
-
-
- Expected Identifier, TupleType or Function-Signature as TypeLiteral, but got {0}
-
-
- Invalid Modifier Combination
-
-
- Unknown Character '{0}'
-
-
- Unterminated Char-Literal
-
-
- Unexpected Expression {0}
-
-
- Unknown Literal {0}
-
-
- Trailing comma is forbidden
-
-
- Bitfield member declaration only allows literals
-
-
- Expected Function, Property or Field-declaration for Type, but got {0}
-
-
- Expected Type but got {0}
-
-
- Unexpected Switch Option
-
-
- Expected at least one catch block
-
-
- SourceFile is empty
-
-
- Expected Identifier but got {0}
-
-
- Unterminated String-Literal
-
-
- Multiline comment is not closed
-
-
- Expected '{0}' but got '{1}'
-
-
- Duplicate Modifier '{0}'
-
-
- Namespace '{0}' already imported
-
-
- Got OutputType 'Exe' but couldn't find entry point.
-
-
- {0} cannot be found. Did you mean '{1}'?
-
-
- Cannot implement '{0}', type not found
-
-
- Cannot implement unit type '{0}'
-
-
- '{0}' already declared
-
-
- Type mismatch {0} {1}
-
-
- Unit Type mismatch {0} {1}
-
-
- {0} cannot be resolved
-
-
- Cannot find function '{0}'
-
-
- Target '{0}' cannot be found
-
-
- Identifier '{0}' is not defined
-
-
- Cannot set type
-
-
- Cannot deduce Type. Declare it manually!
-
-
\ No newline at end of file
diff --git a/Source/Backlang.Contracts/ISemanticCheck.cs b/Source/Backlang.Contracts/ISemanticCheck.cs
deleted file mode 100644
index e38754f2..00000000
--- a/Source/Backlang.Contracts/ISemanticCheck.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-using Backlang.Contracts;
-
-namespace Backlang.Codeanalysis.Core;
-
-public interface ISemanticCheck
-{
- void Check(CompilationUnit tree, CompilerContext context);
-}
\ No newline at end of file
diff --git a/Source/Backlang.Contracts/Semantic/VariableTypeCheck.cs b/Source/Backlang.Contracts/Semantic/VariableTypeCheck.cs
deleted file mode 100644
index 302bec52..00000000
--- a/Source/Backlang.Contracts/Semantic/VariableTypeCheck.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Backlang.Driver;
-
-namespace Backlang.Contracts.Semantic;
-
-internal class VariableTypeCheck : ISemanticCheck
-{
- public void Check(CompilationUnit tree, CompilerContext context)
- {
- var letNodes = tree.Body.SelectMany(_ => _.Descendants()).Where(_ => _.Calls(CodeSymbols.Var)).ToArray();
-
- foreach (var node in letNodes)
- {
- if (node is var (_, (_, (_, type)), (_, _, value)))
- {
- if (type.Name.Name == "" && value.Calls(CodeSymbols.Void))
- {
- context.AddError(node, ErrorID.CannotDeduceType);
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Contracts/SemanticChecker.cs b/Source/Backlang.Contracts/SemanticChecker.cs
deleted file mode 100644
index 781ed0bc..00000000
--- a/Source/Backlang.Contracts/SemanticChecker.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using Backlang.Codeanalysis.Core;
-using Backlang.Contracts.Semantic;
-
-namespace Backlang.Contracts;
-
-public static class SemanticChecker
-{
- private static readonly List _semanticChecks = new()
- {
- new ModuleDefinitionCheck(),
- new ImportCheck(),
- new TypenameCheck(),
- new VariableTypeCheck(),
- new ModifierCheck(),
- new InterfaceNameCheck()
- };
-
- public static void Do(CompilationUnit tree, CompilerContext context)
- {
- foreach (var check in _semanticChecks)
- {
- check.Check(tree, context);
- }
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Core/Backlang.Core.csproj b/Source/Backlang.Core/Backlang.Core.csproj
deleted file mode 100644
index f6e4fbc0..00000000
--- a/Source/Backlang.Core/Backlang.Core.csproj
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
- net9.0
- enable
- True
- Furesoft, Backlang-Org
- https://www.backlang-org/
- logo.png
- https://github.com/Backlang-Org/Backlang
- backlang
- True
-
-
-
-
-
-
-
-
- True
- \
-
-
-
-
-
diff --git a/Source/Backlang.Core/CompilerService/MacroLibAttribute.cs b/Source/Backlang.Core/CompilerService/MacroLibAttribute.cs
deleted file mode 100644
index 220b8d34..00000000
--- a/Source/Backlang.Core/CompilerService/MacroLibAttribute.cs
+++ /dev/null
@@ -1,5 +0,0 @@
-namespace Backlang.Core.CompilerService;
-
-public class MacroLibAttribute : Attribute
-{
-}
\ No newline at end of file
diff --git a/Source/Backlang.Core/CompilerService/UnitAttribute.cs b/Source/Backlang.Core/CompilerService/UnitAttribute.cs
deleted file mode 100644
index 977a6872..00000000
--- a/Source/Backlang.Core/CompilerService/UnitAttribute.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace Backlang.Core.CompilerService;
-
-[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.ReturnValue)]
-public class UnitAttribute : Attribute
-{
- public Type UnitType { get; set; }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Core/CompilerService/UnitTypeAttribute.cs b/Source/Backlang.Core/CompilerService/UnitTypeAttribute.cs
deleted file mode 100644
index 5addc853..00000000
--- a/Source/Backlang.Core/CompilerService/UnitTypeAttribute.cs
+++ /dev/null
@@ -1,6 +0,0 @@
-namespace Backlang.Core.CompilerService;
-
-[AttributeUsage(AttributeTargets.Class)]
-public class UnitTypeAttribute : Attribute
-{
-}
\ No newline at end of file
diff --git a/Source/Backlang.Core/Macros/BuiltInMacros.cs b/Source/Backlang.Core/Macros/BuiltInMacros.cs
deleted file mode 100644
index 03862fb9..00000000
--- a/Source/Backlang.Core/Macros/BuiltInMacros.cs
+++ /dev/null
@@ -1,167 +0,0 @@
-using LeMP;
-using Loyc;
-using Loyc.Syntax;
-using System.Text;
-
-namespace Backlang.Core.Macros;
-
-[ContainsMacros]
-public static partial class BuiltInMacros
-{
- private static readonly LNodeFactory F = new(EmptySourceFile.Synthetic);
-
- [LexicalMacro("todo", "Add hint to do something", "todo")]
- public static LNode Todo(LNode node, IMacroContext context)
- {
- if (node.ArgCount == 1)
- {
- var msg = node.Args[0].Args[0];
- context.Warn(msg.Value.ToString());
- }
- else
- {
- context.Error("The ToDo macro needs a message");
- }
-
- return LNode.Missing;
- }
-
- [LexicalMacro("notimplemented", "Semantic info for functionality that is not implemented", "notimplemented")]
- public static LNode NotImplemented(LNode node, IMacroContext context)
- {
- return LNode.Missing;
- }
-
- [LexicalMacro("refactor", "Semantic info for functionality that needs to be refactored", "refactor")]
- public static LNode Refactor(LNode node, IMacroContext context)
- {
- return LNode.Missing;
- }
-
- [LexicalMacro(@"nameof(id_or_expr)",
- @"Converts the 'key' name component of an expression to a string (e.g. nameof(A.B(D)) == ""B"")", "nameof",
- Mode = MacroMode.MatchIdentifierOrCall)]
- public static LNode Nameof(LNode nameof, IMacroContext context)
- {
- if (nameof.ArgCount != 1)
- {
- return null;
- }
-
- var arg = nameof.Args[0];
- if (arg.IsCall)
- {
- if (arg.Name == (Symbol)".")
- {
- if (arg.Args[1].IsCall)
- {
- return F.Literal(arg.Args[1].Name);
- }
-
- return arg.Args[1];
- }
-
- if (arg.Name == (Symbol)"::")
- {
- if (arg.Args[1].IsCall)
- {
- return F.Literal(arg.Args[1].Name);
- }
-
- return arg.Args[1];
- }
-
- if (arg.Target.IsId)
- {
- return arg.Target;
- }
- }
-
- return arg;
- }
-
- [LexicalMacro("concatId(id, id)", "Concats 2 Ids to a new Id (eg. concatId(a, b) == ab)", "concatId",
- Mode = MacroMode.MatchIdentifierOrCall)]
- public static LNode concatId(LNode concatID, IMacroContext context)
- {
- if (concatID.ArgCount < 2)
- {
- return null;
- }
-
- var sb = new StringBuilder();
-
- foreach (var arg in concatID.Args)
- {
- if (arg.IsId)
- {
- sb.Append(arg.Name.Name);
- }
- else
- {
- context.Sink.Warning(arg, "Argument is not an Id");
- }
- }
-
- return F.Id(sb.ToString());
- }
-
- [LexicalMacro("$variableName",
- "Expands a variable (scoped property) assigned by a macro such as `static deconstruct()` or `static tryDeconstruct()`.",
- "'$", Mode = MacroMode.Passive)]
- public static LNode DollarSignVariable(LNode node, IMacroContext context)
- {
- LNode id;
- if (node.ArgCount == 1 && (id = node.Args[0]).IsId && !id.HasPAttrs())
- {
- object value;
- if (context.ScopedProperties.TryGetValue("$" + id.Name.Name, out value))
- {
- if (value is LNode)
- {
- return ((LNode)value).WithRange(id.Range);
- }
-
- context.Sink.Warning(id, "The specified scoped property is not a syntax tree. " +
- "Use `#getScopedProperty({0})` to insert it as a literal.", id.Name);
- }
- else
- {
- context.Sink.Error(id, "There is no macro property in scope named `{0}`", id.Name);
- }
- }
-
- return null;
- }
-
- [LexicalMacro("left <-> right", "Swaps the values of the two variables", "'<->",
- Mode = MacroMode.MatchIdentifierOrCall)]
- public static LNode Swap(LNode node, IMacroContext context)
- {
- var left = node.Args[0];
- var right = node.Args[1];
- var temp = GenerateId(null, context);
-
- return LNode.Call(CodeSymbols.Braces, LNode.List(
- LNode.Call(CodeSymbols.Var,
- LNode.List(LNode.Missing, LNode.Call(CodeSymbols.Assign, LNode.List(temp, left)))),
- LNode.Call(CodeSymbols.Assign, LNode.List(left, right)),
- LNode.Call(CodeSymbols.Assign, LNode.List(right, temp))
- )).SetStyle(NodeStyle.StatementBlock);
- }
-
- [LexicalMacro("generateId()", "Generates a new Id (eg. generateId() == a0)", "generateId",
- Mode = MacroMode.MatchIdentifierOrCall)]
- public static LNode GenerateId(LNode generateID, IMacroContext context)
- {
- var alphabet = "abcdefghijklmnopqrstuvwxyz_";
-
- var sb = new StringBuilder();
- for (var i = 0; i < 3; i++)
- {
- sb.Append(Random.Shared.Next(0, alphabet.Length));
- }
-
- return F.Id("_" + sb + context.IncrementTempCounter());
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Core/Macros/QuoteMacro.cs b/Source/Backlang.Core/Macros/QuoteMacro.cs
deleted file mode 100644
index 5e885ccb..00000000
--- a/Source/Backlang.Core/Macros/QuoteMacro.cs
+++ /dev/null
@@ -1,309 +0,0 @@
-using LeMP;
-using Loyc;
-using Loyc.Syntax;
-using System.Reflection;
-using S = Loyc.Syntax.CodeSymbols;
-
-namespace Backlang.Core.Macros;
-
-public partial class BuiltInMacros
-{
- private static readonly LNode _CodeSymbols = F.Id("CodeSymbols");
-
- private static Dictionary CodeSymbolTable;
-
- [LexicalMacro("quote(code); quote { code(); }",
- "Macro-based code quote mechanism, to be used as long as a more complete compiler is not availabe. " +
- "If there is a single parameter that is braces, the braces are stripped out. " +
- "If there are multiple parameters, or multiple statements in braces, the result is a call to #splice(). " +
- "The output refers unqualified to `CodeSymbols` and `LNode` so you must have 'using Loyc.Syntax' at the top of your file. " +
- "The substitution operator $(expr) causes the specified expression to be inserted unchanged into the output.",
- "quote", "#quote")]
- public static LNode Quote(LNode node, IMessageSink sink)
- {
- return Quote(node, true, true);
- }
-
- ///
- /// This implements `quote` and related macros. It converts a
- /// Loyc tree (e.g. `Foo(this)`) into a piece of .NET code that can
- /// construct the essence of the same tree (e.g.
- /// `LNode.Call((Symbol) "Foo", LNode.List(LNode.Id(CodeSymbols.This)));`),
- /// although this code does not preserve the Range properties.
- ///
- /// If this flag is true, when a calls to
- /// @`'$` is encountered, it is treated as a substitution request,
- /// e.g. $node causes node to be included unchanged in the
- /// output, and by example, Foo($x, $(..list)) produces this tree:
- /// LNode.Call((Symbol) "Foo", LNode.List().Add(x).AddRange(list)).
- ///
- ///
- /// If this flag is true, the output expression
- /// does not construct trivia attributes.
- ///
- /// The quoted form.
- public static LNode Quote(LNode node, bool allowSubstitutions, bool ignoreTrivia)
- {
- LNode code = node, arg;
- if (code.ArgCount == 1 && (arg = code.Args[0]).Calls(S.Braces) && !arg.HasPAttrs())
- {
- // Braces are needed to allow statement syntax in EC#; they are
- // not necessarily desired in the output, so ignore them. The user
- // can still write quote {{...}} to include braces in the output.
- code = arg;
- }
-
- return new CodeQuoter(allowSubstitutions, ignoreTrivia).Quote(code.Args.AsLNode(S.Splice));
- }
-
- [LexicalMacro(
- @"e.g. quoteWithTrivia(/* cool! */ $foo) ==> foo.PlusAttrs(LNode.List(LNode.Trivia(CodeSymbols.TriviaMLComment, "" cool! "")))",
- "Behaves the same as quote(code) except that trivia is included in the output.")]
- public static LNode QuoteWithTrivia(LNode node, IMessageSink sink)
- {
- return Quote(node, true, false);
- }
-
- [LexicalMacro(@"e.g. rawQuote($foo) ==> F.Call(CodeSymbols.Substitute, F.Id(""foo""));",
- "Behaves the same as quote(code) except that the substitution operator $ is not recognized as a request for substitution.",
- "rawQuote", "#rawQuote")]
- public static LNode RawQuote(LNode node, IMessageSink sink)
- {
- return Quote(node, false, true);
- }
-
- [LexicalMacro(
- @"e.g. rawQuoteWithTrivia(/* cool! */ $foo) ==> LNode.Call(LNode.List(LNode.Trivia(CodeSymbols.TriviaMLComment, "" cool! "")), CodeSymbols.Substitute, LNode.List(LNode.Id((Symbol) ""foo"")))",
- "Behaves the same as rawQuote(code) except that trivia is included in the output.")]
- public static LNode RawQuoteWithTrivia(LNode node, IMessageSink sink)
- {
- return Quote(node, false, false);
- }
-
- internal static LNode QuoteSymbol(Symbol name)
- {
- if (CodeSymbolTable == null)
- {
- CodeSymbolTable = FindStaticReadOnlies(typeof(CodeSymbols), fInfo => !fInfo.Name.StartsWith("_"));
- }
-
- if (CodeSymbolTable.TryGetValue(name, out var field))
- {
- return F.Dot(_CodeSymbols, F.Id(field));
- }
-
- return F.Call(S.Cast, F.Literal(name.Name), F.Id("Symbol"));
- }
-
- ///
- /// Helper function that finds the static readonly fields of a given
- /// type in a given class, and creates a table from the _values_ of those
- /// fields to the _names_ of those fields.
- ///
- private static Dictionary FindStaticReadOnlies(Type type, Predicate filter = null)
- {
- var dict = new Dictionary();
- var list = type.GetFields(BindingFlags.Static | BindingFlags.Public)
- .Where(field => typeof(T).IsAssignableFrom(field.FieldType) && field.IsInitOnly
- && field.GetCustomAttributes(
- typeof(ObsoleteAttribute), true).Length ==
- 0);
- foreach (var field in list)
- {
- if (filter == null || filter(field))
- {
- dict[(T)field.GetValue(null)] = GSymbol.Get(field.Name);
- }
- }
-
- return dict;
- }
-
- public class CodeQuoter
- {
- private static readonly LNode CodeSymbols_Splice = F.Dot(_CodeSymbols, F.Id("Splice"));
-
- private static readonly LNode Id_LNode = F.Id("LNode");
-
- private static readonly LNode Id_PlusAttrs = F.Id("PlusAttrs");
-
- private static readonly LNode LNode_Braces = F.Dot(Id_LNode, F.Id("Braces"));
-
- private static readonly LNode LNode_Call = F.Dot(Id_LNode, F.Id("Call"));
-
- private static readonly LNode LNode_Dot = F.Dot(Id_LNode, F.Id("Dot"));
-
- private static readonly LNode LNode_Id = F.Dot(Id_LNode, F.Id("Id"));
-
- private static readonly LNode LNode_InParensTrivia = F.Dot(Id_LNode, F.Id("InParensTrivia"));
-
- private static readonly LNode LNode_List = F.Dot(Id_LNode, F.Id("List"));
-
- private static readonly LNode LNode_Literal = F.Dot(Id_LNode, F.Id("Literal"));
-
- private static readonly LNode LNode_Missing = F.Dot(Id_LNode, F.Id("Missing"));
-
- private static readonly LNode LNode_Trivia = F.Dot(Id_LNode, F.Id("Trivia"));
- public bool _doSubstitutions;
- public bool _ignoreTrivia;
-
- public CodeQuoter(
- bool doSubstitutions,
- bool ignoreTrivia = true)
- {
- _doSubstitutions = doSubstitutions;
- _ignoreTrivia = ignoreTrivia;
- }
-
- public LNode Quote(LNode node)
- {
- if (node.Equals(LNode.InParensTrivia))
- {
- return LNode_InParensTrivia;
- }
-
- if (node.Equals(LNode.Missing))
- {
- return LNode_Missing;
- }
-
- var creationArgs = new LNodeList();
-
- // Translate attributes (if any)
- var attrList = MaybeQuoteList(node.Attrs, true);
- if (attrList != null)
- {
- creationArgs.Add(attrList);
- }
-
- LNode result;
- switch (node.Kind)
- {
- case LNodeKind.Literal: // => F.Literal(value)
- creationArgs.Add(node.WithoutAttrs());
- result = F.Call(LNode_Literal, creationArgs);
- break;
-
- case LNodeKind.Id: // => F.Id(string), F.Id(CodeSymbols.Name)
- creationArgs.Add(QuoteSymbol(node.Name));
- result = F.Call(LNode_Id, creationArgs);
- break;
-
- default: // NodeKind.Call => F.Dot(...), F.Of(...), F.Call(...), F.Braces(...)
- var preserveStyle = true;
- if (_doSubstitutions && node.Calls(S.Substitute, 1))
- {
- preserveStyle = false;
- result = node.Args[0];
- if (attrList != null)
- {
- if (result.IsCall)
- {
- result = result.InParens();
- }
-
- result = F.Call(F.Dot(result, Id_PlusAttrs), attrList);
- }
- }
- else if (!_ignoreTrivia && node.ArgCount == 1 && node.TriviaValue != NoValue.Value &&
- node.Target.IsId)
- {
- // LNode.Trivia(Symbol, object)
- result = F.Call(LNode_Trivia, QuoteSymbol(node.Name), F.Literal(node.TriviaValue));
- }
- /*else if (node.Calls(S.Braces)) // F.Braces(...)
- result = F.Call(LNode_Braces, node.Args.SmartSelect(arg => QuoteOne(arg, substitutions)));
- else if (node.Calls(S.Dot) && node.ArgCount.IsInRange(1, 2))
- result = F.Call(LNode_Dot, node.Args.SmartSelect(arg => QuoteOne(arg, substitutions)));
- else if (node.Calls(S.Of))
- result = F.Call(LNode_Of, node.Args.SmartSelect(arg => QuoteOne(arg, substitutions)));*/
- else
- {
- // General case: F.Call(, )
- if (node.Target.IsId)
- {
- creationArgs.Add(QuoteSymbol(node.Name));
- }
- else
- {
- creationArgs.Add(Quote(node.Target));
- }
-
- var argList = MaybeQuoteList(node.Args);
- if (argList != null)
- {
- creationArgs.Add(argList);
- }
-
- result = F.Call(LNode_Call, creationArgs);
- }
-
- // Note: don't preserve prefix notation because if $op is +,
- // we want $op(x, y) to generate code for x + y (there is no
- // way to express this with infix notation.)
- if (preserveStyle && node.BaseStyle != NodeStyle.Default &&
- node.BaseStyle != NodeStyle.PrefixNotation)
- {
- result = F.Call(F.Dot(result, F.Id("SetStyle")),
- F.Dot(F.Id("NodeStyle"), F.Id(node.BaseStyle.ToString())));
- }
-
- break;
- }
-
- return result;
- }
-
- private static LNode VarArgExpr(LNode arg)
- {
- LNode subj;
- if (arg.Calls(S.Substitute, 1) && ((subj = arg.Args[0]).Calls(S.DotDot, 1) || subj.Calls(S.DotDotDot, 1)))
- {
- return subj.Args[0];
- }
-
- return null;
- }
-
- private LNode MaybeQuoteList(LNodeList list, bool isAttributes = false)
- {
- if (isAttributes && _ignoreTrivia)
- {
- list = list.SmartWhere(n => !n.IsTrivia || n.IsIdNamed(S.TriviaInParens));
- }
-
- if (list.IsEmpty)
- {
- return null;
- }
-
- if (_doSubstitutions && list.Any(a => VarArgExpr(a) != null))
- {
- if (list.Count == 1)
- {
- return F.Call(LNode_List, VarArgExpr(list[0]));
- }
-
- // If you write something like quote(Foo($x, $(...y), $z)), a special
- // output style is used to accommodate the variable argument list.
- var argList = F.Call(LNode_List);
- foreach (var arg in list)
- {
- var vae = VarArgExpr(arg);
- if (vae != null)
- {
- argList = F.Call(F.Dot(argList, F.Id("AddRange")), vae);
- }
- else
- {
- argList = F.Call(F.Dot(argList, F.Id("Add")), Quote(arg));
- }
- }
-
- return argList;
- }
-
- return F.Call(LNode_List, list.SmartSelect(item => Quote(item)));
- }
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Core/Result.cs b/Source/Backlang.Core/Result.cs
deleted file mode 100644
index dd073c25..00000000
--- a/Source/Backlang.Core/Result.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System.Runtime.CompilerServices;
-
-namespace Backlang.Core;
-
-public class Result
-{
- private readonly T? _value;
-
- public Result(T value)
- {
- _value = value;
- }
-
- public static implicit operator T(Result value)
- {
- return value._value;
- }
-
- //Unpacking operator
- [SpecialName]
- public static bool op_Unpacking(Result value)
- {
- return value._value != null;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Core/Sealed.cs b/Source/Backlang.Core/Sealed.cs
deleted file mode 100644
index ecca4c70..00000000
--- a/Source/Backlang.Core/Sealed.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using System.Runtime.CompilerServices;
-
-namespace Backlang.Core;
-
-public struct Sealed
-{
- private T _value;
-
- public bool IsFreezed { get; private set; }
-
- public static implicit operator Sealed(T value)
- {
- return new Sealed { _value = value, IsFreezed = true };
- }
-
- public static implicit operator T(Sealed @sealed)
- {
- return @sealed._value;
- }
-
- public void Set(T value)
- {
- if (IsFreezed)
- {
- throw new InvalidOperationException("Object is freezed");
- }
-
- _value = value;
- }
-
- public void Freeze()
- {
- IsFreezed = true;
- }
-
- public void Unfreeze()
- {
- IsFreezed = false;
- }
-
- //Unpacking operator
- [SpecialName]
- public static T op_Unpacking(Sealed value)
- {
- return value._value;
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Core/logo.png b/Source/Backlang.Core/logo.png
deleted file mode 100644
index 557ebd34..00000000
Binary files a/Source/Backlang.Core/logo.png and /dev/null differ
diff --git a/Source/Backlang.Driver/Compiling/Stages/ParsingStage.cs b/Source/Backlang.Driver/Compiling/Stages/ParsingStage.cs
deleted file mode 100644
index 5c09bffc..00000000
--- a/Source/Backlang.Driver/Compiling/Stages/ParsingStage.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using Flo;
-
-namespace Backlang.Driver.Compiling.Stages;
-
-public sealed class ParsingStage : IHandler
-{
- public async Task HandleAsync(CompilerContext context,
- Func> next)
- {
- if (context.Playground.IsPlayground)
- {
- var tree = CompilationUnit.FromText(context.Playground.Source);
-
- ApplyTree(context, tree);
-
- return await next.Invoke(context);
- }
-
- ParseSourceFiles(context);
-
- return await next.Invoke(context);
- }
-
- private static void ParseSourceFiles(CompilerContext context)
- {
- Parallel.ForEachAsync(context.Options.InputFiles, (filename, ct) => {
- if (File.Exists(filename))
- {
- var tree = CompilationUnit.FromFile(filename);
-
- ApplyTree(context, tree);
- }
- else
- {
- context.Messages.Add(Message.Error($"File '{filename}' does not exists", SourceRange.Synthetic));
- }
-
- return ValueTask.CompletedTask;
- }).Wait();
- }
-
- private static void ApplyTree(CompilerContext context, CompilationUnit tree)
- {
- context.Trees.Add(tree);
-
- context.Messages.AddRange(tree.Messages);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.Driver/Compiling/Stages/SemanticCheckStage.cs b/Source/Backlang.Driver/Compiling/Stages/SemanticCheckStage.cs
deleted file mode 100644
index 29191871..00000000
--- a/Source/Backlang.Driver/Compiling/Stages/SemanticCheckStage.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Flo;
-
-namespace Backlang.Driver.Compiling.Stages;
-
-public sealed class SemanticCheckStage : IHandler
-{
- public async Task HandleAsync(CompilerContext context,
- Func> next)
- {
- Parallel.ForEachAsync(context.Trees, (tree, ct) => {
- SemanticChecker.Do(tree, context);
-
- return ValueTask.CompletedTask;
- }).Wait();
-
- return await next.Invoke(context);
- }
-}
\ No newline at end of file
diff --git a/Source/Backlang.WasmBridge/Backlang.WasmBridge.csproj b/Source/Backlang.WasmBridge/Backlang.WasmBridge.csproj
deleted file mode 100644
index 30d9e55d..00000000
--- a/Source/Backlang.WasmBridge/Backlang.WasmBridge.csproj
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
- net9.0
- browser-wasm
- main.mjs
- Exe
- true
- true
- preview
- True
-
-
-
-
-
-
diff --git a/Source/Backlang.WasmBridge/Bridge.cs b/Source/Backlang.WasmBridge/Bridge.cs
deleted file mode 100644
index acfcc035..00000000
--- a/Source/Backlang.WasmBridge/Bridge.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using Backlang.Contracts;
-using Backlang.Driver;
-using System;
-using System.IO;
-using System.Runtime.InteropServices.JavaScript;
-using System.Text;
-
-public partial class Bridge
-{
- [JSExport]
- public static string CompileAndRun(string src)
- {
- var context = new CompilerContext();
- context.Playground = new PlaygroundData { IsPlayground = true, Source = src };
-
- var assemblyStream = new MemoryStream();
-
- context.OutputStream = assemblyStream;
-
- var output = new MemoryStream();
- var sw = new StreamWriter(output);
- Console.SetOut(sw);
-
- CompilerDriver.Compile(context);
-
- assemblyStream.Seek(0, SeekOrigin.Begin);
-
- //var assembly = Assembly.Load(assemblyStream.ToArray());
- //assembly.EntryPoint.Invoke(null, Array.Empty