From c6bb8085721ec898dd0d0d3e57f8f20f92ecacd5 Mon Sep 17 00:00:00 2001 From: Chris Anders Date: Sun, 22 Dec 2024 09:00:16 +0100 Subject: [PATCH] refactor: Convert to new ast --- .../.idea/.idea.Backlang/.idea/workspace.xml | 450 ------------------ .../.idea/.idea.BacklangSdk/.idea/vcs.xml | 6 - .../Socordia.CodeAnalysis/AST/AstNode.cs | 9 - .../AST/Declarations/ClassDeclaration.cs | 14 + .../AST/Expressions/Call.cs | 13 + .../AST/Expressions/CollectionExpression.cs | 9 + .../AST/Expressions/UnaryOperator.cs | 15 +- .../AST/Statements/BreakStatement.cs | 6 - .../AST/Statements/ContinueStatement.cs | 6 - .../AST/Statements/Loops/BreakStatement.cs | 6 + .../AST/Statements/Loops/ContinueStatement.cs | 6 + .../{ => Loops}/DoWhileStatement.cs | 2 +- .../AST/Statements/Loops/ForStatement.cs | 17 + .../Statements/{ => Loops}/WhileStatement.cs | 2 +- .../Socordia.CodeAnalysis/AST/TypeAlias.cs | 11 + .../AST/TypeNames/GenericTypeName.cs | 11 + .../AST/TypeNames/PointerKind.cs | 7 + .../AST/TypeNames/PointerTypeName.cs | 37 ++ .../AST/TypeNames/SimpleTypeName.cs | 13 + .../AST/TypeNames/TypeName.cs | 6 + .../Parsing/Expression.cs | 15 +- .../Parsing/LNodeExtensions.cs | 1 + .../Parsing/ParsePoints/AnnotationParser.cs | 13 +- .../Declarations/BitFieldDeclaration.cs | 9 +- .../Declarations/BitFieldMemberDeclaration.cs | 9 +- .../Declarations/ClassDeclaration.cs | 13 +- .../ConstructorDeclarationParser.cs | 8 +- .../Declarations/DestructorDeclaration.cs | 8 +- .../DiscriminatedUnionDeclaration.cs | 8 +- .../Declarations/EnumDeclaration.cs | 9 +- .../Declarations/EnumMemberDeclaration.cs | 8 +- .../Declarations/FunctionDeclaration.cs | 8 +- .../Declarations/ImplementationDeclaration.cs | 8 +- .../Declarations/InterfaceDeclaration.cs | 9 +- .../Declarations/MacroBlockDeclaration.cs | 8 +- .../Declarations/MacroDeclaration.cs | 8 +- .../Declarations/ModuleDeclarationParser.cs | 2 +- .../ParameterDeclarationParser.cs | 5 +- .../Declarations/StructDeclaration.cs | 9 +- .../Declarations/TypeAliasDeclaration.cs | 8 +- .../Declarations/TypeFieldDeclaration.cs | 8 +- .../Declarations/TypeFunctionDeclaration.cs | 8 +- .../Declarations/TypeMemberDeclaration.cs | 13 +- .../Declarations/UnionDeclaration.cs | 9 +- .../Declarations/UnitDeclarationParser.cs | 2 +- .../Expressions/DefaultExpressionParser.cs | 2 +- .../Expressions/IdentifierParser.cs | 8 +- .../Expressions/Match/MatchExpression.cs | 8 +- .../Expressions/Match/MatchRule.cs | 10 +- .../Expressions/SizeOfExpression.cs | 2 +- .../Expressions/TypeOfExpressionParser.cs | 2 +- .../Parsing/ParsePoints/SignatureParser.cs | 6 +- .../Statements/BreakStatementParser.cs | 4 +- .../Statements/ExpressionStatementParser.cs | 2 +- .../Statements/IfStatementParser.cs | 4 +- .../Statements/ImportStatementParser.cs | 2 +- .../Loops/ContinueStatementParser.cs | 4 +- .../Loops/DoWhileStatementParser.cs | 3 +- .../Statements/Loops/ForStatement.cs | 12 +- .../Statements/Loops/WhileStatementParser.cs | 2 +- .../Statements/MacroBlockStatement.cs | 8 +- .../ParsePoints/Statements/Statement.cs | 4 +- .../ParsePoints/Statements/SwitchStatement.cs | 12 +- .../Statements/ThrowStatementParser.cs | 2 +- .../Statements/TryStatementParser.cs | 3 +- .../Statements/VariableStatementParser.cs | 11 +- .../{TypeLiteral.cs => TypeLiteralParser.cs} | 57 ++- .../Parsing/Parser.Expressions.cs | 46 +- .../Parsing/Parser.ParsePoints.cs | 37 +- .../Parsing/SyntaxTree.cs | 36 +- .../Socordia.CodeAnalysis.csproj | 1 + NewSource/SocordiaC/Core/ExtensionUtils.cs | 46 -- .../SocordiaC/Core/LNodeDeconstructors.cs | 29 -- .../Core/Semantic/Checks/ImportCheck.cs | 4 +- .../Semantic/Checks/InterfaceNameCheck.cs | 4 +- .../Core/Semantic/Checks/ModifierCheck.cs | 4 +- .../Semantic/Checks/ModuleDefinitionCheck.cs | 4 +- .../Core/Semantic/Checks/TypenameCheck.cs | 4 +- .../Core/Semantic/SemanticChecker.cs | 3 +- NewSource/SocordiaC/Core/SyntacticMacros.cs | 5 +- 80 files changed, 419 insertions(+), 824 deletions(-) delete mode 100644 NewSource/.idea/.idea.Backlang/.idea/workspace.xml delete mode 100644 NewSource/.idea/.idea.BacklangSdk/.idea/vcs.xml create mode 100644 NewSource/Socordia.CodeAnalysis/AST/Declarations/ClassDeclaration.cs create mode 100644 NewSource/Socordia.CodeAnalysis/AST/Expressions/Call.cs create mode 100644 NewSource/Socordia.CodeAnalysis/AST/Expressions/CollectionExpression.cs delete mode 100644 NewSource/Socordia.CodeAnalysis/AST/Statements/BreakStatement.cs delete mode 100644 NewSource/Socordia.CodeAnalysis/AST/Statements/ContinueStatement.cs create mode 100644 NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/BreakStatement.cs create mode 100644 NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/ContinueStatement.cs rename NewSource/Socordia.CodeAnalysis/AST/Statements/{ => Loops}/DoWhileStatement.cs (82%) create mode 100644 NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/ForStatement.cs rename NewSource/Socordia.CodeAnalysis/AST/Statements/{ => Loops}/WhileStatement.cs (82%) create mode 100644 NewSource/Socordia.CodeAnalysis/AST/TypeAlias.cs create mode 100644 NewSource/Socordia.CodeAnalysis/AST/TypeNames/GenericTypeName.cs create mode 100644 NewSource/Socordia.CodeAnalysis/AST/TypeNames/PointerKind.cs create mode 100644 NewSource/Socordia.CodeAnalysis/AST/TypeNames/PointerTypeName.cs create mode 100644 NewSource/Socordia.CodeAnalysis/AST/TypeNames/SimpleTypeName.cs create mode 100644 NewSource/Socordia.CodeAnalysis/AST/TypeNames/TypeName.cs rename NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/{TypeLiteral.cs => TypeLiteralParser.cs} (72%) delete mode 100644 NewSource/SocordiaC/Core/ExtensionUtils.cs delete mode 100644 NewSource/SocordiaC/Core/LNodeDeconstructors.cs diff --git a/NewSource/.idea/.idea.Backlang/.idea/workspace.xml b/NewSource/.idea/.idea.Backlang/.idea/workspace.xml deleted file mode 100644 index 84deaf00..00000000 --- a/NewSource/.idea/.idea.Backlang/.idea/workspace.xml +++ /dev/null @@ -1,450 +0,0 @@ - - - - BacklangC/BacklangC.csproj - SdkSample/Sample.backproj - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - { - "lastFilter": { - "state": "OPEN", - "assignee": "furesoft" - } -} - { - "selectedUrlAndAccountId": { - "url": "https://github.com/Backlang-Org/Backlang.git", - "accountId": "40174b11-8cff-4ee7-9725-c6cbeba5bbde" - } -} - - - - - - - - - - - - - - - - { - "associatedIndex": 5 -} - - - - - - - { - "keyToString": { - ".NET Project.BacklangC.executor": "Run", - "RunOnceActivity.ShowReadmeOnStart": "true", - "RunOnceActivity.git.unshallow": "true", - "git-widget-placeholder": "feature/new-backend-sdk", - "ignore.virus.scanning.warn.message": "true", - "node.js.detected.package.eslint": "true", - "node.js.detected.package.tslint": "true", - "node.js.selected.package.eslint": "(autodetect)", - "node.js.selected.package.tslint": "(autodetect)", - "nodejs_package_manager_path": "npm", - "settings.editor.selected.configurable": "RiderNuGetOptionsPageId", - "vue.rearranger.settings.migration": "true" - } -} - - - - - - - - - - - 1732998079780 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/NewSource/.idea/.idea.BacklangSdk/.idea/vcs.xml b/NewSource/.idea/.idea.BacklangSdk/.idea/vcs.xml deleted file mode 100644 index c2365ab1..00000000 --- a/NewSource/.idea/.idea.BacklangSdk/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/AstNode.cs b/NewSource/Socordia.CodeAnalysis/AST/AstNode.cs index 454b0a10..a72d337a 100644 --- a/NewSource/Socordia.CodeAnalysis/AST/AstNode.cs +++ b/NewSource/Socordia.CodeAnalysis/AST/AstNode.cs @@ -1,17 +1,8 @@ using MrKWatkins.Ast; -using Socordia.CodeAnalysis.Parsing; namespace Socordia.CodeAnalysis.AST; public class AstNode : PropertyNode { - public AstNode WithRange(Token keywordToken, Token iteratorPrev) - { - throw new NotImplementedException(); - } - public AstNode WithRange(Token token) - { - throw new NotImplementedException(); - } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/Declarations/ClassDeclaration.cs b/NewSource/Socordia.CodeAnalysis/AST/Declarations/ClassDeclaration.cs new file mode 100644 index 00000000..e7737461 --- /dev/null +++ b/NewSource/Socordia.CodeAnalysis/AST/Declarations/ClassDeclaration.cs @@ -0,0 +1,14 @@ +namespace Socordia.CodeAnalysis.AST.Declarations; + +public class ClassDeclaration : Declaration +{ + public ClassDeclaration(string name, List inheritances, List members) + { + Properties.Set(nameof(Name), name); + Properties.Set(nameof(Inheritances), inheritances); + Children.Add(members); + } + + public string Name => Properties.GetOrThrow(nameof(Name)); + public List Inheritances => Properties.GetOrThrow>(nameof(Inheritances)); +} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/Expressions/Call.cs b/NewSource/Socordia.CodeAnalysis/AST/Expressions/Call.cs new file mode 100644 index 00000000..db4dd36a --- /dev/null +++ b/NewSource/Socordia.CodeAnalysis/AST/Expressions/Call.cs @@ -0,0 +1,13 @@ +namespace Socordia.CodeAnalysis.AST.Expressions; + +public class Call : AstNode +{ + public Call(AstNode callee, List arguments) + { + Children.Add(callee); + Children.Add(arguments); + } + + public AstNode Callee => Children[0]; + public IEnumerable Arguments => Children.Skip(1); +} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/Expressions/CollectionExpression.cs b/NewSource/Socordia.CodeAnalysis/AST/Expressions/CollectionExpression.cs new file mode 100644 index 00000000..6ac103f4 --- /dev/null +++ b/NewSource/Socordia.CodeAnalysis/AST/Expressions/CollectionExpression.cs @@ -0,0 +1,9 @@ +namespace Socordia.CodeAnalysis.AST.Expressions; + +public class CollectionExpression : AstNode +{ + public CollectionExpression(List elements) + { + Children.Add(elements); + } +} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/Expressions/UnaryOperator.cs b/NewSource/Socordia.CodeAnalysis/AST/Expressions/UnaryOperator.cs index 822f377e..60abbc2f 100644 --- a/NewSource/Socordia.CodeAnalysis/AST/Expressions/UnaryOperator.cs +++ b/NewSource/Socordia.CodeAnalysis/AST/Expressions/UnaryOperator.cs @@ -1,15 +1,22 @@ -using Loyc; +namespace Socordia.CodeAnalysis.AST.Expressions; -namespace Socordia.CodeAnalysis.AST.Expressions; +public enum UnaryOperatorKind +{ + Prefix, + Suffix +} public class UnaryOperator : AstNode { - public UnaryOperator(Symbol op, AstNode operand) + public UnaryOperator(string op, AstNode operand, UnaryOperatorKind kind) { Properties.Set(nameof(Op), op); + Properties.Set(nameof(Kind), kind); + Children.Add(operand); } - public Symbol Op => Properties.GetOrThrow(nameof(Op)); + public string Op => Properties.GetOrThrow(nameof(Op)); + public UnaryOperatorKind Kind => Properties.GetOrThrow(nameof(Kind)); public AstNode Operand => Children.First; } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/Statements/BreakStatement.cs b/NewSource/Socordia.CodeAnalysis/AST/Statements/BreakStatement.cs deleted file mode 100644 index bc96e6e0..00000000 --- a/NewSource/Socordia.CodeAnalysis/AST/Statements/BreakStatement.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Socordia.CodeAnalysis.AST.Statements; - -public class BreakStatement : AstNode -{ - -} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/Statements/ContinueStatement.cs b/NewSource/Socordia.CodeAnalysis/AST/Statements/ContinueStatement.cs deleted file mode 100644 index 9104bd18..00000000 --- a/NewSource/Socordia.CodeAnalysis/AST/Statements/ContinueStatement.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Socordia.CodeAnalysis.AST.Statements; - -public class ContinueStatement : AstNode -{ - -} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/BreakStatement.cs b/NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/BreakStatement.cs new file mode 100644 index 00000000..c5543934 --- /dev/null +++ b/NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/BreakStatement.cs @@ -0,0 +1,6 @@ +namespace Socordia.CodeAnalysis.AST.Statements.Loops; + +public class BreakStatement : AstNode +{ + +} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/ContinueStatement.cs b/NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/ContinueStatement.cs new file mode 100644 index 00000000..bb23c2e4 --- /dev/null +++ b/NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/ContinueStatement.cs @@ -0,0 +1,6 @@ +namespace Socordia.CodeAnalysis.AST.Statements.Loops; + +public class ContinueStatement : AstNode +{ + +} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/Statements/DoWhileStatement.cs b/NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/DoWhileStatement.cs similarity index 82% rename from NewSource/Socordia.CodeAnalysis/AST/Statements/DoWhileStatement.cs rename to NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/DoWhileStatement.cs index cc688cbd..b6bfadf5 100644 --- a/NewSource/Socordia.CodeAnalysis/AST/Statements/DoWhileStatement.cs +++ b/NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/DoWhileStatement.cs @@ -1,4 +1,4 @@ -namespace Socordia.CodeAnalysis.AST.Statements; +namespace Socordia.CodeAnalysis.AST.Statements.Loops; public class DoWhileStatement : AstNode { diff --git a/NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/ForStatement.cs b/NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/ForStatement.cs new file mode 100644 index 00000000..b073410c --- /dev/null +++ b/NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/ForStatement.cs @@ -0,0 +1,17 @@ +namespace Socordia.CodeAnalysis.AST.Statements.Loops; + +public class ForStatement : AstNode +{ + public ForStatement(AstNode varExpr, AstNode type, AstNode arr, Block body) + { + Children.Add(varExpr); + Children.Add(type); + Children.Add(arr); + Children.Add(body); + } + + public AstNode VarExpr => Children[0]; + public AstNode Type => Children[1]; + public AstNode Arr => Children[2]; + public Block Body => (Block) Children[3]; +} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/Statements/WhileStatement.cs b/NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/WhileStatement.cs similarity index 82% rename from NewSource/Socordia.CodeAnalysis/AST/Statements/WhileStatement.cs rename to NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/WhileStatement.cs index 504ba896..93c9b238 100644 --- a/NewSource/Socordia.CodeAnalysis/AST/Statements/WhileStatement.cs +++ b/NewSource/Socordia.CodeAnalysis/AST/Statements/Loops/WhileStatement.cs @@ -1,4 +1,4 @@ -namespace Socordia.CodeAnalysis.AST.Statements; +namespace Socordia.CodeAnalysis.AST.Statements.Loops; public class WhileStatement : AstNode { diff --git a/NewSource/Socordia.CodeAnalysis/AST/TypeAlias.cs b/NewSource/Socordia.CodeAnalysis/AST/TypeAlias.cs new file mode 100644 index 00000000..281a5933 --- /dev/null +++ b/NewSource/Socordia.CodeAnalysis/AST/TypeAlias.cs @@ -0,0 +1,11 @@ +namespace Socordia.CodeAnalysis.AST; + +public class TypeAlias : AstNode +{ + public TypeAlias(AstNode expr) + { + Children.Add(expr); + } + + public AstNode Expression => Children[0]; +} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/TypeNames/GenericTypeName.cs b/NewSource/Socordia.CodeAnalysis/AST/TypeNames/GenericTypeName.cs new file mode 100644 index 00000000..47985086 --- /dev/null +++ b/NewSource/Socordia.CodeAnalysis/AST/TypeNames/GenericTypeName.cs @@ -0,0 +1,11 @@ +namespace Socordia.CodeAnalysis.AST.TypeNames; + +public class GenericTypeName : SimpleTypeName +{ + public GenericTypeName(string name, List genericArguments) : base(name) + { + Properties.Set(nameof(GenericArguments), genericArguments); + } + + public List GenericArguments => Properties.GetOrThrow>(nameof(GenericArguments)); +} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/TypeNames/PointerKind.cs b/NewSource/Socordia.CodeAnalysis/AST/TypeNames/PointerKind.cs new file mode 100644 index 00000000..e3ae7b34 --- /dev/null +++ b/NewSource/Socordia.CodeAnalysis/AST/TypeNames/PointerKind.cs @@ -0,0 +1,7 @@ +namespace Socordia.CodeAnalysis.AST.TypeNames; + +public enum PointerKind +{ + Transient, + Reference +} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/TypeNames/PointerTypeName.cs b/NewSource/Socordia.CodeAnalysis/AST/TypeNames/PointerTypeName.cs new file mode 100644 index 00000000..351e6d9a --- /dev/null +++ b/NewSource/Socordia.CodeAnalysis/AST/TypeNames/PointerTypeName.cs @@ -0,0 +1,37 @@ +using System.Text; +using Socordia.CodeAnalysis.Parsing; + +namespace Socordia.CodeAnalysis.AST.TypeNames; + +public class PointerTypeName : TypeName +{ + public PointerTypeName(TypeName type, PointerKind kind) + { + Children.Add(type); + Properties.Set(nameof(Kind), kind); + } + + public TypeName Type => (TypeName)Children[0]; + public PointerKind Kind => Properties.GetOrThrow(nameof(Kind)); + + public override string ToString() + { + var builder = new StringBuilder(); + + switch (Kind) + { + case PointerKind.Transient: + builder.Append('*'); + break; + case PointerKind.Reference: + builder.Append('&'); + break; + default: + throw new ArgumentOutOfRangeException(); + } + + builder.Append(Type); + + return builder.ToString(); + } +} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/TypeNames/SimpleTypeName.cs b/NewSource/Socordia.CodeAnalysis/AST/TypeNames/SimpleTypeName.cs new file mode 100644 index 00000000..d7d6ed61 --- /dev/null +++ b/NewSource/Socordia.CodeAnalysis/AST/TypeNames/SimpleTypeName.cs @@ -0,0 +1,13 @@ +namespace Socordia.CodeAnalysis.AST.TypeNames; + +public class SimpleTypeName : TypeName +{ + public SimpleTypeName(string name) + { + Properties.Set(nameof(Name), name); + } + + public string Name => Properties.GetOrThrow(nameof(Name)); + + public override string ToString() => Name; +} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/AST/TypeNames/TypeName.cs b/NewSource/Socordia.CodeAnalysis/AST/TypeNames/TypeName.cs new file mode 100644 index 00000000..9da64786 --- /dev/null +++ b/NewSource/Socordia.CodeAnalysis/AST/TypeNames/TypeName.cs @@ -0,0 +1,6 @@ +namespace Socordia.CodeAnalysis.AST.TypeNames; + +public abstract class TypeName : AstNode +{ + +} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/Expression.cs b/NewSource/Socordia.CodeAnalysis/Parsing/Expression.cs index 3bc09e29..91002d81 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/Expression.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/Expression.cs @@ -2,6 +2,7 @@ using Loyc; using Loyc.Syntax; using Socordia.CodeAnalysis.AST; +using Socordia.CodeAnalysis.AST.Expressions; using Socordia.CodeAnalysis.Core; using Socordia.CodeAnalysis.Core.Attributes; @@ -47,7 +48,7 @@ public static int GetBinaryOperatorPrecedence(TokenType kind) return BinaryOperators.GetValueOrDefault(kind); } - public static AstNode Parse(Parser parser, ParsePoints parsePoints = null, int parentPrecedence = 0) + public static AstNode Parse(Parser parser, ParsePointCollection parsePoints = null, int parentPrecedence = 0) { AstNode left = null; var preUnaryOperatorPrecedence = GetPreUnaryOperatorPrecedence(parser.Iterator.Current.Type); @@ -60,8 +61,7 @@ public static AstNode Parse(Parser parser, ParsePoints parsePoints = null, int p var operand = Parse(parser, parsePoints, preUnaryOperatorPrecedence + 1); - left = SyntaxTree.Unary(GSymbol.Get($"'{operatorToken.Text}"), operand) - .WithRange(operatorToken.Start, operand.Range.EndIndex).WithStyle(NodeStyle.PrefixNotation); + left = SyntaxTree.Unary(operatorToken.Text, operand, UnaryOperatorKind.Prefix); } } else @@ -77,8 +77,7 @@ public static AstNode Parse(Parser parser, ParsePoints parsePoints = null, int p { var unaryOperatorToken = parser.Iterator.NextToken(); - left = SyntaxTree.Unary(GSymbol.Get($"'suf{unaryOperatorToken.Text}"), left) - .WithRange(left.Range.StartIndex, unaryOperatorToken.End).WithStyle(NodeStyle.Operator); + left = SyntaxTree.Unary(unaryOperatorToken.Text, left, UnaryOperatorKind.Suffix); } } } @@ -94,8 +93,7 @@ public static AstNode Parse(Parser parser, ParsePoints parsePoints = null, int p 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); + left = SyntaxTree.Binary(GSymbol.Get($"'{operatorToken.Text}"), left, right); // parsing postunary for: Hello::new()? = false; var postUnaryOperatorPrecedence = GetPostUnaryOperatorPrecedence(parser.Iterator.Current.Type); @@ -106,8 +104,7 @@ public static AstNode Parse(Parser parser, ParsePoints parsePoints = null, int p { var unaryOperatorToken = parser.Iterator.NextToken(); - left = SyntaxTree.Unary(GSymbol.Get($"'suf{unaryOperatorToken.Text}"), left) - .WithRange(left.Range.StartIndex, unaryOperatorToken.End).WithStyle(NodeStyle.Operator); + left = SyntaxTree.Unary(unaryOperatorToken.Text, left, UnaryOperatorKind.Suffix); } } } diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/LNodeExtensions.cs b/NewSource/Socordia.CodeAnalysis/Parsing/LNodeExtensions.cs index 170420c3..f0e6fd05 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/LNodeExtensions.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/LNodeExtensions.cs @@ -1,4 +1,5 @@ using Loyc.Syntax; +using Socordia.CodeAnalysis.Parsing.ParsePoints; namespace Socordia.CodeAnalysis.Parsing; diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/AnnotationParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/AnnotationParser.cs index edbc7fd3..cb2e9c6b 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/AnnotationParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/AnnotationParser.cs @@ -8,10 +8,17 @@ public static Annotation Parse(TokenIterator iterator, Parser parser) { var atToken = iterator.Match(TokenType.At); - //ToDo: allow support for annotations without arguments and parens - var call = Expression.Parse(parser); + var name = iterator.Match(TokenType.Identifier); + var args = new List(); - return new Annotation(call).WithRange(atToken, iterator.Prev); + if (iterator.IsMatch(TokenType.OpenParen)) + { + iterator.NextToken(); + + args = Expression.ParseList(parser, TokenType.CloseParen); + } + + return new Annotation(name.Text, args); } public static bool TryParse(Parser parser, out List node) diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/BitFieldDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/BitFieldDeclaration.cs index 5e8bead2..9cc56ada 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/BitFieldDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/BitFieldDeclaration.cs @@ -1,8 +1,6 @@ -using Loyc.Syntax; -using Socordia.CodeAnalysis.Core; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public sealed class BitFieldDeclaration : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -16,4 +14,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return SyntaxTree.Bitfield(nameToken, members).WithRange(keywordToken, iterator.Prev); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/BitFieldMemberDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/BitFieldMemberDeclaration.cs index 380bf3c1..b891906d 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/BitFieldMemberDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/BitFieldMemberDeclaration.cs @@ -1,8 +1,6 @@ -using Loyc.Syntax; -using Socordia.CodeAnalysis.Core; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public sealed class BitFieldMemberDeclaration : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -30,4 +28,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return SyntaxTree.Factory.Tuple(SyntaxTree.Factory.Id(nameToken.Text).WithRange(nameToken), value); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ClassDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ClassDeclaration.cs index da6abbe9..119a6907 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ClassDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ClassDeclaration.cs @@ -1,16 +1,15 @@ -using Loyc.Syntax; -using Socordia.CodeAnalysis.Core; +using Socordia.CodeAnalysis.AST; namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; -public sealed class ClassDeclaration : IParsePoint +public sealed class ClassDeclarationParser : IParsePoint { - public static LNode Parse(TokenIterator iterator, Parser parser) + public static AstNode Parse(TokenIterator iterator, Parser parser) { var keywordToken = iterator.Prev; var nameToken = iterator.Match(TokenType.Identifier); - var inheritances = new LNodeList(); + var inheritances = new List(); if (iterator.ConsumeIfMatch(TokenType.Colon)) { @@ -19,8 +18,8 @@ public static LNode Parse(TokenIterator iterator, Parser parser) iterator.Match(TokenType.OpenCurly); - var members = ParsingHelpers.ParseUntil(parser, TokenType.CloseCurly); + List members = []; //ParsingHelpers.ParseUntil(parser, TokenType.CloseCurly); - return SyntaxTree.Class(nameToken, inheritances, members).WithRange(keywordToken, iterator.Prev); + return SyntaxTree.Class(nameToken, inheritances, members); } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ConstructorDeclarationParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ConstructorDeclarationParser.cs index 8a830c9f..0b5a7993 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ConstructorDeclarationParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ConstructorDeclarationParser.cs @@ -1,7 +1,6 @@ -using Socordia.CodeAnalysis.AST; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public class ConstructorDeclarationParser : IParsePoint { public static AstNode Parse(TokenIterator iterator, Parser parser) @@ -17,4 +16,5 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) return SyntaxTree.Constructor(parameters, code) .WithRange(keywordToken, iterator.Prev); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/DestructorDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/DestructorDeclaration.cs index 2ab73cb4..3b4554e4 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/DestructorDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/DestructorDeclaration.cs @@ -1,7 +1,6 @@ -using Loyc.Syntax; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public class DestructorDeclaration : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -16,4 +15,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return SyntaxTree.Destructor(parameters, code).WithRange(keywordToken, iterator.Prev); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/DiscriminatedUnionDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/DiscriminatedUnionDeclaration.cs index de38661c..3beeb316 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/DiscriminatedUnionDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/DiscriminatedUnionDeclaration.cs @@ -1,7 +1,6 @@ -using Loyc.Syntax; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public class DiscriminatedUnionDeclaration : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -65,4 +64,5 @@ public static LNodeList ParseParameterDeclarations(TokenIterator iterator, Parse return parameters; } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/EnumDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/EnumDeclaration.cs index fee4cd11..fb8722fa 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/EnumDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/EnumDeclaration.cs @@ -1,8 +1,6 @@ -using Loyc.Syntax; -using Socordia.CodeAnalysis.Core; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public sealed class EnumDeclaration : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -16,4 +14,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return SyntaxTree.Enum(LNode.Id(nameToken.Text), members).WithRange(keywordToken, iterator.Prev); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/EnumMemberDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/EnumMemberDeclaration.cs index a6efcd30..c4021aaf 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/EnumMemberDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/EnumMemberDeclaration.cs @@ -1,7 +1,6 @@ -using Loyc.Syntax; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public class EnumMemberDeclaration : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -18,4 +17,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return SyntaxTree.Factory.Var(LNode.Missing, LNode.Id(memberNameToken.Text), value).PlusAttrs(annotations); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/FunctionDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/FunctionDeclaration.cs index 32eb7745..744188c4 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/FunctionDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/FunctionDeclaration.cs @@ -1,7 +1,6 @@ -using Loyc.Syntax; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public sealed class FunctionDeclaration : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -11,4 +10,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return signature.PlusArg(Statements.Statement.ParseBlock(parser)).WithRange(keywordToken, iterator.Prev); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ImplementationDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ImplementationDeclaration.cs index e84baf72..7fe5eacb 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ImplementationDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ImplementationDeclaration.cs @@ -1,7 +1,6 @@ -using Loyc.Syntax; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public class ImplementationDeclaration : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -53,4 +52,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return SyntaxTree.ImplDecl(target, body).WithRange(keywordToken, iterator.Prev); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/InterfaceDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/InterfaceDeclaration.cs index d60e876a..6e83244b 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/InterfaceDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/InterfaceDeclaration.cs @@ -1,8 +1,6 @@ -using Loyc.Syntax; -using Socordia.CodeAnalysis.Core; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public sealed class InterfaceDeclaration : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -22,4 +20,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return SyntaxTree.Interface(nameToken, inheritances, members).WithRange(keywordToken, iterator.Prev); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/MacroBlockDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/MacroBlockDeclaration.cs index f71b21bc..570d22cd 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/MacroBlockDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/MacroBlockDeclaration.cs @@ -1,7 +1,6 @@ -using Loyc.Syntax; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public sealed class MacroBlockDeclaration : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -62,4 +61,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return LNode.Missing; } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/MacroDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/MacroDeclaration.cs index e8d21b43..ca79a734 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/MacroDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/MacroDeclaration.cs @@ -1,7 +1,6 @@ -using Loyc.Syntax; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public sealed class MacroDeclaration : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -12,4 +11,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return signature.WithTarget(Symbols.Macro).PlusArg(LNode.Call(CodeSymbols.Braces, Statements.Statement.ParseBlock(parser)) .SetStyle(NodeStyle.StatementBlock)).WithRange(keywordToken, iterator.Prev); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ModuleDeclarationParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ModuleDeclarationParser.cs index 97f8194b..c9349cba 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ModuleDeclarationParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ModuleDeclarationParser.cs @@ -13,6 +13,6 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) iterator.Match(TokenType.Semicolon); - return tree.WithRange(keywordToken, iterator.Prev); + return tree; } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ParameterDeclarationParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ParameterDeclarationParser.cs index a8c79954..6950b8e0 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ParameterDeclarationParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/ParameterDeclarationParser.cs @@ -17,7 +17,7 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) iterator.Match(TokenType.Colon); - var type = TypeLiteral.Parse(iterator, parser); + var type = TypeLiteralParser.Parse(iterator, parser); AstNode? defaultValue = null; @@ -28,8 +28,7 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) defaultValue = Expression.Parse(parser); } - return new ParameterDeclaration(type, name.Text, defaultValue, assertNotNull, annotations) - .WithRange(keywordToken, iterator.Prev); + return new ParameterDeclaration(type, name.Text, defaultValue, assertNotNull, annotations); } public static List ParseList(Parser parser) diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/StructDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/StructDeclaration.cs index c339d5d5..dbd6e8fa 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/StructDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/StructDeclaration.cs @@ -1,8 +1,6 @@ -using Loyc.Syntax; -using Socordia.CodeAnalysis.Core; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public sealed class StructDeclaration : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -23,4 +21,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return SyntaxTree.Struct(name, inheritances, members) .WithRange(keywordToken, iterator.Prev); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeAliasDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeAliasDeclaration.cs index 2c8ce459..26c78df2 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeAliasDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeAliasDeclaration.cs @@ -1,10 +1,10 @@ -using Loyc.Syntax; +using Socordia.CodeAnalysis.AST; namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; -public sealed class TypeAliasDeclaration : IParsePoint +public sealed class TypeAliasDeclarationParser : IParsePoint { - public static LNode Parse(TokenIterator iterator, Parser parser) + public static AstNode Parse(TokenIterator iterator, Parser parser) { // using as var keywordToken = iterator.Prev; @@ -12,6 +12,6 @@ public static LNode Parse(TokenIterator iterator, Parser parser) iterator.Match(TokenType.Semicolon); - return SyntaxTree.Using(expr).WithRange(keywordToken, iterator.Prev); + return new TypeAlias(expr); } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeFieldDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeFieldDeclaration.cs index 4fb6934b..a83a8888 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeFieldDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeFieldDeclaration.cs @@ -1,7 +1,6 @@ -using Loyc.Syntax; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public sealed class TypeFieldDeclaration { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -9,4 +8,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) iterator.Match(TokenType.Let); return Statements.VariableStatementParser.Parse(iterator, parser); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeFunctionDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeFunctionDeclaration.cs index a5f1d877..4d54df19 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeFunctionDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeFunctionDeclaration.cs @@ -1,15 +1,15 @@ -using Loyc.Syntax; +using Socordia.CodeAnalysis.AST; namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; public sealed class TypeFunctionDeclaration { - public static LNode Parse(TokenIterator iterator, Parser parser) + public static AstNode Parse(TokenIterator iterator, Parser parser) { var keywordToken = iterator.Match(TokenType.Function); - var result = Signature.Parse(parser); + var result = SignatureParser.Parse(parser); iterator.Match(TokenType.Semicolon); - return result.WithRange(keywordToken, iterator.Prev); + return result; } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeMemberDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeMemberDeclaration.cs index c122c89a..cd040e40 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeMemberDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/TypeMemberDeclaration.cs @@ -1,14 +1,12 @@ -using Loyc.Syntax; -using Socordia.CodeAnalysis.Core; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public sealed class TypeMemberDeclaration : IParsePoint { - public static LNode Parse(TokenIterator iterator, Parser parser) + public static AstNode Parse(TokenIterator iterator, Parser parser) { _ = AnnotationParser.TryParse(parser, out var annotations); - _ = Modifier.TryParse(parser, out var modifiers); + _ = ModifierParser.TryParse(parser, out var modifiers); LNode declaration = LNode.Missing; @@ -139,4 +137,5 @@ public static LNode ParseProperty(TokenIterator iterator, Parser parser) return SyntaxTree.Property(type, name, getter, setter, value).WithRange(keywordToken, iterator.Prev); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/UnionDeclaration.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/UnionDeclaration.cs index a40f62e8..f1606a8b 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/UnionDeclaration.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/UnionDeclaration.cs @@ -1,8 +1,6 @@ -using Loyc.Syntax; -using Socordia.CodeAnalysis.Core; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +/* public sealed class UnionDeclaration : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -17,4 +15,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return SyntaxTree.Union(nameToken.Text, members).WithRange(keywordToken, iterator.Current); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/UnitDeclarationParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/UnitDeclarationParser.cs index 967d266b..9c7e1525 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/UnitDeclarationParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/UnitDeclarationParser.cs @@ -11,6 +11,6 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) iterator.Match(TokenType.Semicolon); - return SyntaxTree.UnitDeclaration(nameToken).WithRange(keywordToken, nameToken); + return SyntaxTree.UnitDeclaration(nameToken); } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/DefaultExpressionParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/DefaultExpressionParser.cs index 1075c620..2bd47858 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/DefaultExpressionParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/DefaultExpressionParser.cs @@ -10,7 +10,7 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) //default if (iterator.ConsumeIfMatch(TokenType.OpenParen)) { - var type = TypeLiteral.Parse(iterator, parser); + var type = TypeLiteralParser.Parse(iterator, parser); iterator.Match(TokenType.CloseParen); diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/IdentifierParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/IdentifierParser.cs index 324fd053..341f9ab3 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/IdentifierParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/IdentifierParser.cs @@ -1,4 +1,5 @@ using Socordia.CodeAnalysis.AST; +using Socordia.CodeAnalysis.AST.Expressions; namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Expressions; @@ -13,8 +14,7 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) { iterator.NextToken(); - return SyntaxTree.ArrayInstantiation(nameExpression, Expression.ParseList(parser, TokenType.CloseSquare)) - .WithRange(nameToken, iterator.Prev); + return SyntaxTree.ArrayInstantiation(nameExpression, Expression.ParseList(parser, TokenType.CloseSquare)); } if (iterator.Current.Type == TokenType.OpenParen) @@ -23,9 +23,9 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) var arguments = Expression.ParseList(parser, TokenType.CloseParen); - return SyntaxTree.Factory.Call(nameExpression, arguments).WithRange(nameToken, iterator.Prev); + return new Call(nameExpression, arguments); } - return nameExpression.WithRange(nameToken, iterator.Prev); + return nameExpression; } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/Match/MatchExpression.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/Match/MatchExpression.cs index eb036471..7588982f 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/Match/MatchExpression.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/Match/MatchExpression.cs @@ -1,7 +1,6 @@ -using Loyc.Syntax; - namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Expressions.Match; +/* public sealed class MatchExpression : IParsePoint { /* @@ -10,7 +9,7 @@ public sealed class MatchExpression : IParsePoint i32 num => num + 2, _ => 0 + 4; */ - +/* public static LNode Parse(TokenIterator iterator, Parser parser) { var matchArgument = Expression.Parse(parser); @@ -33,4 +32,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return SyntaxTree.Factory.Call(LNode.Id(Symbols.Match), matchArgument).WithAttrs(conditions); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/Match/MatchRule.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/Match/MatchRule.cs index 9e6f690e..8466a894 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/Match/MatchRule.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/Match/MatchRule.cs @@ -1,8 +1,5 @@ -using Loyc; -using Loyc.Syntax; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Expressions.Match; - +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Expressions.Match; +/* public sealed class MatchRule { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -69,4 +66,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return LNode.Missing; } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/SizeOfExpression.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/SizeOfExpression.cs index 23c1f234..494b1320 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/SizeOfExpression.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/SizeOfExpression.cs @@ -10,7 +10,7 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) iterator.Match(TokenType.OpenParen); - var type = TypeLiteral.Parse(iterator, parser); + var type = TypeLiteralParser.Parse(iterator, parser); iterator.Match(TokenType.CloseParen); diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/TypeOfExpressionParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/TypeOfExpressionParser.cs index da54eede..707919c9 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/TypeOfExpressionParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Expressions/TypeOfExpressionParser.cs @@ -8,7 +8,7 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) { iterator.Match(TokenType.OpenParen); - var type = TypeLiteral.Parse(iterator, parser); + var type = TypeLiteralParser.Parse(iterator, parser); iterator.Match(TokenType.CloseParen); diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/SignatureParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/SignatureParser.cs index 8c9b704c..f722e447 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/SignatureParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/SignatureParser.cs @@ -10,7 +10,7 @@ public static Signature Parse(Parser parser) var iterator = parser.Iterator; var nameToken = iterator.Peek(-1); - var name = new Identifier(nameToken.Text).WithRange(nameToken); + var name = new Identifier(nameToken.Text); AstNode? returnType = null; iterator.Match(TokenType.OpenParen); @@ -31,7 +31,7 @@ public static Signature Parse(Parser parser) iterator.NextToken(); } - bases.Add(TypeLiteral.Parse(iterator, parser)); + bases.Add(TypeLiteralParser.Parse(iterator, parser)); } while (iterator.IsMatch(TokenType.Comma)); //generics.Add(LNode.Call(Symbols.Where, LNode.List(genericName, LNode.Call(CodeSymbols.Base, bases)))); @@ -41,7 +41,7 @@ public static Signature Parse(Parser parser) { iterator.NextToken(); - returnType = TypeLiteral.Parse(iterator, parser); + returnType = TypeLiteralParser.Parse(iterator, parser); } return SyntaxTree.Signature(name, returnType, parameters, generics); diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/BreakStatementParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/BreakStatementParser.cs index 2622842a..5c7b9134 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/BreakStatementParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/BreakStatementParser.cs @@ -1,5 +1,5 @@ using Socordia.CodeAnalysis.AST; -using Socordia.CodeAnalysis.AST.Statements; +using Socordia.CodeAnalysis.AST.Statements.Loops; namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Statements; @@ -10,6 +10,6 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) var keywordToken = iterator.Prev; iterator.Match(TokenType.Semicolon); - return new BreakStatement().WithRange(keywordToken, iterator.Prev); + return new BreakStatement(); } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/ExpressionStatementParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/ExpressionStatementParser.cs index 0e987b51..7a062602 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/ExpressionStatementParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/ExpressionStatementParser.cs @@ -10,6 +10,6 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) iterator.Match(TokenType.Semicolon); - return expr.WithRange(expr.Range.StartIndex, iterator.Prev.End); + return expr; } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/IfStatementParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/IfStatementParser.cs index 912efd0b..a4a81679 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/IfStatementParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/IfStatementParser.cs @@ -10,7 +10,7 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) var keywordToken = iterator.Prev; var cond = Expression.Parse(parser); var body = Statement.ParseOneOrBlock(parser); - AstNode? elseBlock = new Block([]); + Block elseBlock = new Block([]); if (iterator.Current.Type == TokenType.Else) { @@ -19,6 +19,6 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) elseBlock = Statement.ParseOneOrBlock(parser); } - return SyntaxTree.If(cond, body, elseBlock).WithRange(keywordToken, iterator.Prev); + return SyntaxTree.If(cond, body, elseBlock); } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/ImportStatementParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/ImportStatementParser.cs index dce855cb..fa2f0a74 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/ImportStatementParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/ImportStatementParser.cs @@ -13,6 +13,6 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) iterator.Match(TokenType.Semicolon); - return tree.WithRange(keywordToken, iterator.Prev); + return tree; } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/ContinueStatementParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/ContinueStatementParser.cs index 028de8b8..faae7569 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/ContinueStatementParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/ContinueStatementParser.cs @@ -1,5 +1,5 @@ using Socordia.CodeAnalysis.AST; -using Socordia.CodeAnalysis.AST.Statements; +using Socordia.CodeAnalysis.AST.Statements.Loops; namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Statements.Loops; @@ -10,6 +10,6 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) var keywordToken = iterator.Prev; iterator.Match(TokenType.Semicolon); - return new ContinueStatement().WithRange(keywordToken, iterator.Prev); + return new ContinueStatement(); } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/DoWhileStatementParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/DoWhileStatementParser.cs index 2082744f..250dad52 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/DoWhileStatementParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/DoWhileStatementParser.cs @@ -16,7 +16,6 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) iterator.Match(TokenType.Semicolon); - return SyntaxTree.DoWhile(body, cond) - .WithRange(keywordToken, iterator.Prev); + return SyntaxTree.DoWhile(body, cond); } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/ForStatement.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/ForStatement.cs index 4b40a1b2..b5f5dbad 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/ForStatement.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/ForStatement.cs @@ -1,23 +1,24 @@ -using Loyc.Syntax; +using Socordia.CodeAnalysis.AST; +using Socordia.CodeAnalysis.AST.TypeNames; namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Statements.Loops; public sealed class ForStatement : IParsePoint { - public static LNode Parse(TokenIterator iterator, Parser parser) + public static AstNode 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; + TypeName type = null; if (iterator.Current.Type == TokenType.Colon) { iterator.NextToken(); - type = TypeLiteral.Parse(iterator, parser); + type = TypeLiteralParser.Parse(iterator, parser); } iterator.Match(TokenType.In); @@ -25,7 +26,6 @@ public static LNode Parse(TokenIterator iterator, Parser parser) var collExpr = Expression.Parse(parser); var body = Statement.ParseOneOrBlock(parser); - return SyntaxTree.For(SyntaxTree.Factory.Tuple(varExpr, type), collExpr, body) - .WithRange(keywordToken, iterator.Prev); + return SyntaxTree.For(varExpr, type, collExpr, body); } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/WhileStatementParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/WhileStatementParser.cs index c8abacd3..af470cb7 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/WhileStatementParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Loops/WhileStatementParser.cs @@ -11,6 +11,6 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) var cond = Expression.Parse(parser); var body = Statement.ParseOneOrBlock(parser); - return SyntaxTree.While(cond, body).WithRange(keywordToken, iterator.Prev); + return SyntaxTree.While(cond, body); } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/MacroBlockStatement.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/MacroBlockStatement.cs index 6de63b03..d6d1b818 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/MacroBlockStatement.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/MacroBlockStatement.cs @@ -1,7 +1,6 @@ -using Loyc.Syntax; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Statements; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Statements; +/* public sealed class MacroBlockStatement : IParsePoint { public static LNode Parse(TokenIterator iterator, Parser parser) @@ -45,4 +44,5 @@ public static LNode Parse(TokenIterator iterator, Parser parser) return ExpressionStatementParser.Parse(iterator, parser); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Statement.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Statement.cs index a05907fd..e6ee0359 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Statement.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/Statement.cs @@ -16,7 +16,7 @@ public static Block ParseBlock(Parser parser) parser.Iterator.Match(TokenType.CloseCurly); - return (Block)new Block(body).WithRange(openCurlyToken, parser.Iterator.Prev); + return new Block(body); } public static Block ParseOneOrBlock(Parser parser) @@ -28,6 +28,6 @@ public static Block ParseOneOrBlock(Parser parser) var node = parser.InvokeStatementParsePoint(); - return new Block([node]).WithRange(node.Range); + return new Block([node]); } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/SwitchStatement.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/SwitchStatement.cs index 8f6f8c95..bd4fcc1e 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/SwitchStatement.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/SwitchStatement.cs @@ -1,9 +1,6 @@ -using Loyc; -using Loyc.Syntax; -using Socordia.CodeAnalysis.Core; - -namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Statements; +namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Statements; +/* public sealed class SwitchStatement : IParsePoint { /* @@ -17,7 +14,7 @@ public sealed class SwitchStatement : IParsePoint * default: { block; } * } */ - +/* public static LNode Parse(TokenIterator iterator, Parser parser) { var keywordToken = iterator.Prev; @@ -164,4 +161,5 @@ private static LNode ParseWhen(Parser parser, bool autoBreak) return SyntaxTree.When(binOp, right, body); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/ThrowStatementParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/ThrowStatementParser.cs index c1b0e60b..e833f3a2 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/ThrowStatementParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/ThrowStatementParser.cs @@ -13,7 +13,7 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) var arg = Expression.Parse(parser); iterator.Match(TokenType.Semicolon); - return SyntaxTree.Throw(arg).WithRange(keywordToken, iterator.Prev); + return SyntaxTree.Throw(arg); } return null; diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/TryStatementParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/TryStatementParser.cs index b984ebec..be8de994 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/TryStatementParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/TryStatementParser.cs @@ -34,8 +34,7 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) finallly = Statement.ParseOneOrBlock(parser); } - return SyntaxTree.Try(body, catches, finallly) - .WithRange(keywordToken, iterator.Prev); + return SyntaxTree.Try(body, catches, finallly); } private static CatchStatement ParseCatch(Parser parser) diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/VariableStatementParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/VariableStatementParser.cs index bb11be9a..4e5ec933 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/VariableStatementParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/VariableStatementParser.cs @@ -1,6 +1,6 @@ -using Loyc.Syntax; -using Socordia.CodeAnalysis.AST; +using Socordia.CodeAnalysis.AST; using Socordia.CodeAnalysis.AST.Statements; +using Socordia.CodeAnalysis.AST.TypeNames; namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Statements; @@ -11,7 +11,7 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) var keywordToken = iterator.Prev; var isMutable = false; - var type = SyntaxTree.Type("", LNode.List()); + TypeName? type = null; Token mutableToken = null; @@ -27,7 +27,7 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) { iterator.NextToken(); - type = TypeLiteral.Parse(iterator, parser); + type = TypeLiteralParser.Parse(iterator, parser); } AstNode initilizer = null; @@ -40,7 +40,6 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) iterator.Match(TokenType.Semicolon); - return new VariableStatement(nameToken.Text, type, initilizer, isMutable) - .WithRange(keywordToken, iterator.Prev); + return new VariableStatement(nameToken.Text, type, initilizer, isMutable); } } \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/TypeLiteral.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/TypeLiteralParser.cs similarity index 72% rename from NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/TypeLiteral.cs rename to NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/TypeLiteralParser.cs index 09c16aea..5eb43b8d 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/TypeLiteral.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/TypeLiteralParser.cs @@ -1,36 +1,33 @@ using Loyc.Syntax; -using Socordia.CodeAnalysis.AST; +using Socordia.CodeAnalysis.AST.TypeNames; using Socordia.CodeAnalysis.Core; namespace Socordia.CodeAnalysis.Parsing.ParsePoints; -public sealed class TypeLiteral +public sealed class TypeLiteralParser { - public static AstNode Parse(TokenIterator iterator, Parser parser) + public static TypeName Parse(TokenIterator iterator, Parser parser) { - LNode typeNode; + TypeName typeNode; var typeToken = iterator.Current; if (iterator.IsMatch(TokenType.Identifier)) { var typename = iterator.Match(TokenType.Identifier).Text; - var args = new LNodeList(); + var args = new List(); - typeNode = SyntaxTree.Type(typename, []).WithRange(typeToken); + typeNode = new SimpleTypeName(typename); if (iterator.IsMatch(TokenType.Star)) { - iterator.NextToken(); - - typeNode = SyntaxTree.Pointer(typeNode).WithRange(typeToken, iterator.Prev); + typeNode = new PointerTypeName(typeNode, PointerKind.Transient); } if (iterator.IsMatch(TokenType.Ampersand)) { - iterator.NextToken(); - - typeNode = SyntaxTree.RefType(typeNode).WithRange(typeToken, iterator.Prev); + typeNode = new PointerTypeName(typeNode, PointerKind.Reference); } + /* else if (iterator.IsMatch(TokenType.Questionmark)) { iterator.NextToken(); @@ -40,39 +37,40 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) else if (iterator.IsMatch(TokenType.OpenSquare)) { typeNode = ParseArrayType(iterator, typeNode, typeToken); - } + }*/ else if (iterator.IsMatch(TokenType.LessThan)) { - typeNode = ParseGenericType(iterator, parser, typeToken, typename, args); + typeNode = ParseGenericType(iterator, parser, typename, args); } } else if (iterator.IsMatch(TokenType.None)) { - typeNode = SyntaxTree.Type("none", LNode.List()).WithRange(typeToken); + typeNode = new SimpleTypeName("none"); 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 + TokenIterator.GetTokenRepresentation(iterator.Current.Type))); - typeNode = LNode.Missing; + typeNode = null; iterator.NextToken(); } return typeNode; } - public static bool TryParse(Parser parser, out LNode node) + public static bool TryParse(Parser parser, out TypeName node) { var cursor = parser.Iterator.Position; node = Parse(parser.Iterator, parser); - if (node == LNode.Missing) + if (node == null) { parser.Iterator.Position = cursor; return false; @@ -80,13 +78,13 @@ public static bool TryParse(Parser parser, out LNode node) return true; } - +/* private static LNode ParseFunctionOrTupleType(TokenIterator iterator, Parser parser, Token typeToken) { LNode typeNode; iterator.Match(TokenType.OpenParen); - var parameters = new LNodeList(); + var parameters = new List(); while (parser.Iterator.Current.Type != TokenType.CloseParen) { parameters.Add(Parse(iterator, parser)); @@ -106,21 +104,20 @@ private static LNode ParseFunctionOrTupleType(TokenIterator iterator, Parser par 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); + LNode.List(returnType, LNode.Missing, LNode.Call(CodeSymbols.AltList, parameters))); } else { - typeNode = SyntaxTree.Factory.Tuple(parameters).WithRange(typeToken, iterator.Prev); + typeNode = SyntaxTree.Factory.Tuple(parameters); } return typeNode; } - - private static LNode ParseGenericType(TokenIterator iterator, Parser parser, Token typeToken, string typename, - LNodeList args) +*/ + private static TypeName ParseGenericType(TokenIterator iterator, Parser parser, string typename, + List args) { - LNode typeNode; + TypeName typeNode; iterator.NextToken(); while (!iterator.IsMatch(TokenType.GreaterThan)) @@ -138,7 +135,7 @@ private static LNode ParseGenericType(TokenIterator iterator, Parser parser, Tok iterator.Match(TokenType.GreaterThan); - typeNode = SyntaxTree.Type(typename, args).WithRange(typeToken, parser.Iterator.Prev); + typeNode = new GenericTypeName(typename, args); return typeNode; } diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/Parser.Expressions.cs b/NewSource/Socordia.CodeAnalysis/Parsing/Parser.Expressions.cs index d1cb46de..cecf98c3 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/Parser.Expressions.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/Parser.Expressions.cs @@ -1,27 +1,28 @@ +using DistIL.AsmIO; using Loyc; using Loyc.Syntax; using Socordia.CodeAnalysis.AST; using Socordia.CodeAnalysis.AST.Literals; using Socordia.CodeAnalysis.Core; +using Socordia.CodeAnalysis.Parsing.ParsePoints; using LiteralNode = Socordia.CodeAnalysis.AST.Literals.LiteralNode; namespace Socordia.CodeAnalysis.Parsing; public sealed partial class Parser { - private readonly Dictionary _literals = new() + private readonly Dictionary _literals = 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 } + { "ub", PrimType.Byte }, + { "us", PrimType.UInt16 }, + { "u", PrimType.UInt32 }, + { "ui", PrimType.UInt32 }, + { "ul", PrimType.UInt64 }, + { "b", PrimType.SByte }, + { "s", PrimType.Int16 }, + { "l", PrimType.Int64 }, + { "f", PrimType.Single }, + { "d", PrimType.Double } }; public void AddError(LocalizableString message, SourceRange range) @@ -35,7 +36,7 @@ public void AddError(LocalizableString message) new SourceRange(Document, Iterator.Current.Start, Iterator.Current.Text.Length))); } - internal AstNode? ParsePrimary(ParsePoints? parsePoints = null) + internal AstNode? ParsePrimary(ParsePointCollection? parsePoints = null) { parsePoints ??= ExpressionParsePoints; @@ -60,10 +61,10 @@ private AstNode ParseArrayLiteral() var elements = Expression.ParseList(this, TokenType.CloseSquare); - return new ArrayLiteral(elements).WithRange(startToken, Iterator.Prev); + return new ArrayLiteral(elements); } - private AstNode? InvokeExpressionParsePoint(ParsePoints parsePoints) + private AstNode? InvokeExpressionParsePoint(ParsePointCollection parsePoints) { var token = Iterator.Current; var type = token.Type; @@ -72,7 +73,7 @@ private AstNode ParseArrayLiteral() { Iterator.NextToken(); - return value(Iterator, this).WithRange(token, Iterator.Prev); + return value(Iterator, this); } AddError(ErrorID.UnknownExpression); @@ -90,14 +91,14 @@ private AstNode ParseArrayLiteral() return null; } - return new LiteralNode(result).WithRange(Iterator.Prev); + return new LiteralNode(result); } private AstNode ParseBooleanLiteral(bool value) { Iterator.NextToken(); - return new LiteralNode(value).WithRange(Iterator.Prev); + return new LiteralNode(value); } private AstNode ParseChar() @@ -132,7 +133,7 @@ private AstNode ParseNumber() { var value = ParseHelpers.TryParseDouble(ref text, 10, ParseNumberFlag.SkipUnderscores); - result = new LiteralNode(value).WithRange(Iterator.Prev); + result = new LiteralNode(value); } else { @@ -144,7 +145,7 @@ private AstNode ParseNumber() } else { - result = new LiteralNode(value).WithRange(Iterator.Prev); + result = new LiteralNode(value); } } @@ -152,7 +153,7 @@ private AstNode ParseNumber() { if (_literals.TryGetValue(Iterator.Current.Text.ToLower(), out var value)) { - result = new LiteralNode(result).WithRange(Iterator.Prev, Iterator.Current); + result = new LiteralNode(result); } else { @@ -170,8 +171,7 @@ private AstNode ParseNumber() var unit = Iterator.Match(TokenType.Identifier); - result = SyntaxTree.Unit(result, unit.Text) - .WithRange(token, Iterator.Prev); + result = SyntaxTree.Unit(result, unit.Text); Iterator.Match(TokenType.GreaterThan); } diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/Parser.ParsePoints.cs b/NewSource/Socordia.CodeAnalysis/Parsing/Parser.ParsePoints.cs index c2a5e17c..c7c3a6cd 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/Parser.ParsePoints.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/Parser.ParsePoints.cs @@ -1,38 +1,43 @@ using Loyc.Syntax; using Socordia.CodeAnalysis.AST; using Socordia.CodeAnalysis.Core; +using Socordia.CodeAnalysis.Parsing.ParsePoints; +using Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; +using Socordia.CodeAnalysis.Parsing.ParsePoints.Expressions; +using Socordia.CodeAnalysis.Parsing.ParsePoints.Statements; +using Socordia.CodeAnalysis.Parsing.ParsePoints.Statements.Loops; namespace Socordia.CodeAnalysis.Parsing; public sealed partial class Parser { - public readonly ParsePoints DeclarationParsePoints = new(); - public readonly ParsePoints ExpressionParsePoints = new(); - public readonly ParsePoints StatementParsePoints = new(); + public readonly ParsePointCollection DeclarationParsePoints = new(); + public readonly ParsePointCollection ExpressionParsePoints = new(); + public readonly ParsePointCollection StatementParsePoints = new(); public void InitParsePoints() { - AddDeclarationParsePoint(TokenType.Bitfield); - AddDeclarationParsePoint(TokenType.Union); - AddDeclarationParsePoint(TokenType.Class); - AddDeclarationParsePoint(TokenType.Constructor); + //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.Implement);*/ AddDeclarationParsePoint(TokenType.Import); - AddDeclarationParsePoint(TokenType.Struct); + // AddDeclarationParsePoint(TokenType.Struct); AddDeclarationParsePoint(TokenType.Module); - AddDeclarationParsePoint(TokenType.Using); + AddDeclarationParsePoint(TokenType.Using); AddDeclarationParsePoint(TokenType.Unit); - AddDeclarationParsePoint(TokenType.Identifier); + // AddDeclarationParsePoint(TokenType.Identifier); AddExpressionParsePoint(TokenType.Identifier); AddExpressionParsePoint(TokenType.OpenParen); - AddExpressionParsePoint(TokenType.Match); + // AddExpressionParsePoint(TokenType.Match); AddExpressionParsePoint(TokenType.Default); AddExpressionParsePoint(TokenType.SizeOf); AddExpressionParsePoint(TokenType.TypeOf); @@ -44,13 +49,13 @@ public void InitParsePoints() AddStatementParsePoint(TokenType.Continue); AddStatementParsePoint(TokenType.Return); AddStatementParsePoint(TokenType.Let); - AddStatementParsePoint(TokenType.Switch); + // AddStatementParsePoint(TokenType.Switch); AddStatementParsePoint(TokenType.If); AddStatementParsePoint(TokenType.While); AddStatementParsePoint(TokenType.Do); AddStatementParsePoint(TokenType.Try); AddStatementParsePoint(TokenType.For); - AddStatementParsePoint(TokenType.Identifier); + //AddStatementParsePoint(TokenType.Identifier); } public void AddDeclarationParsePoint(TokenType type) @@ -71,7 +76,7 @@ public void AddStatementParsePoint(TokenType type) StatementParsePoints.Add(type, T.Parse); } - public List InvokeDeclarationParsePoints(TokenType terminator = TokenType.EOF, ParsePoints parsePoints = null) + public List InvokeDeclarationParsePoints(TokenType terminator = TokenType.EOF, ParsePointCollection parsePoints = null) { if (parsePoints == null) { @@ -100,7 +105,7 @@ public List InvokeDeclarationParsePoints(TokenType terminator = Tok return declarations; } - public AstNode? InvokeParsePoint(ParsePoints parsePoints) + public AstNode? InvokeParsePoint(ParsePointCollection parsePoints) { var type = Iterator.Current.Type; diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/SyntaxTree.cs b/NewSource/Socordia.CodeAnalysis/Parsing/SyntaxTree.cs index bf7cde5a..d567d208 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/SyntaxTree.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/SyntaxTree.cs @@ -5,6 +5,9 @@ using Socordia.CodeAnalysis.AST.Expressions; using Socordia.CodeAnalysis.AST.Literals; using Socordia.CodeAnalysis.AST.Statements; +using Socordia.CodeAnalysis.AST.Statements.Loops; +using Socordia.CodeAnalysis.AST.TypeNames; +using Socordia.CodeAnalysis.Parsing.ParsePoints; using LiteralNode = Socordia.CodeAnalysis.AST.Literals.LiteralNode; namespace Socordia.CodeAnalysis.Parsing; @@ -61,14 +64,14 @@ public static AstNode Throw(AstNode arg) return new ThrowStatement(arg); } - public static LNode ArrayInstantiation(LNodeList elements) + public static AstNode ArrayInstantiation(List elements) { - return Factory.Call(CodeSymbols.Braces, elements); + return new CollectionExpression(elements); } public static AstNode ArrayInstantiation(AstNode arr, List indices) { - return arr.WithArgs(indices); + return arr; //.WithArgs(indices); } public static AstNode Binary(Symbol op, AstNode left, AstNode right) @@ -91,13 +94,9 @@ public static CatchStatement Catch(Identifier exceptionType, Identifier exceptio return new CatchStatement(exceptionType, exceptionValueName, body); } - public static LNode Class(Token nameToken, LNodeList inheritances, LNodeList members) + public static AstNode Class(Token nameToken, List inheritances, List members) { - return Factory.Call(CodeSymbols.Class, - LNode.List( - Factory.FromToken(nameToken), - Factory.Call(Symbols.Inheritance, inheritances), - Factory.Call(CodeSymbols.Braces, members).SetStyle(NodeStyle.StatementBlock))); + return new ClassDeclaration(nameToken.Text, inheritances, members); } public static AstNode Default(AstNode? type = null) @@ -113,14 +112,9 @@ public static LNode Enum(LNode name, LNodeList members) members))); } - public static LNode For(LNode init, LNode arr, LNode body) + public static AstNode For(AstNode varExpr, AstNode type, AstNode arr, Block 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)); + return new ForStatement(varExpr, type, arr, body); } public static AstNode If(AstNode cond, Block ifBody, Block elseBody) @@ -206,15 +200,9 @@ public static AstNode Try(Block body, List catches, Block? final return new TryStatement(body, catches, 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 AstNode Unary(Symbol op, AstNode operand) + public static AstNode Unary(string op, AstNode operand, UnaryOperatorKind kind) { - return new UnaryOperator(op, operand); + return new UnaryOperator(op, operand, kind); } public static LNode Union(string name, LNodeList members) diff --git a/NewSource/Socordia.CodeAnalysis/Socordia.CodeAnalysis.csproj b/NewSource/Socordia.CodeAnalysis/Socordia.CodeAnalysis.csproj index d2370e7a..62920888 100644 --- a/NewSource/Socordia.CodeAnalysis/Socordia.CodeAnalysis.csproj +++ b/NewSource/Socordia.CodeAnalysis/Socordia.CodeAnalysis.csproj @@ -5,6 +5,7 @@ + diff --git a/NewSource/SocordiaC/Core/ExtensionUtils.cs b/NewSource/SocordiaC/Core/ExtensionUtils.cs deleted file mode 100644 index cf9e9042..00000000 --- a/NewSource/SocordiaC/Core/ExtensionUtils.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Loyc.Syntax; - -namespace SocordiaC.Core; - -public static class ExtensionUtils -{ - public static LNode dot(this string s, string other) - { - return LNode.Call(CodeSymbols.Dot, LNode.List(LNode.Id(s), LNode.Id(other))).SetStyle(NodeStyle.Operator); - } - - public static LNode dot(this LNode n, string other) - { - return LNode.Call(CodeSymbols.Dot, LNode.List(n, LNode.Id(other))).SetStyle(NodeStyle.Operator); - } - - public static LNode dot(this string s, LNode other) - { - return LNode.Call(CodeSymbols.Dot, LNode.List(LNode.Id(s), other)).SetStyle(NodeStyle.Operator); - } - - public static LNode dot(this LNode n, LNode other) - { - return LNode.Call(CodeSymbols.Dot, LNode.List(n, other)).SetStyle(NodeStyle.Operator); - } - - public static LNode coloncolon(this string s, string other) - { - return LNode.Call(Symbols.ColonColon, LNode.List(LNode.Id(s), LNode.Id(other))).SetStyle(NodeStyle.Operator); - } - - public static LNode coloncolon(this LNode n, string other) - { - return LNode.Call(Symbols.ColonColon, LNode.List(n, LNode.Id(other))).SetStyle(NodeStyle.Operator); - } - - public static LNode coloncolon(this string s, LNode other) - { - return LNode.Call(Symbols.ColonColon, LNode.List(LNode.Id(s), other)).SetStyle(NodeStyle.Operator); - } - - public static LNode coloncolon(this LNode n, LNode other) - { - return LNode.Call(Symbols.ColonColon, LNode.List(n, other)).SetStyle(NodeStyle.Operator); - } -} \ No newline at end of file diff --git a/NewSource/SocordiaC/Core/LNodeDeconstructors.cs b/NewSource/SocordiaC/Core/LNodeDeconstructors.cs deleted file mode 100644 index b1176d90..00000000 --- a/NewSource/SocordiaC/Core/LNodeDeconstructors.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Loyc.Syntax; - -namespace SocordiaC.Core; - -public static class LNodeDeconstructors -{ - public static void Deconstruct(this LNode node, out string name, out LNode a0) - { - name = node.Name.Name; - a0 = node.Args.Count >= 1 ? node.Args[0] : LNode.Missing; - } - - public static void Deconstruct(this LNode node, out string name, out LNode a0, out LNode a1) - { - name = node.Name.Name; - - a0 = node.Args.Count >= 1 ? node.Args[0] : LNode.Missing; - a1 = node.Args.Count >= 2 ? node.Args[1] : LNode.Missing; - } - - public static void Deconstruct(this LNode node, out string name, out LNode a0, out LNode a1, out LNode a2) - { - name = node.Name.Name; - - a0 = node.Args.Count >= 1 ? node.Args[0] : LNode.Missing; - a1 = node.Args.Count >= 2 ? node.Args[1] : LNode.Missing; - a2 = node.Args.Count >= 3 ? node.Args[2] : LNode.Missing; - } -} \ No newline at end of file diff --git a/NewSource/SocordiaC/Core/Semantic/Checks/ImportCheck.cs b/NewSource/SocordiaC/Core/Semantic/Checks/ImportCheck.cs index 28f711bd..411d1d0e 100644 --- a/NewSource/SocordiaC/Core/Semantic/Checks/ImportCheck.cs +++ b/NewSource/SocordiaC/Core/Semantic/Checks/ImportCheck.cs @@ -4,6 +4,7 @@ namespace SocordiaC.Core.Semantic.Checks; +/* internal class ImportCheck : ISemanticCheck { public void Check(CompilationUnit tree, Driver context) @@ -19,4 +20,5 @@ public void Check(CompilationUnit tree, Driver context) } } } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/SocordiaC/Core/Semantic/Checks/InterfaceNameCheck.cs b/NewSource/SocordiaC/Core/Semantic/Checks/InterfaceNameCheck.cs index 5256ae2e..6c8b02aa 100644 --- a/NewSource/SocordiaC/Core/Semantic/Checks/InterfaceNameCheck.cs +++ b/NewSource/SocordiaC/Core/Semantic/Checks/InterfaceNameCheck.cs @@ -4,6 +4,7 @@ namespace SocordiaC.Core.Semantic.Checks; +/* internal class InterfaceNameCheck : ISemanticCheck { public void Check(CompilationUnit tree, Driver context) @@ -31,4 +32,5 @@ public void Check(CompilationUnit tree, Driver context) } } } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/SocordiaC/Core/Semantic/Checks/ModifierCheck.cs b/NewSource/SocordiaC/Core/Semantic/Checks/ModifierCheck.cs index 66038db3..b6009f66 100644 --- a/NewSource/SocordiaC/Core/Semantic/Checks/ModifierCheck.cs +++ b/NewSource/SocordiaC/Core/Semantic/Checks/ModifierCheck.cs @@ -3,6 +3,7 @@ namespace SocordiaC.Core.Semantic.Checks; +/* internal class ModifierCheck : ISemanticCheck { public void Check(CompilationUnit tree, Driver context) @@ -36,4 +37,5 @@ private bool IsModifiableNode(LNode arg) return arg.Calls(CodeSymbols.Class) || arg.Calls(CodeSymbols.Struct) || arg.Calls(CodeSymbols.Fn) || arg.Calls(Symbols.Bitfield); } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/SocordiaC/Core/Semantic/Checks/ModuleDefinitionCheck.cs b/NewSource/SocordiaC/Core/Semantic/Checks/ModuleDefinitionCheck.cs index fa344967..e0d9d682 100644 --- a/NewSource/SocordiaC/Core/Semantic/Checks/ModuleDefinitionCheck.cs +++ b/NewSource/SocordiaC/Core/Semantic/Checks/ModuleDefinitionCheck.cs @@ -4,6 +4,7 @@ namespace SocordiaC.Core.Semantic.Checks; +/* internal class ModuleDefinitionCheck : ISemanticCheck { public void Check(CompilationUnit tree, Driver context) @@ -15,4 +16,5 @@ public void Check(CompilationUnit tree, Driver context) context.Messages.Add(Message.Warning("A module definition is already defined", moduleDefinition.Range)); } } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/SocordiaC/Core/Semantic/Checks/TypenameCheck.cs b/NewSource/SocordiaC/Core/Semantic/Checks/TypenameCheck.cs index eda2ddf1..1327d5a7 100644 --- a/NewSource/SocordiaC/Core/Semantic/Checks/TypenameCheck.cs +++ b/NewSource/SocordiaC/Core/Semantic/Checks/TypenameCheck.cs @@ -4,6 +4,7 @@ namespace SocordiaC.Core.Semantic.Checks; +/* internal class TypenameCheck : ISemanticCheck { public void Check(CompilationUnit tree, Driver context) @@ -22,4 +23,5 @@ public void Check(CompilationUnit tree, Driver context) } } } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/NewSource/SocordiaC/Core/Semantic/SemanticChecker.cs b/NewSource/SocordiaC/Core/Semantic/SemanticChecker.cs index 7ff2c607..13c489d1 100644 --- a/NewSource/SocordiaC/Core/Semantic/SemanticChecker.cs +++ b/NewSource/SocordiaC/Core/Semantic/SemanticChecker.cs @@ -7,11 +7,12 @@ public static class SemanticChecker { private static readonly List SemanticChecks = [ - new ModuleDefinitionCheck(), + /* new ModuleDefinitionCheck(), new ImportCheck(), new TypenameCheck(), new ModifierCheck(), new InterfaceNameCheck() + */ ]; public static void Do(CompilationUnit tree, Driver context) diff --git a/NewSource/SocordiaC/Core/SyntacticMacros.cs b/NewSource/SocordiaC/Core/SyntacticMacros.cs index 2bb51c25..88d2710d 100644 --- a/NewSource/SocordiaC/Core/SyntacticMacros.cs +++ b/NewSource/SocordiaC/Core/SyntacticMacros.cs @@ -30,9 +30,7 @@ public static class SyntacticMacros ["addrof"] = ("AddressOf", 2), ["percent"] = ("Percentage", 1) }; - - private static readonly LNodeFactory F = new(EmptySourceFile.Synthetic); - + /* [LexicalMacro("constructor()", "Convert constructor() to .ctor() function", "#constructor", Mode = MacroMode.MatchIdentifierOrCall)] public static LNode Constructor(LNode node, IMacroContext context) @@ -354,4 +352,5 @@ private static LNode ConvertToAssignment(LNode node, Symbol symbol) return factory.Call(CodeSymbols.Assign, arg1, factory.Call(symbol, arg1, arg2)); } + */ } \ No newline at end of file