├── demos
├── FizzBuzz
│ ├── Program.cs
│ ├── README.md
│ └── FizzBuzz.csproj
├── HelloWorld
│ ├── README.md
│ ├── Program.c♯
│ └── HelloWorld.csproj
├── Sandbox
│ ├── Program.cs
│ ├── README.md
│ ├── MyClass.c♯
│ └── Sandbox.csproj
└── WebAPI
│ ├── WebAPI.http
│ ├── appsettings.Development.json
│ ├── appsettings.json
│ ├── README.md
│ ├── Program.cs
│ ├── Properties
│ └── launchSettings.json
│ ├── Services
│ ├── Abstractions
│ │ └── ITestService.c♯
│ └── Implementations
│ │ └── TestService.c♯
│ ├── WebAPI.csproj
│ └── Models
│ └── TestModel.c♯
├── src
└── Csml
│ ├── Parser
│ ├── Nodes
│ │ ├── Expressions
│ │ │ ├── NotNode.cs
│ │ │ ├── OrNode.cs
│ │ │ ├── AddNode.cs
│ │ │ ├── AndNode.cs
│ │ │ ├── XorNode.cs
│ │ │ ├── DivideNode.cs
│ │ │ ├── EqualsNode.cs
│ │ │ ├── AssignmentNode.cs
│ │ │ ├── BitwiseAndNode.cs
│ │ │ ├── BitwiseNotNode.cs
│ │ │ ├── BitwiseOrNode.cs
│ │ │ ├── ExpressionNode.cs
│ │ │ ├── LeftShiftNode.cs
│ │ │ ├── LessThanNode.cs
│ │ │ ├── MultiplyNode.cs
│ │ │ ├── NotEqualsNode.cs
│ │ │ ├── RemainderNode.cs
│ │ │ ├── RightShiftNode.cs
│ │ │ ├── SubtractNode.cs
│ │ │ ├── DecrementNode.cs
│ │ │ ├── GreaterThanNode.cs
│ │ │ ├── IncrementNode.cs
│ │ │ ├── LessThanOrEqualNode.cs
│ │ │ ├── PrefixDecrementNode.cs
│ │ │ ├── PrefixIncrementNode.cs
│ │ │ ├── GreaterThanOrEqualNode.cs
│ │ │ ├── UnsignedRightShiftNode.cs
│ │ │ ├── ValueNode.cs
│ │ │ ├── AwaitNode.cs
│ │ │ ├── UnaryValueExpressionNode.cs
│ │ │ ├── UnaryExpressionNode.cs
│ │ │ ├── NewNode.cs
│ │ │ └── BinaryExpressionNode.cs
│ │ ├── Members
│ │ │ ├── ConstructorNode.cs
│ │ │ ├── PropertyGetterAccessor.cs
│ │ │ ├── ArgumentNode.cs
│ │ │ ├── PropertySetterAccessor.cs
│ │ │ ├── EnumValue.cs
│ │ │ ├── ParameterModifier.cs
│ │ │ ├── ParameterNode.cs
│ │ │ ├── MethodBaseNode.cs
│ │ │ ├── FieldNode.cs
│ │ │ ├── MemberNode.cs
│ │ │ ├── PropertyNode.cs
│ │ │ └── MethodNode.cs
│ │ ├── Statements
│ │ │ ├── BlockNode.cs
│ │ │ ├── DefaultNode.cs
│ │ │ ├── ThrowNode.cs
│ │ │ ├── BreakNode.cs
│ │ │ ├── ElseIfNode.cs
│ │ │ ├── ContinueNode.cs
│ │ │ ├── ElseNode.cs
│ │ │ ├── TryNode.cs
│ │ │ ├── CaseNode.cs
│ │ │ ├── FinallyNode.cs
│ │ │ ├── ReturnNode.cs
│ │ │ ├── WhileNode.cs
│ │ │ ├── CatchNode.cs
│ │ │ ├── SwitchNode.cs
│ │ │ ├── IfNode.cs
│ │ │ ├── ForEachNode.cs
│ │ │ ├── CallNode.cs
│ │ │ ├── VariableNode.cs
│ │ │ ├── ForNode.cs
│ │ │ ├── StatementContainerNode.cs
│ │ │ └── ExpressionStatementNode.cs
│ │ ├── Types
│ │ │ ├── InheritanceNode.cs
│ │ │ ├── InterfaceNode.cs
│ │ │ ├── ClassNode.cs
│ │ │ ├── UsingDirectiveNode.cs
│ │ │ ├── StructNode.cs
│ │ │ ├── EnumNode.cs
│ │ │ ├── NamespaceNode.cs
│ │ │ └── TypeNode.cs
│ │ ├── CsmlNode.cs
│ │ ├── BaseNode.cs
│ │ └── AccessModifier.cs
│ ├── CsmlConstants.cs
│ ├── CsmlParseResult.cs
│ ├── CsmlParseError.cs
│ ├── ObjectValidator.cs
│ └── CsmlParser.cs
│ ├── AssemblyInfo.cs
│ ├── AnalyzerReleases.Shipped.md
│ ├── Generator
│ └── SyntaxBuilders
│ │ ├── Statements
│ │ ├── BreakBuilder.cs
│ │ ├── ContinueBuilder.cs
│ │ ├── ThrowBuilder.cs
│ │ ├── ReturnBuilder.cs
│ │ ├── WhileBuilder.cs
│ │ ├── ForEachBuilder.cs
│ │ ├── ArgumentListBuilder.cs
│ │ ├── ForBuilder.cs
│ │ ├── VariableBuilder.cs
│ │ ├── CallBuilder.cs
│ │ ├── SwitchBuilder.cs
│ │ ├── IfBuilder.cs
│ │ └── TryBuilder.cs
│ │ ├── CsmlBuilder.cs
│ │ ├── UsingDirectiveBuilder.cs
│ │ ├── NamespaceBuilder.cs
│ │ ├── Members
│ │ ├── ParameterBuilder.cs
│ │ └── ConstructorBuilder.cs
│ │ └── BlockBuilder.cs
│ ├── Exceptions
│ ├── UnknownCsmlElementException.cs
│ ├── UnknownCsmlAttributeException.cs
│ ├── UnexpectedCsmlPermutationException.cs
│ ├── CsmlParseException.cs
│ └── InvalidAccessorException.cs
│ ├── GlobalUsings.cs
│ ├── AnalyzerReleases.Unshipped.md
│ ├── Csml.csproj
│ └── Workarounds.cs
├── tests
└── CsmlTests
│ ├── GlobalUsings.cs
│ ├── Statements
│ ├── BreakTests.cs
│ ├── ContinueTests.cs
│ ├── WhileTests.cs
│ ├── SwitchTests.cs
│ ├── ThrowTests.cs
│ └── ForEachTests.cs
│ ├── CsmlSyntaxWrapper.cs
│ ├── Expressions
│ ├── AwaitTests.cs
│ ├── ValueTests.cs
│ ├── AssignmentTests.cs
│ ├── NewTests.cs
│ └── BinaryExpressionTests.cs
│ ├── CsmlTests.csproj
│ ├── Types
│ ├── InheritanceTests.cs
│ ├── StructRefTests.cs
│ └── StructReadOnlyTests.cs
│ ├── FileExtensionTests.cs
│ ├── Members
│ ├── InterfaceMethodTests.cs
│ ├── FieldRefTests.cs
│ ├── FieldConstTests.cs
│ ├── FieldStaticTests.cs
│ ├── FieldReadOnlyTests.cs
│ ├── MethodAsyncTests.cs
│ ├── MethodStaticTests.cs
│ ├── MethodVirtualTests.cs
│ ├── MethodAbstractTests.cs
│ └── MethodOverrideTests.cs
│ ├── NamespaceTests.cs
│ ├── UsingDirectiveTests.cs
│ └── Helpers
│ └── CompilationHelper.cs
├── documentation
├── types
│ ├── property-getter-accessor.md
│ ├── property-setter-accessor.md
│ ├── access-modifiers.md
│ ├── parameter-modifier.md
│ └── expressions.md
└── tags
│ ├── break.md
│ ├── default.md
│ ├── continue.md
│ ├── return.md
│ ├── decrement.md
│ ├── increment.md
│ ├── prefix-decrement.md
│ ├── prefix-increment.md
│ ├── value.md
│ ├── throw.md
│ ├── inheritance.md
│ ├── not.md
│ ├── argument.md
│ ├── await.md
│ ├── try.md
│ ├── bitwise-not.md
│ ├── csml.md
│ ├── new.md
│ ├── using-directive.md
│ ├── case.md
│ ├── add.md
│ ├── divide.md
│ ├── equals.md
│ ├── or.md
│ ├── and.md
│ ├── less-than.md
│ ├── multiply.md
│ ├── subtract.md
│ ├── left-shift.md
│ ├── not-equals.md
│ ├── xor.md
│ ├── remainder.md
│ ├── right-shift.md
│ ├── assignment.md
│ ├── greater-than.md
│ ├── bitwise-or.md
│ ├── bitwise-and.md
│ ├── less-than-or-equal.md
│ ├── parameter.md
│ ├── greater-than-or-equal.md
│ ├── unsigned-right-shift.md
│ ├── call.md
│ ├── enum-value.md
│ ├── for-each.md
│ ├── finally.md
│ ├── variable.md
│ ├── while.md
│ ├── else.md
│ ├── catch.md
│ ├── enum.md
│ ├── interface.md
│ ├── switch.md
│ ├── if.md
│ ├── constructor.md
│ ├── else-if.md
│ ├── namespace.md
│ ├── field.md
│ ├── for.md
│ ├── property.md
│ ├── class.md
│ ├── method.md
│ ├── struct.md
│ └── block.md
├── .github
├── dependabot.yml
└── workflows
│ └── dotnet.yml
└── LICENSE
/demos/FizzBuzz/Program.cs:
--------------------------------------------------------------------------------
1 | using Demo;
2 |
3 | FizzBuzz.Run();
4 |
--------------------------------------------------------------------------------
/demos/HelloWorld/README.md:
--------------------------------------------------------------------------------
1 | # HelloWorld
2 |
3 | This project is a simple "*Hello, World!*" written in C♯ML.
4 |
--------------------------------------------------------------------------------
/demos/Sandbox/Program.cs:
--------------------------------------------------------------------------------
1 | using Sandbox;
2 |
3 | MyClass myClass = new MyClass();
4 | myClass.MyMethod();
5 |
--------------------------------------------------------------------------------
/demos/Sandbox/README.md:
--------------------------------------------------------------------------------
1 | # Sandbox
2 |
3 | This project is intended to be a sandbox for playing around with C♯ML.
4 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/NotNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class NotNode : UnaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/OrNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class OrNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/AddNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class AddNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/AndNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class AndNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/XorNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class XorNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Members/ConstructorNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Members;
2 |
3 | public class ConstructorNode : MethodBaseNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/BlockNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | public class BlockNode : StatementContainerNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/DivideNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class DivideNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/EqualsNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class EqualsNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/DefaultNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | public class DefaultNode : StatementContainerNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/ThrowNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | public class ThrowNode : ExpressionStatementNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/demos/WebAPI/WebAPI.http:
--------------------------------------------------------------------------------
1 | @WebAPI_HostAddress = http://localhost:5178
2 |
3 | GET {{WebAPI_HostAddress}}/double?input=7
4 | Accept: application/json
5 |
6 | ###
7 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/AssignmentNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class AssignmentNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/BitwiseAndNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class BitwiseAndNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/BitwiseNotNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class BitwiseNotNode : UnaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/BitwiseOrNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class BitwiseOrNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/ExpressionNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public abstract class ExpressionNode : BaseNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/LeftShiftNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class LeftShiftNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/LessThanNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class LessThanNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/MultiplyNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class MultiplyNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/NotEqualsNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class NotEqualsNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/RemainderNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class RemainderNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/RightShiftNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class RightShiftNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/SubtractNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class SubtractNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/DecrementNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class DecrementNode : UnaryValueExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/GreaterThanNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class GreaterThanNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/IncrementNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class IncrementNode : UnaryValueExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/LessThanOrEqualNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class LessThanOrEqualNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/PrefixDecrementNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class PrefixDecrementNode : UnaryValueExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/PrefixIncrementNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class PrefixIncrementNode : UnaryValueExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | // Exposes internal types as public for the testing project.
4 | [assembly: InternalsVisibleTo("CsmlTests")]
5 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/GreaterThanOrEqualNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class GreaterThanOrEqualNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/UnsignedRightShiftNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class UnsignedRightShiftNode : BinaryExpressionNode
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/demos/WebAPI/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft.AspNetCore": "Warning"
6 | }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Csml/AnalyzerReleases.Shipped.md:
--------------------------------------------------------------------------------
1 | ; Shipped analyzer releases
2 | ; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
3 |
4 |
--------------------------------------------------------------------------------
/demos/WebAPI/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft.AspNetCore": "Warning"
6 | }
7 | },
8 | "AllowedHosts": "*"
9 | }
10 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/BreakNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | ///
4 | /// Represents a break statement.
5 | ///
6 | public class BreakNode : BaseNode
7 | {
8 | }
9 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Types/InheritanceNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Types;
2 |
3 | public class InheritanceNode : BaseNode
4 | {
5 | [XmlAttribute("Type")]
6 | public required string Type { get; set; }
7 | }
8 |
--------------------------------------------------------------------------------
/demos/FizzBuzz/README.md:
--------------------------------------------------------------------------------
1 | # FizzBuzz
2 |
3 | This project is a C♯ML implementation of the game [Fizz Buzz](https://en.wikipedia.org/wiki/Fizz_buzz).
4 |
5 | This project also demonstrates interoperability between C♯ML and C#.
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/ElseIfNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | ///
4 | /// Represents an else if statement.
5 | ///
6 | public class ElseIfNode : IfNode
7 | {
8 | }
9 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/ValueNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class ValueNode : ExpressionNode
4 | {
5 | [XmlAttribute("Value")]
6 | public required string Value { get; init; }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/ContinueNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | ///
4 | /// Represents a continue statement.
5 | ///
6 | public class ContinueNode : BaseNode
7 | {
8 | }
9 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/ElseNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | ///
4 | /// Represents an else statement.
5 | ///
6 | public class ElseNode : StatementContainerNode
7 | {
8 | }
9 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/TryNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | public class TryNode : BaseNode
4 | {
5 | [XmlElement("Statements")]
6 | public required BlockNode Statements { get; init; }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/CaseNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | public class CaseNode : StatementContainerNode
4 | {
5 | [XmlAttribute("Value")]
6 | public required string Value { get; init; }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/FinallyNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | public class FinallyNode : BaseNode
4 | {
5 | [XmlElement("Statements")]
6 | public required BlockNode Statements { get; init; }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/AwaitNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class AwaitNode : ExpressionNode
4 | {
5 | [XmlElement("Expression")]
6 | public required ExpressionStatementNode Expression { get; init; }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Types/InterfaceNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Types;
2 |
3 | ///
4 | /// Represents an interface declaration.
5 | ///
6 | [XmlType("Interface")]
7 | public class InterfaceNode : TypeNode
8 | {
9 | }
10 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/UnaryValueExpressionNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public abstract class UnaryValueExpressionNode : ExpressionNode
4 | {
5 | [XmlAttribute("Target")]
6 | public required string Target { get; init; }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/Statements/BreakBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders.Statements;
2 |
3 | internal class BreakBuilder
4 | {
5 | public static BreakStatementSyntax Build()
6 | {
7 | return SF.BreakStatement();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Csml/Parser/CsmlConstants.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser;
2 |
3 | ///
4 | /// Contains general constant- and static values.
5 | ///
6 | internal static class CsmlConstants
7 | {
8 | public const string LineNumberMetadataAttribute = "__LineNumber";
9 | }
10 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/UnaryExpressionNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public abstract class UnaryExpressionNode : ExpressionNode
4 | {
5 | [XmlElement("Expression")]
6 | public required ExpressionStatementNode Expression { get; init; }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/Statements/ContinueBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders.Statements;
2 |
3 | internal class ContinueBuilder
4 | {
5 | public static ContinueStatementSyntax Build()
6 | {
7 | return SF.ContinueStatement();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/demos/WebAPI/README.md:
--------------------------------------------------------------------------------
1 | # WebAPI
2 |
3 | This project is a .NET Web API, with service interfaces, service classes, and model classes all written in C♯ML.
4 |
5 | This project demonstrates that C♯ML can fully substitute traditional C#, including in web-based applications which utilize dependency injection.
6 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Members/PropertyGetterAccessor.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Members;
2 |
3 | ///
4 | /// Defines the valid values of a property getter.
5 | ///
6 | public enum PropertyGetterAccessor
7 | {
8 | Unset,
9 |
10 | [XmlEnum("Get")]
11 | Get
12 | }
13 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/ReturnNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | ///
4 | /// Represents a return statement.
5 | ///
6 | public class ReturnNode : BaseNode
7 | {
8 | [XmlAttribute("Value")]
9 | public string? Value { get; init; }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Types/ClassNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Types;
2 |
3 | ///
4 | /// Represents a class declaration.
5 | ///
6 | [XmlType("Class")]
7 | public class ClassNode : TypeNode
8 | {
9 | [XmlAttribute("Static")]
10 | public bool Static { get; init; }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/NewNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public class NewNode : ExpressionNode
4 | {
5 | [XmlAttribute("Type")]
6 | public required string Type { get; init; }
7 |
8 | [XmlElement("Argument")]
9 | public ArgumentNode[]? Arguments { get; init; }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Types/UsingDirectiveNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Types;
2 |
3 | ///
4 | /// Represents a using directive.
5 | ///
6 | public class UsingDirectiveNode : BaseNode
7 | {
8 | [XmlAttribute("Namespace")]
9 | public required string Namespace { get; init; }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/Statements/ThrowBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders.Statements;
2 |
3 | internal class ThrowBuilder
4 | {
5 | public static ThrowStatementSyntax Build(ThrowNode node)
6 | {
7 | return SF.ThrowStatement(ExpressionBuilder.Build(node.Expression));
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Members/ArgumentNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Members;
2 |
3 | ///
4 | /// Represents an argument provided to a method invocation.
5 | ///
6 | public class ArgumentNode : BaseNode
7 | {
8 | [XmlAttribute("Value")]
9 | public required string Value { get; init; }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Csml/Parser/CsmlParseResult.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser;
2 |
3 | ///
4 | /// DTO which contains the C♯ML parse result, as well as any potential errors.
5 | ///
6 | ///
7 | ///
8 | public record CsmlParseResult(CsmlNode? Result, List Errors);
9 |
--------------------------------------------------------------------------------
/src/Csml/Exceptions/UnknownCsmlElementException.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Exceptions;
2 |
3 | public class UnknownCsmlElementException : CsmlParseException
4 | {
5 | public UnknownCsmlElementException(int? LineNumber, string ElementName)
6 | : base(CsmlDiagnostics.UnexpectedElement, LineNumber, [ElementName])
7 | {
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/CsmlTests/GlobalUsings.cs:
--------------------------------------------------------------------------------
1 | global using Microsoft.CodeAnalysis;
2 | global using Microsoft.CodeAnalysis.CSharp;
3 | global using Microsoft.CodeAnalysis.CSharp.Syntax;
4 | global using System.Collections.Immutable;
5 | global using static CsmlTests.Helpers.CompilationHelper;
6 | global using static CsmlTests.Helpers.SyntaxNodeDescendantExtensions;
7 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Members/PropertySetterAccessor.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Members;
2 |
3 | ///
4 | /// Defines the valid values of a property setter.
5 | ///
6 | public enum PropertySetterAccessor
7 | {
8 | Unset,
9 |
10 | [XmlEnum("Set")]
11 | Set,
12 |
13 | [XmlEnum("Init")]
14 | Init
15 | }
16 |
--------------------------------------------------------------------------------
/demos/Sandbox/MyClass.c♯:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/Csml/Parser/CsmlParseError.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser;
2 |
3 | ///
4 | /// Describes a C♯ML parsing error.
5 | ///
6 | ///
7 | ///
8 | ///
9 | public record CsmlParseError(DiagnosticDescriptor Descriptor, int? LineNumber, params string[] Arguments);
10 |
--------------------------------------------------------------------------------
/documentation/types/property-getter-accessor.md:
--------------------------------------------------------------------------------
1 | # Property getter accessor
2 |
3 | ## Description
4 |
5 | Represents the various accessors for property getters.
6 |
7 | ## Values
8 |
9 | | Value | C# equivalent |
10 | |---|---|
11 | | Get | [`get`](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-properties#the-get-accessor) |
12 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Expressions/BinaryExpressionNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Expressions;
2 |
3 | public abstract class BinaryExpressionNode : ExpressionNode
4 | {
5 | [XmlElement("Left")]
6 | public required ExpressionStatementNode Left { get; init; }
7 |
8 | [XmlElement("Right")]
9 | public required ExpressionStatementNode Right { get; init; }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/WhileNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | public class WhileNode : BaseNode
4 | {
5 | [XmlElement("Condition", typeof(ExpressionStatementNode))]
6 | public required ExpressionStatementNode Condition { get; init; }
7 |
8 | [XmlElement("Statements")]
9 | public required BlockNode Statements { get; init; }
10 | }
11 |
--------------------------------------------------------------------------------
/documentation/tags/break.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents the `break` keyword.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | None.
14 |
15 | ## C# equivalent
16 |
17 | The `break` keyword.
18 |
19 | ## Example
20 |
21 | ### C♯ML
22 |
23 | ```xml
24 |
25 | ```
26 |
27 | ### C#
28 |
29 | ```csharp
30 | break
31 | ```
32 |
--------------------------------------------------------------------------------
/src/Csml/Exceptions/UnknownCsmlAttributeException.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Csml.Exceptions;
3 |
4 | public class UnknownCsmlAttributeException : CsmlParseException
5 | {
6 | public UnknownCsmlAttributeException(DiagnosticDescriptor Descriptor, int? LineNumber, string AttributeName)
7 | : base(CsmlDiagnostics.UnexpectedAttribute, LineNumber, [AttributeName])
8 | {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/documentation/tags/default.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents the `default` keyword.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | None.
14 |
15 | ## C# equivalent
16 |
17 | The `default` keyword.
18 |
19 | ## Example
20 |
21 | ### C♯ML
22 |
23 | ```xml
24 |
25 | ```
26 |
27 | ### C#
28 |
29 | ```csharp
30 | default
31 | ```
32 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/CatchNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | public class CatchNode : BaseNode
4 | {
5 | [XmlAttribute("Type")]
6 | public string? Type { get; init; }
7 |
8 | [XmlAttribute("Name")]
9 | public string? Name { get; init; }
10 |
11 | [XmlElement("Statements")]
12 | public required BlockNode Statements { get; init; }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/SwitchNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | public class SwitchNode : BaseNode
4 | {
5 | [XmlAttribute("Value")]
6 | public required string Value { get; init; }
7 |
8 | [XmlElement("Case", typeof(CaseNode))]
9 | [XmlElement("Default", typeof(DefaultNode))]
10 | public StatementContainerNode[]? Cases { get; init; }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Types/StructNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Types;
2 |
3 | ///
4 | /// Represents a struct declaration.
5 | ///
6 | [XmlType("Struct")]
7 | public class StructNode : TypeNode
8 | {
9 | [XmlAttribute("ReadOnly")]
10 | public bool ReadOnly { get; set; }
11 |
12 | [XmlAttribute("Ref")]
13 | public bool Ref { get; set; }
14 | }
15 |
--------------------------------------------------------------------------------
/documentation/tags/continue.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents the `continue` keyword.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | None.
14 |
15 | ## C# equivalent
16 |
17 | The `continue` keyword.
18 |
19 | ## Example
20 |
21 | ### C♯ML
22 |
23 | ```xml
24 |
25 | ```
26 |
27 | ### C#
28 |
29 | ```csharp
30 | continue
31 | ```
32 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Members/EnumValue.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Members;
2 |
3 | ///
4 | /// Represents a value of an enum.
5 | ///
6 | [XmlType("EnumValue")]
7 | public class EnumValue : BaseNode
8 | {
9 | [XmlAttribute("Name")]
10 | public required string Name { get; init; }
11 |
12 | [XmlAttribute("Value")]
13 | public string? Value { get; init; }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Csml/Exceptions/UnexpectedCsmlPermutationException.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Exceptions;
2 |
3 | public class UnexpectedCsmlPermutationException : CsmlParseException
4 | {
5 | public UnexpectedCsmlPermutationException(int? LineNumber, string unexpectedTypeName, string baseTypeName)
6 | : base(CsmlDiagnostics.UnexpectedPermutation, LineNumber, [unexpectedTypeName, baseTypeName])
7 | {
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Csml/Exceptions/CsmlParseException.cs:
--------------------------------------------------------------------------------
1 | using Csml.Parser;
2 |
3 | namespace Csml.Exceptions;
4 |
5 | public class CsmlParseException : Exception
6 | {
7 | public CsmlParseError ParseError { get; }
8 |
9 | public CsmlParseException(DiagnosticDescriptor Descriptor, int? LineNumber, string[] Arguments)
10 | {
11 | ParseError = new CsmlParseError(Descriptor, LineNumber, Arguments);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/demos/WebAPI/Program.cs:
--------------------------------------------------------------------------------
1 | using WebAPI.Services.Abstractions;
2 | using WebAPI.Services.Implementations;
3 |
4 | WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
5 | builder.Services.AddScoped();
6 |
7 | WebApplication app = builder.Build();
8 |
9 | app.MapGet("/double",
10 | (int input, ITestService testService)
11 | => testService.Double(input));
12 |
13 | app.Run();
14 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/IfNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | ///
4 | /// Represents an if statement.
5 | ///
6 | public class IfNode : BaseNode
7 | {
8 | [XmlElement("Expression")]
9 | public required ExpressionStatementNode Expression { get; init; }
10 |
11 | [XmlElement("Statements")]
12 | public required BlockNode Statements { get; init; }
13 | }
14 |
--------------------------------------------------------------------------------
/demos/WebAPI/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/launchsettings.json",
3 | "profiles": {
4 | "http": {
5 | "commandName": "Project",
6 | "dotnetRunMessages": true,
7 | "launchBrowser": false,
8 | "applicationUrl": "http://localhost:5178",
9 | "environmentVariables": {
10 | "ASPNETCORE_ENVIRONMENT": "Development"
11 | }
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/Statements/ReturnBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders.Statements;
2 |
3 | internal static class ReturnBuilder
4 | {
5 | public static ReturnStatementSyntax Build(ReturnNode node)
6 | {
7 | if (node.Value == null)
8 | {
9 | return SF.ReturnStatement();
10 | }
11 |
12 | return SF.ReturnStatement(SF.IdentifierName(node.Value));
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/CsmlNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes;
2 |
3 | ///
4 | /// The root node of a C♯ML source file.
5 | ///
6 | [XmlRoot(ElementName = "Csml", IsNullable = false)]
7 | public class CsmlNode : BaseNode
8 | {
9 | [XmlElement("UsingDirective")]
10 | public UsingDirectiveNode[]? UsingDirectives { get; init; }
11 |
12 | [XmlElement("Namespace")]
13 | public NamespaceNode[]? Namespaces { get; init; }
14 | }
15 |
--------------------------------------------------------------------------------
/demos/WebAPI/Services/Abstractions/ITestService.c♯:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Members/ParameterModifier.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Members;
2 |
3 | ///
4 | /// Defines the valid values of a reference parameter.
5 | ///
6 | public enum ParameterModifier
7 | {
8 | Unset,
9 |
10 | [XmlEnum("Ref")]
11 | Ref,
12 |
13 | [XmlEnum("Out")]
14 | Out,
15 |
16 | [XmlEnum("RefReadonly")]
17 | RefReadonly,
18 |
19 | [XmlEnum("In")]
20 | In,
21 |
22 | [XmlEnum("Params")]
23 | Params
24 | }
25 |
--------------------------------------------------------------------------------
/demos/HelloWorld/Program.c♯:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Members/ParameterNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Members;
2 |
3 | public class ParameterNode : BaseNode
4 | {
5 | [XmlAttribute("Type")]
6 | public required string Type { get; init; }
7 |
8 | [XmlAttribute("Name")]
9 | public required string Name { get; init; }
10 |
11 | [XmlAttribute("Default")]
12 | public string? Default { get; init; }
13 |
14 | [XmlAttribute("Modifier")]
15 | public ParameterModifier Modifier { get; init; }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Types/EnumNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Types;
2 |
3 | ///
4 | /// Represents an enum declaration.
5 | ///
6 | [XmlType("Enum")]
7 | public class EnumNode : BaseNode
8 | {
9 | [XmlAttribute("Name")]
10 | public required string Name { get; init; }
11 |
12 | [XmlAttribute("Access")]
13 | public AccessModifier Access { get; init; }
14 |
15 | [XmlElement("EnumValue")]
16 | public EnumValue[]? Values { get; init; }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/Statements/WhileBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders.Statements;
2 |
3 | internal static class WhileBuilder
4 | {
5 | public static WhileStatementSyntax Build(WhileNode whileNode)
6 | {
7 | ExpressionSyntax condition = ExpressionBuilder.Build(whileNode.Condition.Expression);
8 | BlockSyntax block = BlockBuilder.Build(whileNode.Statements.Statements);
9 |
10 | return SF.WhileStatement(condition, block);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Csml/GlobalUsings.cs:
--------------------------------------------------------------------------------
1 | global using Csml.Exceptions;
2 | global using Csml.Generator;
3 | global using Csml.Parser.Nodes;
4 | global using Csml.Parser.Nodes.Members;
5 | global using Csml.Parser.Nodes.Statements;
6 | global using Csml.Parser.Nodes.Types;
7 | global using Microsoft.CodeAnalysis;
8 | global using Microsoft.CodeAnalysis.CSharp;
9 | global using Microsoft.CodeAnalysis.CSharp.Syntax;
10 | global using System.Xml.Serialization;
11 | global using SF = Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
12 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Members/MethodBaseNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Members;
2 |
3 | public abstract class MethodBaseNode : BaseNode
4 | {
5 | [XmlAttribute("Access")]
6 | public AccessModifier Access { get; init; }
7 |
8 | [XmlAttribute("Static")]
9 | public bool Static { get; init; }
10 |
11 | [XmlElement("Parameter")]
12 | public ParameterNode[]? Parameters { get; init; }
13 |
14 | [XmlElement("Statements")]
15 | public BlockNode? Statements { get; init; }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/ForEachNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | ///
4 | /// Represents a foreach statement.
5 | ///
6 | public class ForEachNode : StatementContainerNode
7 | {
8 | [XmlAttribute("Type")]
9 | public required string Type { get; init; }
10 |
11 | [XmlAttribute("Name")]
12 | public required string Name { get; init; }
13 |
14 | [XmlAttribute("Collection")]
15 | public required string Collection { get; init; }
16 | }
17 |
--------------------------------------------------------------------------------
/documentation/types/property-setter-accessor.md:
--------------------------------------------------------------------------------
1 | # Property setter accessor
2 |
3 | ## Description
4 |
5 | Represents the various accessors for property setters.
6 |
7 | ## Values
8 |
9 | | Value | C# equivalent |
10 | |---|---|
11 | | Set | [`set`](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-properties#the-set-accessor) |
12 | | Init | [`init`](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-properties#the-init-accessor) |
13 |
--------------------------------------------------------------------------------
/documentation/tags/return.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents a `return` statement.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Value` | `string` | *Nothing* | No | The value to be returned. |
12 |
13 | ## Elements
14 |
15 | None.
16 |
17 | ## C# equivalent
18 |
19 | The `return` keyword.
20 |
21 | ## Example
22 |
23 | ```xml
24 |
25 | ```
26 |
27 | ### C#
28 |
29 | ```csharp
30 | return 123;
31 | ```
32 |
--------------------------------------------------------------------------------
/src/Csml/Exceptions/InvalidAccessorException.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Exceptions;
2 |
3 | public class InvalidAccessorException : Exception
4 | {
5 | public int LineNumber { get; }
6 |
7 | public AccessModifier AccessModifiers { get; }
8 |
9 | public string Target { get; }
10 |
11 | public InvalidAccessorException(int lineNumber, AccessModifier accessModifiers, string target)
12 | {
13 | LineNumber = lineNumber;
14 | AccessModifiers = accessModifiers;
15 | Target = target;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/Statements/ForEachBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders.Statements;
2 |
3 | internal class ForEachBuilder
4 | {
5 | public static ForEachStatementSyntax Build(ForEachNode node)
6 | {
7 | BlockSyntax block = BlockBuilder.Build(node.Statements);
8 |
9 | return SF.ForEachStatement(
10 | SF.IdentifierName(node.Type),
11 | SF.Identifier(node.Name),
12 | SF.IdentifierName(node.Collection),
13 | block);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Members/FieldNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Members;
2 |
3 | ///
4 | /// Represents a field.
5 | ///
6 | [XmlType("Field")]
7 | public class FieldNode : MemberNode
8 | {
9 | [XmlAttribute("Const")]
10 | public bool Const { get; set; }
11 |
12 | [XmlAttribute("ReadOnly")]
13 | public bool ReadOnly { get; set; }
14 |
15 | [XmlAttribute("Ref")]
16 | public bool Ref { get; set; }
17 |
18 | [XmlAttribute("Static")]
19 | public bool Static { get; set; }
20 | }
21 |
--------------------------------------------------------------------------------
/documentation/types/access-modifiers.md:
--------------------------------------------------------------------------------
1 | # Access modifiers
2 |
3 | ## Description
4 |
5 | Represents the various [access modifiers](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers).
6 |
7 | ## Values
8 |
9 | | Value | C# equivalent |
10 | |---|---|
11 | | Public | `public` |
12 | | Private | `private` |
13 | | Protected | `protected` |
14 | | Internal | `internal` |
15 | | ProtectedInternal | `protected internal` |
16 | | PrivateProtected | `private protected` |
17 | | File | `file` |
18 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/BaseNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes;
2 |
3 | ///
4 | /// The base CSML node type which all other node types inherit from.
5 | ///
6 | public abstract class BaseNode
7 | {
8 | ///
9 | /// Metadata field specifying the line number corresponding to the current node.
10 | /// Used to allow diagnostics to specify a concrete line number.
11 | ///
12 | [XmlAttribute(CsmlConstants.LineNumberMetadataAttribute)]
13 | public int LineNumber { get; init; }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/CallNode.cs:
--------------------------------------------------------------------------------
1 | using Csml.Parser.Nodes.Expressions;
2 |
3 | namespace Csml.Parser.Nodes.Statements;
4 |
5 | ///
6 | /// Represents a method invocation statement.
7 | ///
8 | public class CallNode : ExpressionNode
9 | {
10 | [XmlAttribute("Target")]
11 | public string? Target { get; init; }
12 |
13 | [XmlAttribute("Method")]
14 | public required string Method { get; init; }
15 |
16 | [XmlElement("Argument")]
17 | public ArgumentNode[]? Arguments { get; init; }
18 | }
19 |
--------------------------------------------------------------------------------
/demos/Sandbox/Sandbox.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0
6 | enable
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/demos/FizzBuzz/FizzBuzz.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0
6 | enable
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/demos/HelloWorld/HelloWorld.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0
6 | enable
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Members/MemberNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Members;
2 |
3 | ///
4 | /// Base class representing an type member.
5 | ///
6 | public abstract class MemberNode : BaseNode
7 | {
8 | [XmlAttribute("Name")]
9 | public required string Name { get; init; }
10 |
11 | [XmlAttribute("Type")]
12 | public required string Type { get; init; }
13 |
14 | [XmlAttribute("Value")]
15 | public string? Value { get; init; }
16 |
17 | [XmlAttribute("Access")]
18 | public AccessModifier Access { get; init; }
19 | }
20 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # To get started with Dependabot version updates, you'll need to specify which
2 | # package ecosystems to update and where the package manifests are located.
3 | # Please see the documentation for all configuration options:
4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5 |
6 | version: 2
7 | updates:
8 | - package-ecosystem: "nuget" # See documentation for possible values
9 | directory: "/" # Location of package manifests
10 | schedule:
11 | interval: "weekly"
12 |
--------------------------------------------------------------------------------
/documentation/tags/decrement.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a decrement operation (postfix) on `Target`.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Target` | `string` | *None* | Yes | The target of the operation. |
12 |
13 | ## Elements
14 |
15 | None.
16 |
17 | ## C# equivalent
18 |
19 | The `--` operator (postfix).
20 |
21 | ## Example
22 |
23 | ### C♯ML
24 |
25 | ```xml
26 |
27 | ```
28 |
29 | ### C#
30 |
31 | ```csharp
32 | number--
33 | ```
34 |
--------------------------------------------------------------------------------
/documentation/tags/increment.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a increment operation (postfix) on `Target`.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Target` | `string` | *None* | Yes | The target of the operation. |
12 |
13 | ## Elements
14 |
15 | None.
16 |
17 | ## C# equivalent
18 |
19 | The `++` operator (postfix).
20 |
21 | ## Example
22 |
23 | ### C♯ML
24 |
25 | ```xml
26 |
27 | ```
28 |
29 | ### C#
30 |
31 | ```csharp
32 | number++
33 | ```
34 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/VariableNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | ///
4 | /// Represents a variable declaration statement.
5 | ///
6 | public class VariableNode : BaseNode
7 | {
8 | [XmlAttribute("Const")]
9 | public bool Const { get; init; }
10 |
11 | [XmlAttribute("Name")]
12 | public required string Name { get; init; }
13 |
14 | [XmlAttribute("Type")]
15 | public required string Type { get; init; }
16 |
17 | [XmlElement("Expression")]
18 | public ExpressionStatementNode? Expression { get; init; }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/Statements/ArgumentListBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders.Statements;
2 |
3 | internal static class ArgumentListBuilder
4 | {
5 | public static ArgumentListSyntax BuildArgumentList(ArgumentNode[] argumentNodes)
6 | {
7 | ArgumentListSyntax argumentList = SF.ArgumentList();
8 |
9 | foreach (ArgumentNode argument in argumentNodes)
10 | {
11 | argumentList = argumentList.AddArguments(SF.Argument(SF.IdentifierName(argument.Value)));
12 | }
13 |
14 | return argumentList;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/documentation/tags/prefix-decrement.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a decrement operation (prefix) on `Target`.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Target` | `string` | *None* | Yes | The target of the operation. |
12 |
13 | ## Elements
14 |
15 | None.
16 |
17 | ## C# equivalent
18 |
19 | The `--` operator (prefix).
20 |
21 | ## Example
22 |
23 | ### C♯ML
24 |
25 | ```xml
26 |
27 | ```
28 |
29 | ### C#
30 |
31 | ```csharp
32 | --number
33 | ```
34 |
--------------------------------------------------------------------------------
/documentation/tags/prefix-increment.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a increment operation (prefix) on `Target`.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Target` | `string` | *None* | Yes | The target of the operation. |
12 |
13 | ## Elements
14 |
15 | None.
16 |
17 | ## C# equivalent
18 |
19 | The `++` operator (prefix).
20 |
21 | ## Example
22 |
23 | ### C♯ML
24 |
25 | ```xml
26 |
27 | ```
28 |
29 | ### C#
30 |
31 | ```csharp
32 | ++number
33 | ```
34 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/AccessModifier.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes;
2 |
3 | ///
4 | /// Defines the valid values of access modifiers.
5 | ///
6 | public enum AccessModifier
7 | {
8 | Unset,
9 |
10 | [XmlEnum("Public")]
11 | Public,
12 |
13 | [XmlEnum("Private")]
14 | Private,
15 |
16 | [XmlEnum("Protected")]
17 | Protected,
18 |
19 | [XmlEnum("Internal")]
20 | Internal,
21 |
22 | [XmlEnum("ProtectedInternal")]
23 | ProtectedInternal,
24 |
25 | [XmlEnum("PrivateProtected")]
26 | PrivateProtected,
27 |
28 | [XmlEnum("File")]
29 | File
30 | }
31 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Members/PropertyNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Members;
2 |
3 | ///
4 | /// Represents a property.
5 | ///
6 | [XmlType("Property")]
7 | public class PropertyNode : MemberNode
8 | {
9 | [XmlAttribute("Getter")]
10 | public PropertyGetterAccessor Getter { get; init; }
11 |
12 | [XmlAttribute("Setter")]
13 | public PropertySetterAccessor Setter { get; init; }
14 |
15 | [XmlAttribute("GetterAccess")]
16 | public AccessModifier GetterAccess { get; init; }
17 |
18 | [XmlAttribute("SetterAccess")]
19 | public AccessModifier SetterAccess { get; init; }
20 | }
21 |
--------------------------------------------------------------------------------
/documentation/tags/value.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Refers to a value or an object.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Type` | `string` | *None* | Yes | The value. |
12 |
13 | ## Elements
14 |
15 | None.
16 |
17 | ## C# equivalent
18 |
19 | A literal value, or the name of a variable.
20 |
21 | ## Example
22 |
23 | ```xml
24 |
25 |
26 |
27 |
28 |
29 | ```
30 |
31 | ### C#
32 |
33 | ```csharp
34 | int number = 123;
35 | ```
36 |
--------------------------------------------------------------------------------
/documentation/tags/throw.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs `throw` on ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The contained expression. |
16 |
17 | ## C# equivalent
18 |
19 | The `throw` keyword.
20 |
21 | ## Example
22 |
23 | ### C♯ML
24 |
25 | ```xml
26 |
27 |
28 |
29 | ```
30 |
31 | ### C#
32 |
33 | ```csharp
34 | throw new MyException();
35 | ```
36 |
--------------------------------------------------------------------------------
/documentation/tags/inheritance.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Specifies a base class or interface implementation.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Type` | `string` | *None* | Yes | The name of the type. |
12 |
13 | ## Elements
14 |
15 | None.
16 |
17 | ## C# equivalent
18 |
19 | The `:` keyword and an type name.
20 |
21 | ## Example
22 |
23 | ### C♯ML
24 |
25 | ```xml
26 |
27 |
28 |
29 | ```
30 |
31 | ### C#
32 |
33 | ```csharp
34 | class MyClass : IDisposable
35 | {
36 | }
37 | ```
38 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/CsmlBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders;
2 |
3 | internal static class CsmlBuilder
4 | {
5 | public static CompilationUnitSyntax Build(CsmlNode node)
6 | {
7 | CompilationUnitSyntax comp = SF.CompilationUnit();
8 |
9 | SyntaxList usingList = UsingDirectiveBuilder.BuildMultiple(node.UsingDirectives);
10 | SyntaxList namespaceList = NamespaceBuilder.BuildMultiple(node.Namespaces);
11 |
12 | return comp
13 | .WithUsings(usingList)
14 | .WithMembers(namespaceList)
15 | .NormalizeWhitespace();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/demos/WebAPI/WebAPI.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net9.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/documentation/tags/not.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a logical NOT operation on ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The contained expression. |
16 |
17 | ## C# equivalent
18 |
19 | The `!` operator.
20 |
21 | ## Example
22 |
23 | ### C♯ML
24 |
25 | ```xml
26 |
27 |
28 |
29 |
30 |
31 | ```
32 |
33 | ### C#
34 |
35 | ```csharp
36 | !hasValue
37 | ```
38 |
--------------------------------------------------------------------------------
/documentation/tags/argument.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents an argument being provided to a method invocation or object constructor.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Value` | `string` | *None* | Yes | The value of the argument. |
12 |
13 | ## Elements
14 |
15 | None.
16 |
17 | ## C# equivalent
18 |
19 | A method- or constructor argument.
20 |
21 | ## Example
22 |
23 | ### C♯ML
24 |
25 | ```xml
26 |
27 |
28 |
29 | ```
30 |
31 | ### C#
32 |
33 | ```csharp
34 | System.Console.WriteLine(123);
35 | ```
36 |
--------------------------------------------------------------------------------
/documentation/tags/await.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs `` in an `await` expression.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The contained expression. |
16 |
17 | ## C# equivalent
18 |
19 | The `await` keyword.
20 |
21 | ## Example
22 |
23 | ### C♯ML
24 |
25 | ```xml
26 |
27 |
28 |
29 |
30 |
31 | ```
32 |
33 | ### C#
34 |
35 | ```csharp
36 | await myTask
37 | ```
38 |
--------------------------------------------------------------------------------
/documentation/tags/try.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents a `try` statement.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [``](./block.md) | *None* | Yes | No | The statements contained within the try-statement. |
16 |
17 | ## C# equivalent
18 |
19 | The `try` keyword.
20 |
21 | ## Example
22 |
23 | ### C♯ML
24 |
25 | ```xml
26 |
27 |
28 |
29 |
30 |
31 | ```
32 |
33 | ### C#
34 |
35 | ```csharp
36 | try
37 | {
38 | DoWork();
39 | }
40 | ```
41 |
--------------------------------------------------------------------------------
/tests/CsmlTests/Statements/BreakTests.cs:
--------------------------------------------------------------------------------
1 | namespace CsmlTests.Statements;
2 |
3 | public class BreakTests
4 | {
5 | [Fact]
6 | public void BreakTest()
7 | {
8 | // Arrange
9 | string csml = """
10 |
11 | """;
12 |
13 | // Act
14 | SyntaxNode[] output = AssertCompileNoDiagnostics(CsmlSyntaxWrapper.WrapInMethod(csml));
15 |
16 | // Assert
17 | if (!output.FirstDescendant(out MethodDeclarationSyntax? methodDeclaration))
18 | {
19 | Assert.Fail();
20 | return;
21 | }
22 |
23 | Assert.True(methodDeclaration.Body?.GetChildNodes() is [BreakStatementSyntax]);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Csml/AnalyzerReleases.Unshipped.md:
--------------------------------------------------------------------------------
1 | ; Unshipped analyzer release
2 | ; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
3 |
4 | ### New Rules
5 |
6 | Rule ID | Category | Severity | Notes
7 | --------|----------|----------|-------
8 | CSML0001 | CSML | Warning | CsmlDiagnostics
9 | CSML0002 | CSML | Error | CsmlDiagnostics
10 | CSML0003 | CSML | Error | CsmlDiagnostics
11 | CSML0004 | CSML | Error | CsmlDiagnostics
12 | CSML0005 | CSML | Error | CsmlDiagnostics
13 | CSML0006 | CSML | Error | CsmlDiagnostics
14 | CSML0007 | CSML | Error | CsmlDiagnostics
15 | CSML0008 | CSML | Error | CsmlDiagnostics
16 | CSML0009 | CSML | Error | CsmlDiagnostics
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Members/MethodNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Members;
2 |
3 | ///
4 | /// Represents a method.
5 | ///
6 | public class MethodNode : MethodBaseNode
7 | {
8 | [XmlAttribute("Name")]
9 | public required string Name { get; init; }
10 |
11 | [XmlAttribute("Return")]
12 | public required string Return { get; init; }
13 |
14 | [XmlAttribute("Async")]
15 | public bool Async { get; init; }
16 |
17 | [XmlAttribute("Abstract")]
18 | public bool Abstract { get; init; }
19 |
20 | [XmlAttribute("Virtual")]
21 | public bool Virtual { get; init; }
22 |
23 | [XmlAttribute("Override")]
24 | public bool Override { get; init; }
25 | }
26 |
--------------------------------------------------------------------------------
/documentation/tags/bitwise-not.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a bitwise NOT operation on ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The contained expression. |
16 |
17 | ## C# equivalent
18 |
19 | The `~` operator.
20 |
21 | ## Example
22 |
23 | ### C♯ML
24 |
25 | ```xml
26 |
27 |
28 |
29 |
30 |
31 | ```
32 |
33 | ### C#
34 |
35 | ```csharp
36 | ~myNumber
37 | ```
38 |
--------------------------------------------------------------------------------
/documentation/tags/csml.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents the root node of a C♯ML source file.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | Using directive | *None* | No | Yes | Using directives. |
16 | | `` | Namespace | *None* | No | Yes | Namespace declarations. |
17 |
18 | ## C# equivalent
19 |
20 | *No direct C# equivalent.*
21 |
22 | ## Example
23 |
24 | ```xml
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | ```
34 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/ForNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Statements;
2 |
3 | ///
4 | /// Represents a for statement.
5 | ///
6 | public class ForNode : BaseNode
7 | {
8 | [XmlElement("Variable", typeof(VariableNode))]
9 | public required VariableNode Variable { get; init; }
10 |
11 | [XmlElement("Condition", typeof(ExpressionStatementNode))]
12 | public required ExpressionStatementNode Condition { get; init; }
13 |
14 | [XmlElement("Iterator", typeof(ExpressionStatementNode))]
15 | public required ExpressionStatementNode Iterator { get; init; }
16 |
17 | [XmlElement("Statements")]
18 | public required BlockNode Statements { get; init; }
19 | }
20 |
--------------------------------------------------------------------------------
/tests/CsmlTests/Statements/ContinueTests.cs:
--------------------------------------------------------------------------------
1 | namespace CsmlTests.Statements;
2 |
3 | public class ContinueTests
4 | {
5 | [Fact]
6 | public void ContinueTest()
7 | {
8 | // Arrange
9 | string csml = """
10 |
11 | """;
12 |
13 | // Act
14 | SyntaxNode[] output = AssertCompileNoDiagnostics(CsmlSyntaxWrapper.WrapInMethod(csml));
15 |
16 | // Assert
17 | if (!output.FirstDescendant(out MethodDeclarationSyntax? methodDeclaration))
18 | {
19 | Assert.Fail();
20 | return;
21 | }
22 |
23 | Assert.True(methodDeclaration.Body?.GetChildNodes() is [ContinueStatementSyntax]);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/documentation/tags/new.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Constructs a new object.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Type` | `string` | *None* | Yes | The type to be constructed. |
12 |
13 | ## Elements
14 |
15 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
16 | |---|---|---|---|---|---|
17 | | `` | [``](../tags/argument.md) | *None* | No | Yes | Constructor arguments. |
18 |
19 | ## C# equivalent
20 |
21 | The `new` keyword.
22 |
23 | ## Example
24 |
25 | ```xml
26 |
27 |
28 |
29 | ```
30 |
31 | ### C#
32 |
33 | ```csharp
34 | new MyType(1)
35 | ```
36 |
--------------------------------------------------------------------------------
/.github/workflows/dotnet.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a .NET project
2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3 |
4 | name: .NET
5 |
6 | on:
7 | push:
8 | branches: [ "main" ]
9 | pull_request:
10 | branches: [ "main" ]
11 |
12 | jobs:
13 | build:
14 |
15 | runs-on: ubuntu-latest
16 |
17 | steps:
18 | - uses: actions/checkout@v4
19 | - name: Setup .NET
20 | uses: actions/setup-dotnet@v4
21 | with:
22 | dotnet-version: 9.0.x
23 | - name: Restore dependencies
24 | run: dotnet restore
25 | - name: Build
26 | run: dotnet build --no-restore
27 | - name: Test
28 | run: dotnet test --no-build --verbosity normal
29 |
--------------------------------------------------------------------------------
/src/Csml/Csml.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | 13.0
6 | enable
7 | enable
8 | true
9 |
10 |
11 |
12 |
13 | all
14 | runtime; build; native; contentfiles; analyzers; buildtransitive
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/Statements/ForBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders.Statements;
2 |
3 | internal static class ForBuilder
4 | {
5 | public static ForStatementSyntax Build(ForNode node)
6 | {
7 | LocalDeclarationStatementSyntax variable = VariableBuilder.Build(node.Variable);
8 | ExpressionSyntax condition = ExpressionBuilder.Build(node.Condition.Expression);
9 | ExpressionSyntax incrementor = ExpressionBuilder.Build(node.Iterator.Expression);
10 |
11 | BlockSyntax block = BlockBuilder.Build(node.Statements.Statements);
12 |
13 | return SF.ForStatement(block)
14 | .WithDeclaration(variable.Declaration)
15 | .WithCondition(condition)
16 | .WithIncrementors([incrementor]);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/UsingDirectiveBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders;
2 |
3 | internal static class UsingDirectiveBuilder
4 | {
5 | public static SyntaxList BuildMultiple(UsingDirectiveNode[]? nodes)
6 | {
7 | SyntaxList usingList = SF.List();
8 |
9 | if (nodes != null)
10 | {
11 | foreach (UsingDirectiveNode item in nodes)
12 | {
13 | usingList = usingList.Add(Build(item));
14 | }
15 | }
16 |
17 | return usingList;
18 | }
19 |
20 | public static UsingDirectiveSyntax Build(UsingDirectiveNode node)
21 | {
22 | return SF.UsingDirective(SF.IdentifierName(node.Namespace));
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Types/NamespaceNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Types;
2 |
3 | ///
4 | /// Represents a namespace declaration.
5 | ///
6 | public class NamespaceNode : BaseNode
7 | {
8 | [XmlElement("Class", typeof(ClassNode))]
9 | [XmlElement("Struct", typeof(StructNode))]
10 | [XmlElement("Interface", typeof(InterfaceNode))]
11 | public TypeNode[]? Types { get; init; }
12 |
13 | [XmlAttribute("Name")]
14 | public required string Name { get; init; }
15 |
16 | [XmlElement("UsingDirective")]
17 | public UsingDirectiveNode[]? UsingDirectives { get; init; }
18 |
19 | [XmlElement("Namespace")]
20 | public NamespaceNode[]? Namespaces { get; init; }
21 |
22 | [XmlElement("Enum", typeof(EnumNode))]
23 | public EnumNode[]? Enums { get; init; }
24 | }
25 |
--------------------------------------------------------------------------------
/documentation/tags/using-directive.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Declares a using directive.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Namespace` | `string` | *None* | Yes | The namespace of the using directive. |
12 |
13 | ## Elements
14 |
15 | None.
16 |
17 | ## C# equivalent
18 |
19 | The `using` keyword, in the context of using directives.
20 |
21 | ## Example
22 |
23 | ### C♯ML
24 |
25 | ```xml
26 |
27 |
28 |
29 |
30 |
31 |
32 | ```
33 |
34 | ### C#
35 |
36 | ```csharp
37 | using System;
38 |
39 | namespace MyNamespace
40 | {
41 | using System.Text;
42 | }
43 | ```
44 |
--------------------------------------------------------------------------------
/documentation/tags/case.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents a `case` in a `switch` statement.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Value` | `string` | *None* | Yes | The expression of the case. |
12 |
13 | ## Elements
14 |
15 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
16 | |---|---|---|---|---|---|
17 | | *Varies* | [Expressions](../types/expressions.md) | *None* | No | Yes | The statements contained within the case. |
18 |
19 | ## C# equivalent
20 |
21 | The `case` keyword.
22 |
23 | ## Example
24 |
25 | ### C♯ML
26 |
27 | ```xml
28 |
29 |
30 |
31 |
32 | ```
33 |
34 | ### C#
35 |
36 | ```csharp
37 | case 1:
38 | DoWork();
39 | break;
40 | ```
41 |
--------------------------------------------------------------------------------
/documentation/tags/add.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs an addition operation on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `+` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 1 + 2
41 | ```
42 |
--------------------------------------------------------------------------------
/src/Csml/Workarounds.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable IDE0130 // Namespace does not match folder structure
2 | #pragma warning disable IDE0290 // Use primary constructor
3 | #pragma warning disable IDE0060 // Remove unused parameter
4 |
5 | namespace System.Runtime.CompilerServices;
6 |
7 | ///
8 | /// Makes init working on .NET Standard 2.0.
9 | ///
10 | internal static class IsExternalInit
11 | {
12 | }
13 |
14 | ///
15 | /// Makes required work on .NET Standard 2.0.
16 | ///
17 | internal class RequiredMemberAttribute : Attribute
18 | {
19 | }
20 |
21 | ///
22 | /// Makes required work on .NET Standard 2.0.
23 | ///
24 | internal sealed class CompilerFeatureRequiredAttribute : Attribute
25 | {
26 | internal CompilerFeatureRequiredAttribute(string featureName)
27 | {
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/documentation/tags/divide.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a division operation on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `*` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 4 / 2
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/equals.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs an equality comparison on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `==` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 2 == 2
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/or.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a logical OR operation on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `||` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | valueA || valueB
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/and.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a logical AND operation on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `&&` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | valueA && valueB
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/less-than.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a less-than comparison on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `<` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 2 < 3
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/multiply.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a multiplication operation on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `*` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 2 * 3
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/subtract.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a subtraction operation on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `-` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 2 - 1
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/left-shift.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a left shift-operation on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `<<` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 4 << 2
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/not-equals.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs an inequality comparison on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `!=` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 2 != 3
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/xor.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs an XOR operation on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `^` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | valueA ^ valueB
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/remainder.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a remainder/modulo operation on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `%` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 2 - 1
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/right-shift.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a right-shift operation on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `>>` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 4 >> 2
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/assignment.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Assigns a value to a variable, property, or field.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `=` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | number = 123;
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/greater-than.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs an greater-than comparison on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `>` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 3 > 2
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/bitwise-or.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a bitwise OR operation on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `|` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | numberA | numberB
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/bitwise-and.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a bitwise AND operation on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `&` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | numberA & numberB
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/less-than-or-equal.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a less-than-or-equal comparison on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `<=` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 2 <= 3
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/parameter.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents a parameter of a method or a constructor.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Type` | `string` | *None* | Yes | The type of the parameter. |
12 | | `Name` | `string` | *None* | Yes | The name of the parameter. |
13 | | `Default` | `string` | *None* | No | The default value of the parameter. |
14 | | `Modifier` | [`ParameterModifier`](../types/parameter-modifier.md) | *None* | No | The modifiers of the parameter. |
15 |
16 | ## Elements
17 |
18 | None.
19 |
20 | ## C# equivalent
21 |
22 | The method- or constructor parameter.
23 |
24 | ## Example
25 |
26 | ### C♯ML
27 |
28 | ```xml
29 |
30 |
31 |
32 | ```
33 |
34 | ### C#
35 |
36 | ```csharp
37 | void MyMethod(int number)
38 | ```
39 |
--------------------------------------------------------------------------------
/documentation/tags/greater-than-or-equal.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs a greater-than-or-equal comparison on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `>=` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 3 >= 2
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/unsigned-right-shift.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Performs an unsigned right-shift operation on `` and ``.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The left-hand argument of the expression. |
17 |
18 | ## C# equivalent
19 |
20 | The `>>>` operator.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | 1 >>> 2
41 | ```
42 |
--------------------------------------------------------------------------------
/documentation/tags/call.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents a method invocation.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Target` | `string` | *None* | No | The object or type to target the method invocation at. |
12 | | `Method` | `string` | *None* | Yes | The name of the method being invoked. |
13 |
14 | ## Elements
15 |
16 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
17 | |---|---|---|---|---|---|
18 | | `` | [``](./argument.md) | *None* | No | Yes | The arguments passed to the method invocation. |
19 |
20 | ## C# equivalent
21 |
22 | A method invocation.
23 |
24 | ## Example
25 |
26 | ### C♯ML
27 |
28 | ```xml
29 |
30 |
31 |
32 | ```
33 |
34 | ### C#
35 |
36 | ```csharp
37 | System.Console.WriteLine(123);
38 | ```
39 |
--------------------------------------------------------------------------------
/documentation/types/parameter-modifier.md:
--------------------------------------------------------------------------------
1 | # Access modifiers
2 |
3 | ## Description
4 |
5 | Represents the various modifiers that can be applied to method- and constructor parameters.
6 |
7 | ## Values
8 |
9 | | Value | C# equivalent |
10 | |---|---|
11 | | Ref | [`ref`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/method-parameters#ref-parameter-modifier) |
12 | | Out | [`out`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/method-parameters#out-parameter-modifier) |
13 | | RefReadonly | [`ref readonly`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/method-parameters#ref-readonly-modifier) |
14 | | In | [`in`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/method-parameters#in-parameter-modifier) |
15 | | Params | [`params`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/method-parameters#params-modifier) |
16 |
--------------------------------------------------------------------------------
/documentation/tags/enum-value.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Defines a value in an enum.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Name` | `string` | *None* | Yes | The name of the enum value. |
12 | | `Value` | Number | *Implicitly determined* | No | The value of the enum value. |
13 |
14 | ## Elements
15 |
16 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
17 | |---|---|---|---|---|---|
18 | | `` | [``](../tags/enum-value.md) | *None* | No | Yes | The values of the enum. |
19 |
20 | ## C# equivalent
21 |
22 | The values of an `enum`.
23 |
24 | ## Example
25 |
26 | ### C♯ML
27 |
28 | ```xml
29 |
30 |
31 |
32 |
33 |
34 | ```
35 |
36 | ### C#
37 |
38 | ```csharp
39 | enum MyEnum
40 | {
41 | A,
42 | B,
43 | C = 3
44 | }
45 | ```
46 |
--------------------------------------------------------------------------------
/documentation/tags/for-each.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents a `foreach` statement.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Type` | `string` | *None* | Yes | The type of the values being iterated over. |
12 | | `Name` | `string` | *None* | Yes | The name of the current iterated value. |
13 | | `Collection` | `string` | *None* | Yes | The name of the collection that the foreach statement iterates over. |
14 |
15 | ## Elements
16 |
17 | None.
18 |
19 | ## C# equivalent
20 |
21 | The `foreach` keyword.
22 |
23 | ## Example
24 |
25 | ### C♯ML
26 |
27 | ```xml
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | foreach (int number in numbers)
41 | {
42 | int valA = number;
43 | }
44 | ```
45 |
--------------------------------------------------------------------------------
/documentation/tags/finally.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents an `finally` statement.
6 |
7 | Note: This tag must come after a [``](./try.md) or [``](./catch.md) tag.
8 |
9 | ## Attributes
10 |
11 | | Name | Type | Default | Mandatory | Description |
12 | |---|---|---|---|---|
13 | | `Type` | `string` | *None* | No | The exception type to catch. |
14 | | `Name` | `string` | *None* | No | The name of the caught exception. |
15 |
16 | ## Elements
17 |
18 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
19 | |---|---|---|---|---|---|
20 | | `` | [``](./block.md) | *None* | Yes | No | The statements contained within the finally-statement. |
21 |
22 | ## C# equivalent
23 |
24 | The `finally` keyword.
25 |
26 | ## Example
27 |
28 | ### C♯ML
29 |
30 | ```xml
31 |
32 |
33 |
34 |
35 |
36 | ```
37 |
38 | ### C#
39 |
40 | ```csharp
41 | finally
42 | {
43 | Dispose();
44 | }
45 | ```
46 |
--------------------------------------------------------------------------------
/tests/CsmlTests/CsmlSyntaxWrapper.cs:
--------------------------------------------------------------------------------
1 | namespace CsmlTests;
2 |
3 | internal static class CsmlSyntaxWrapper
4 | {
5 | public static string WrapInClass(string markup)
6 | {
7 | return $"""
8 |
9 |
10 |
11 | {markup}
12 |
13 |
14 |
15 | """;
16 | }
17 |
18 | public static string WrapInMethod(string markup)
19 | {
20 | return $"""
21 |
22 |
23 |
24 |
25 |
26 | {markup}
27 |
28 |
29 |
30 |
31 |
32 | """;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/demos/WebAPI/Models/TestModel.c♯:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/documentation/tags/variable.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Declares a variable.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Name` | `string` | *None* | Yes | The name of the variable. |
12 | | `Type` | `string` | *None* | Yes | The type of the variable. |
13 | | `Const` | `bool` | `false` | No | Defines the variable as [`const`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/const). |
14 |
15 | ## Elements
16 |
17 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
18 | |---|---|---|---|---|---|
19 | | `` | [Expressions](../types/expressions.md) | *Uninitialized* | No | No | The expression defining the value of the variable. |
20 |
21 | ## C# equivalent
22 |
23 | A variable declaration.
24 |
25 | ## Example
26 |
27 | ```xml
28 |
29 |
30 |
31 |
32 |
33 | ```
34 |
35 | ### C#
36 |
37 | ```csharp
38 | int number = 123;
39 | ```
40 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/Statements/VariableBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders.Statements;
2 |
3 | internal class VariableBuilder
4 | {
5 | public static LocalDeclarationStatementSyntax Build(VariableNode node)
6 | {
7 | VariableDeclaratorSyntax variableDeclarator = SF.VariableDeclarator(node.Name);
8 |
9 | if (node.Expression != null)
10 | {
11 | ExpressionSyntax valueExpression = ExpressionBuilder.Build(node.Expression.Expression);
12 | variableDeclarator = variableDeclarator.WithInitializer(SF.EqualsValueClause(valueExpression));
13 | }
14 |
15 | VariableDeclarationSyntax variableDeclaration = SF.VariableDeclaration(SF.IdentifierName(node.Type), [variableDeclarator]);
16 |
17 | SyntaxTokenList tokenList = SF.TokenList();
18 |
19 | if (node.Const)
20 | {
21 | tokenList = tokenList.Add(SF.Token(SyntaxKind.ConstKeyword));
22 | }
23 |
24 | return SF.LocalDeclarationStatement(variableDeclaration)
25 | .WithModifiers(tokenList);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/documentation/tags/while.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents a `while` statement.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The condition of the while-statement. |
16 | | `` | [``](./block.md) | *None* | Yes | No | The statements contained within the while-statement. |
17 |
18 | ## C# equivalent
19 |
20 | The `while` keyword.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | ```
43 |
44 | ### C#
45 |
46 | ```csharp
47 | while (i < 5)
48 | {
49 | i++;
50 | }
51 | ```
52 |
--------------------------------------------------------------------------------
/documentation/tags/else.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents an `else` statement.
6 |
7 | Note: This tag must come after an [``](./if.md) or [``](./else-if.md) tag.
8 |
9 | ## Attributes
10 |
11 | None.
12 |
13 | ## Elements
14 |
15 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
16 | |---|---|---|---|---|---|
17 | | `` | [Expression](../types/expressions.md) | *None* | Yes | No | The expression to be matched in order for the statements of the else-statement to be executed. |
18 | | `` | [``](./block.md) | *None* | Yes | No | The statements contained within the else-statement. |
19 |
20 | ## C# equivalent
21 |
22 | The `else` keyword.
23 |
24 | ## Example
25 |
26 | ### C♯ML
27 |
28 | ```xml
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | ```
39 |
40 | ### C#
41 |
42 | ```csharp
43 | else
44 | {
45 | int valA = 3;
46 | }
47 | ```
48 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2025 DevAndersen
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/documentation/tags/catch.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents an `catch` statement.
6 |
7 | Note: This tag must come after a [``](./try.md) tag.
8 |
9 | ## Attributes
10 |
11 | | Name | Type | Default | Mandatory | Description |
12 | |---|---|---|---|---|
13 | | `Type` | `string` | *None* | No | The exception type to catch. |
14 | | `Name` | `string` | *None* | No | The name of the caught exception. |
15 |
16 | ## Elements
17 |
18 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
19 | |---|---|---|---|---|---|
20 | | `` | [``](./block.md) | *None* | Yes | No | The statements contained within the catch-statement. |
21 |
22 | ## C# equivalent
23 |
24 | The `catch` keyword.
25 |
26 | ## Example
27 |
28 | ### C♯ML
29 |
30 | ```xml
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | ```
39 |
40 | ### C#
41 |
42 | ```csharp
43 | catch (InvalidOperationException e)
44 | {
45 | HandleError(e);
46 | }
47 | ```
48 |
--------------------------------------------------------------------------------
/documentation/tags/enum.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Declares an enum.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Access` | [Access modifiers](../types/access-modifiers.md) | *Context dependent* | No | The [access modifiers](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers) of the enum. |
12 | | `Name` | `string` | *None* | Yes | The name of the enum. |
13 |
14 | ## Elements
15 |
16 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
17 | |---|---|---|---|---|---|
18 | | `` | [``](../tags/enum-value.md) | *None* | No | Yes | The values of the enum. |
19 |
20 | ## C# equivalent
21 |
22 | The `enum` keyword and an associated enum declaration.
23 |
24 | ## Example
25 |
26 | ### C♯ML
27 |
28 | ```xml
29 |
30 |
31 |
32 |
33 |
34 | ```
35 |
36 | ### C#
37 |
38 | ```csharp
39 | enum MyEnum
40 | {
41 | A,
42 | B,
43 | C = 3
44 | }
45 | ```
46 |
--------------------------------------------------------------------------------
/tests/CsmlTests/Expressions/AwaitTests.cs:
--------------------------------------------------------------------------------
1 | namespace CsmlTests.Expressions;
2 |
3 | public class AwaitTests
4 | {
5 | [Fact]
6 | public void AwaitTest()
7 | {
8 | // Arrange
9 | string csml = """
10 |
11 |
12 |
13 |
14 |
15 | """;
16 |
17 | // Act
18 | SyntaxNode[] output = AssertCompileNoDiagnostics(CsmlSyntaxWrapper.WrapInMethod(csml));
19 |
20 | // Assert
21 | if (!output.FirstDescendant(out MethodDeclarationSyntax? awaitExpression))
22 | {
23 | Assert.Fail();
24 | return;
25 | }
26 |
27 | if (awaitExpression.Body?.Statements is not [LocalDeclarationStatementSyntax { Declaration: { } declaration }])
28 | {
29 | Assert.Fail();
30 | return;
31 | }
32 |
33 | Assert.True(declaration.Type is IdentifierNameSyntax { Identifier.Value: "await" });
34 | Assert.True(declaration.Variables is [VariableDeclaratorSyntax { Identifier.Value: "task" }]);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/Statements/CallBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders.Statements;
2 |
3 | internal class CallBuilder
4 | {
5 | public static ExpressionStatementSyntax Build(CallNode node)
6 | {
7 | InvocationExpressionSyntax invocationExpression;
8 |
9 | if (node.Target != null && !string.IsNullOrWhiteSpace(node.Target))
10 | {
11 | MemberAccessExpressionSyntax methodAccessExpression = SF.MemberAccessExpression(
12 | SyntaxKind.SimpleMemberAccessExpression,
13 | SF.IdentifierName(node.Target),
14 | SF.IdentifierName(node.Method));
15 |
16 | invocationExpression = SF.InvocationExpression(methodAccessExpression);
17 | }
18 | else
19 | {
20 | invocationExpression = SF.InvocationExpression(SF.IdentifierName(node.Method));
21 | }
22 |
23 | if (node.Arguments != null)
24 | {
25 | invocationExpression = invocationExpression.WithArgumentList(ArgumentListBuilder.BuildArgumentList(node.Arguments));
26 | }
27 |
28 | return SF.ExpressionStatement(invocationExpression);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/Statements/SwitchBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders.Statements;
2 |
3 | internal static class SwitchBuilder
4 | {
5 | public static SwitchStatementSyntax Build(SwitchNode switchNode)
6 | {
7 | SwitchStatementSyntax switchStatement = SF.SwitchStatement(SF.IdentifierName(switchNode.Value));
8 |
9 | if (switchNode.Cases != null)
10 | {
11 | foreach (StatementContainerNode caseNode in switchNode.Cases)
12 | {
13 | switchStatement = switchStatement.AddSections(BuildCase(caseNode));
14 | }
15 | }
16 |
17 | return switchStatement;
18 | }
19 |
20 | private static SwitchSectionSyntax BuildCase(StatementContainerNode node)
21 | {
22 | SwitchLabelSyntax label = node switch
23 | {
24 | CaseNode caseNode => SF.CaseSwitchLabel(SF.IdentifierName(caseNode.Value)),
25 | DefaultNode => SF.DefaultSwitchLabel(),
26 | _ => throw new NotImplementedException() // Todo: Throw appropriate exception.
27 | };
28 |
29 | BlockSyntax block = BlockBuilder.Build(node.Statements);
30 | return SF.SwitchSection([label], [block]);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/documentation/tags/interface.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Declares an interface.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Access` | [Access modifiers](../types/access-modifiers.md) | *Context dependent* | No | The [access modifiers](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers) of the interface. |
12 | | `Name` | `string` | *None* | Yes | The name of the interface. |
13 |
14 | ## Elements
15 |
16 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
17 | |---|---|---|---|---|---|
18 | | `` | [``](../tags/method.md) | *None* | No | Yes | Method declarations. |
19 | | `` | [``](../tags/property.md) | *None* | No | Yes | Property declarations. |
20 |
21 | ## C# equivalent
22 |
23 | The `interface` keyword and an associated interface declaration.
24 |
25 | ## Example
26 |
27 | ### C♯ML
28 |
29 | ```xml
30 |
31 |
32 |
33 | ```
34 |
35 | ### C#
36 |
37 | ```csharp
38 | public interface IMyInterface
39 | {
40 | void DoStuff();
41 | }
42 | ```
43 |
--------------------------------------------------------------------------------
/tests/CsmlTests/CsmlTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net9.0
5 | enable
6 | enable
7 | false
8 |
9 |
10 |
11 |
12 | all
13 | runtime; build; native; contentfiles; analyzers; buildtransitive
14 |
15 |
16 |
17 |
18 |
19 | all
20 | runtime; build; native; contentfiles; analyzers; buildtransitive
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/documentation/tags/switch.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents a `switch` statement.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Value` | `string` | *None* | Yes | The name of the value being switched over. |
12 |
13 | ## Elements
14 |
15 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
16 | |---|---|---|---|---|---|
17 | | `` | [Expressions](./case.md) | *None* | No | Yes | A `case` within the switch-statement. |
18 | | `` | [Expressions](./default.md) | *None* | No | Yes | A `default` case within the switch-statement. |
19 |
20 | ## C# equivalent
21 |
22 | The `switch` keyword.
23 |
24 | ## Example
25 |
26 | ### C♯ML
27 |
28 | ```xml
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | ```
41 |
42 | ### C#
43 |
44 | ```csharp
45 | switch (myNumber)
46 | {
47 | case 1:
48 | {
49 | break;
50 | }
51 |
52 | case 2:
53 | {
54 | break;
55 | }
56 |
57 | default:
58 | {
59 | break;
60 | }
61 | }
62 | ```
63 |
--------------------------------------------------------------------------------
/documentation/tags/if.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents an `if` statement.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [Expression](../types/expressions.md) | *None* | Yes | No | The expression to be matched in order for the statements of the if-statement to be executed. |
16 | | `` | [``](./block.md) | *None* | Yes | No | The statements contained within the if-statement. |
17 |
18 | ## C# equivalent
19 |
20 | The `case` keyword.
21 |
22 | ## Example
23 |
24 | ### C♯ML
25 |
26 | ```xml
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | ```
47 |
48 | ### C#
49 |
50 | ```csharp
51 | if (1 < 2)
52 | {
53 | int valA = 1;
54 | }
55 | ```
56 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Types/TypeNode.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Parser.Nodes.Types;
2 |
3 | ///
4 | /// Base class represents a type declaration (class, struct, or interface).
5 | ///
6 | ///
7 | /// Enumeration types are defined via .
8 | ///
9 | public abstract class TypeNode : BaseNode
10 | {
11 | [XmlAttribute("Name")]
12 | public required string Name { get; init; }
13 |
14 | [XmlAttribute("Access")]
15 | public AccessModifier Access { get; init; }
16 |
17 | [XmlElement("Field", typeof(FieldNode))]
18 | [XmlElement("Property", typeof(PropertyNode))]
19 | public MemberNode[]? Members { get; init; }
20 |
21 | [XmlElement("Class", typeof(ClassNode))]
22 | [XmlElement("Struct", typeof(StructNode))]
23 | [XmlElement("Interface", typeof(InterfaceNode))]
24 | public TypeNode[]? Types { get; init; }
25 |
26 | [XmlElement("Enum", typeof(EnumNode))]
27 | public EnumNode[]? Enums { get; init; }
28 |
29 | [XmlElement("Method")]
30 | public MethodNode[]? Methods { get; init; }
31 |
32 | [XmlElement("Inheritance")]
33 | public InheritanceNode[]? BaseTypes { get; init; }
34 |
35 | [XmlElement("Constructor")]
36 | public ConstructorNode[]? Constructors { get; init; }
37 | }
38 |
--------------------------------------------------------------------------------
/documentation/tags/constructor.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents an constructor declaration.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Access` | [Access modifiers](../types/access-modifiers.md) | *Context dependent* | No | The [access modifiers](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers) of the constructor. |
12 | | `Static` | `bool` | `false` | No | Marks the constructor as static. |
13 |
14 | ## Elements
15 |
16 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
17 | |---|---|---|---|---|---|
18 | | `` | [``](./block.md) | *None* | No | Yes | The parameters of the constructor. |
19 | | `` | [``](./block.md) | *None* | No | No | The statements contained within the constructor. |
20 |
21 | ## C# equivalent
22 |
23 | A constructor method.
24 |
25 | ## Example
26 |
27 | ### C♯ML
28 |
29 | ```xml
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | ### C#
38 |
39 | ```csharp
40 | class MyClass
41 | {
42 | public MyClass(int number)
43 | {
44 | }
45 | }
46 | ```
47 |
--------------------------------------------------------------------------------
/tests/CsmlTests/Statements/WhileTests.cs:
--------------------------------------------------------------------------------
1 | namespace CsmlTests.Statements;
2 |
3 | public class WhileTests
4 | {
5 | [Fact]
6 | public void WhileTest()
7 | {
8 | // Arrange
9 | string csml = """
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | """;
26 |
27 | // Act
28 | SyntaxNode[] output = AssertCompileNoDiagnostics(CsmlSyntaxWrapper.WrapInMethod(csml));
29 |
30 | // Assert
31 | if (!output.FirstDescendant(out WhileStatementSyntax? whileStatement))
32 | {
33 | Assert.Fail();
34 | return;
35 | }
36 |
37 | Assert.True(whileStatement.Condition is BinaryExpressionSyntax { RawKind: (int)SyntaxKind.LessThanExpression });
38 | Assert.True(whileStatement.Statement is BlockSyntax { Statements.Count: 1 });
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/Statements/IfBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace Csml.Generator.SyntaxBuilders.Statements;
2 |
3 | internal static class IfBuilder
4 | {
5 | public static IfStatementSyntax Build(IfNode node, IEnumerable chainedNodes)
6 | {
7 | ExpressionSyntax condition = ExpressionBuilder.Build(node.Expression.Expression);
8 |
9 | BlockSyntax block = BlockBuilder.Build(node.Statements.Statements);
10 | IfStatementSyntax ifStatement = SF.IfStatement(condition, block);
11 |
12 | ifStatement = BuildElseChain(ifStatement, chainedNodes);
13 |
14 | return ifStatement;
15 | }
16 |
17 | private static IfStatementSyntax BuildElseChain(IfStatementSyntax ifStatement, IEnumerable chainedNodes)
18 | {
19 | BaseNode firstNode = chainedNodes.FirstOrDefault();
20 |
21 | if (firstNode is ElseIfNode elseIfNode)
22 | {
23 | ElseClauseSyntax elseClause = SF.ElseClause(Build(elseIfNode, chainedNodes.Skip(1)));
24 | ifStatement = ifStatement.WithElse(elseClause);
25 | }
26 | else if (firstNode is ElseNode elseNode)
27 | {
28 | BlockSyntax block = BlockBuilder.Build(elseNode.Statements);
29 | ifStatement = ifStatement.WithElse(SF.ElseClause(block));
30 | }
31 |
32 | return ifStatement;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/CsmlTests/Expressions/ValueTests.cs:
--------------------------------------------------------------------------------
1 | namespace CsmlTests.Expressions;
2 |
3 | public class ValueTests
4 | {
5 | [Fact]
6 | public void ValueTest()
7 | {
8 | // Arrange
9 | string csml = """
10 |
11 |
12 |
13 |
14 |
15 | """;
16 |
17 | // Act
18 | SyntaxNode[] output = AssertCompileNoDiagnostics(CsmlSyntaxWrapper.WrapInMethod(csml));
19 |
20 | // Assert
21 | if (!output.FirstDescendant(out LocalDeclarationStatementSyntax? declaration))
22 | {
23 | Assert.Fail();
24 | return;
25 | }
26 |
27 | if (declaration.Declaration.Variables is not [VariableDeclaratorSyntax declarator])
28 | {
29 | Assert.Fail();
30 | return;
31 | }
32 |
33 | Assert.True(declaration.Declaration.Type is PredefinedTypeSyntax { Keyword.Value: "int" });
34 | Assert.Equal("number", declarator.Identifier.Text);
35 | Assert.True(declarator.Initializer?.Value is LiteralExpressionSyntax { RawKind: (int)SyntaxKind.NumericLiteralExpression });
36 | Assert.True(declarator.Initializer?.Value is LiteralExpressionSyntax { Token.Value: 123 });
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/demos/WebAPI/Services/Implementations/TestService.c♯:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/documentation/tags/else-if.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents an `else if` statement.
6 |
7 | Note: This tag must come after an [``](./if.md) tag.
8 |
9 | ## Attributes
10 |
11 | None.
12 |
13 | ## Elements
14 |
15 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
16 | |---|---|---|---|---|---|
17 | | `` | [Expression](../types/expressions.md) | *None* | Yes | No | The expression to be matched in order for the statements of the else-if-statement to be executed. |
18 | | `` | [``](./block.md) | *None* | Yes | No | The statements contained within the else-if-statement. |
19 |
20 | ## C# equivalent
21 |
22 | An `else if` statement.
23 |
24 | ## Example
25 |
26 | ### C♯ML
27 |
28 | ```xml
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | ```
49 |
50 | ### C#
51 |
52 | ```csharp
53 | else if (4 != 2)
54 | {
55 | int valA = 2;
56 | }
57 | ```
58 |
--------------------------------------------------------------------------------
/documentation/types/expressions.md:
--------------------------------------------------------------------------------
1 | # Expressions
2 |
3 | ## Description
4 |
5 | Represents various kinds of expressions.
6 |
7 | ## Values
8 |
9 | - [``](../tags/add.md)
10 | - [``](../tags/and.md)
11 | - [``](../tags/assignment.md)
12 | - [``](../tags/await.md)
13 | - [``](../tags/bitwise-and.md)
14 | - [``](../tags/bitwise-not.md)
15 | - [``](../tags/bitwise-or.md)
16 | - [``](../tags/call.md)
17 | - [``](../tags/decrement.md)
18 | - [``](../tags/divide.md)
19 | - [``](../tags/equals.md)
20 | - [``](../tags/greater-than.md)
21 | - [``](../tags/greater-than-or-equal.md)
22 | - [``](../tags/increment.md)
23 | - [``](../tags/left-shift.md)
24 | - [``](../tags/less-than.md)
25 | - [``](../tags/less-than-or-equal.md)
26 | - [``](../tags/multiply.md)
27 | - [``](../tags/new.md)
28 | - [``](../tags/not.md)
29 | - [``](../tags/not-equals.md)
30 | - [``](../tags/or.md)
31 | - [``](../tags/prefix-decrement.md)
32 | - [``](../tags/prefix-increment.md)
33 | - [``](../tags/remainder.md)
34 | - [``](../tags/right-shift.md)
35 | - [``](../tags/subtract.md)
36 | - [``](../tags/unsigned-right-shift.md)
37 | - [``](../tags/value.md)
38 | - [``](../tags/xor.md)
39 |
--------------------------------------------------------------------------------
/tests/CsmlTests/Expressions/AssignmentTests.cs:
--------------------------------------------------------------------------------
1 | namespace CsmlTests.Expressions;
2 |
3 | public class AssignmentTests
4 | {
5 | [Fact]
6 | public void AssignmentTest()
7 | {
8 | // Arrange
9 | string csml = """
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | """;
19 |
20 | // Act
21 | SyntaxNode[] output = AssertCompileNoDiagnostics(CsmlSyntaxWrapper.WrapInMethod(csml));
22 |
23 | // Assert
24 | if (!output.FirstDescendant(out ExpressionStatementSyntax? expressionStatement))
25 | {
26 | Assert.Fail();
27 | return;
28 | }
29 |
30 | if (expressionStatement.Expression is not AssignmentExpressionSyntax assignment)
31 | {
32 | Assert.Fail();
33 | return;
34 | }
35 |
36 | if (assignment.Right is not LiteralExpressionSyntax rightExpression)
37 | {
38 | Assert.Fail();
39 | return;
40 | }
41 |
42 | Assert.True(assignment.Left is IdentifierNameSyntax { Identifier.Value: "number" });
43 | Assert.Equal(SyntaxKind.NumericLiteralExpression, rightExpression.Kind());
44 | Assert.Equal(123, rightExpression.Token.Value);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/documentation/tags/namespace.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents a namespace declaration.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Name` | `string` | *None* | Yes | The name of the namespace. |
12 |
13 | ## Elements
14 |
15 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
16 | |---|---|---|---|---|---|
17 | | `` | [``](../tags/class.md) | *None* | No | Yes | Class declarations. |
18 | | `` | [``](../tags/enum.md) | *None* | No | Yes | Enum declarations. |
19 | | `` | [``](../tags/namespace.md) | *None* | No | Yes | Namespace declarations. |
20 | | `` | [``](../tags/interface.md) | *None* | No | Yes | declarations. |
21 | | `` | [``](../tags/struct.md) | *None* | No | Yes | declarations. |
22 | | `` | [``](../tags/using-directive.md) | *None* | No | Yes | Using directives. |
23 |
24 | ## C# equivalent
25 |
26 | The `namespace` keyword and an associated namespace declaration.
27 |
28 | ## Example
29 |
30 | ```xml
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | ```
41 |
42 | ### C#
43 |
44 | ```csharp
45 | namespace MyNamespace
46 | {
47 | class MyClass
48 | {
49 | }
50 |
51 | interface IMyInterface
52 | {
53 | }
54 | }
55 | ```
56 |
--------------------------------------------------------------------------------
/src/Csml/Parser/Nodes/Statements/StatementContainerNode.cs:
--------------------------------------------------------------------------------
1 | using Csml.Parser.Nodes.Expressions;
2 |
3 | namespace Csml.Parser.Nodes.Statements;
4 |
5 | ///
6 | /// Base class representing a node that can contain statements as child nodes.
7 | ///
8 | public abstract class StatementContainerNode : BaseNode
9 | {
10 | [XmlElement("Assignment", typeof(AssignmentNode))]
11 | [XmlElement("Await", typeof(AwaitNode))]
12 | [XmlElement("Break", typeof(BreakNode))]
13 | [XmlElement("Call", typeof(CallNode))]
14 | [XmlElement("Catch", typeof(CatchNode))]
15 | [XmlElement("Continue", typeof(ContinueNode))]
16 | [XmlElement("Decrement", typeof(DecrementNode))]
17 | [XmlElement("Else", typeof(ElseNode))]
18 | [XmlElement("ElseIf", typeof(ElseIfNode))]
19 | [XmlElement("For", typeof(ForNode))]
20 | [XmlElement("ForEach", typeof(ForEachNode))]
21 | [XmlElement("Finally", typeof(FinallyNode))]
22 | [XmlElement("If", typeof(IfNode))]
23 | [XmlElement("Increment", typeof(IncrementNode))]
24 | [XmlElement("New", typeof(NewNode))]
25 | [XmlElement("PrefixDecrement", typeof(PrefixDecrementNode))]
26 | [XmlElement("PrefixIncrement", typeof(PrefixIncrementNode))]
27 | [XmlElement("Return", typeof(ReturnNode))]
28 | [XmlElement("Throw", typeof(ThrowNode))]
29 | [XmlElement("Try", typeof(TryNode))]
30 | [XmlElement("Variable", typeof(VariableNode))]
31 | [XmlElement("Switch", typeof(SwitchNode))]
32 | [XmlElement("While", typeof(WhileNode))]
33 | public BaseNode[]? Statements { get; init; }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/CsmlTests/Statements/SwitchTests.cs:
--------------------------------------------------------------------------------
1 | namespace CsmlTests.Statements;
2 |
3 | public class SwitchTests
4 | {
5 | [Fact]
6 | public void SwitchTest()
7 | {
8 | // Arrange
9 | string csml = """
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | """;
22 |
23 | // Act
24 | SyntaxNode[] output = AssertCompileNoDiagnostics(CsmlSyntaxWrapper.WrapInMethod(csml));
25 |
26 | // Assert
27 | if (!output.FirstDescendant(out SwitchStatementSyntax? switchStatement))
28 | {
29 | Assert.Fail();
30 | return;
31 | }
32 |
33 | if (switchStatement.Sections is not [SwitchSectionSyntax case1, SwitchSectionSyntax case2, SwitchSectionSyntax case3])
34 | {
35 | Assert.Fail();
36 | return;
37 | }
38 |
39 | Assert.True(switchStatement.Expression is IdentifierNameSyntax { Identifier.Value: "myNumber" });
40 |
41 | Assert.True(case1.Labels is [CaseSwitchLabelSyntax { Value: LiteralExpressionSyntax { Token.Value: 1 } }]);
42 | Assert.True(case2.Labels is [CaseSwitchLabelSyntax { Value: LiteralExpressionSyntax { Token.Value: 2 } }]);
43 | Assert.True(case3.Labels is [DefaultSwitchLabelSyntax]);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/documentation/tags/field.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents a field.
6 |
7 | ## Attributes
8 |
9 | | Name | Type | Default | Mandatory | Description |
10 | |---|---|---|---|---|
11 | | `Type` | `string` | *None* | Yes | The type of the field. |
12 | | `Name` | `string` | *None* | Yes | The name of the field. |
13 | | `Value` | `string` | *None* | No | The initial value of the field. |
14 | | `Access` | [Access modifiers](../types/access-modifiers.md) | *Context dependent* | No | The [access modifiers](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers) of the field. |
15 | | `Const` | `bool` | `false` | No | Marks the field as [`const`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/const). |
16 | | `ReadOnly` | `bool` | `false` | No | Marks the field as [`readonly`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/readonly). |
17 | | `Ref` | `bool` | `false` | No | Marks the field as [`ref`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/declarations#reference-variables). |
18 | | `Static` | `bool` | `false` | No | Marks the field as [`static`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/static). |
19 |
20 | ## Elements
21 |
22 | None.
23 |
24 | ## C# equivalent
25 |
26 | A field declaration.
27 |
28 | ## Example
29 |
30 | ### C♯ML
31 |
32 | ```xml
33 |
34 |
35 |
36 | ```
37 |
38 | ### C#
39 |
40 | ```csharp
41 | class MyClass
42 | {
43 | int myField;
44 | }
45 | ```
46 |
--------------------------------------------------------------------------------
/src/Csml/Generator/SyntaxBuilders/NamespaceBuilder.cs:
--------------------------------------------------------------------------------
1 | using Csml.Generator.SyntaxBuilders.Types;
2 |
3 | namespace Csml.Generator.SyntaxBuilders;
4 |
5 | internal static class NamespaceBuilder
6 | {
7 | public static SyntaxList BuildMultiple(NamespaceNode[]? nodes)
8 | {
9 | SyntaxList namespaceList = SF.List();
10 |
11 | if (nodes != null)
12 | {
13 | foreach (NamespaceNode item in nodes)
14 | {
15 | namespaceList = namespaceList.Add(Build(item));
16 | }
17 | }
18 |
19 | return namespaceList;
20 | }
21 |
22 | public static NamespaceDeclarationSyntax Build(NamespaceNode node)
23 | {
24 | NamespaceDeclarationSyntax syntax = SF.NamespaceDeclaration(SF.IdentifierName(node.Name));
25 | SyntaxList list = SF.List();
26 |
27 | SyntaxList usingList = UsingDirectiveBuilder.BuildMultiple(node.UsingDirectives);
28 | SyntaxList typeList = TypeBuilder.BuildMultiple(node.Types, node);
29 | SyntaxList enumList = EnumBuilder.BuildMultiple(node.Enums, node);
30 |
31 | SyntaxList namespaceList = BuildMultiple(node.Namespaces);
32 | list = list
33 | .AddRange(namespaceList)
34 | .AddRange(typeList)
35 | .AddRange(enumList);
36 |
37 | return syntax
38 | .WithUsings(usingList)
39 | .WithMembers(list);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/tests/CsmlTests/Statements/ThrowTests.cs:
--------------------------------------------------------------------------------
1 | namespace CsmlTests.Statements;
2 |
3 | public class ThrowTests
4 | {
5 | [Fact]
6 | public void Throw_NewException()
7 | {
8 | // Arrange
9 | string csml = """
10 |
11 |
12 |
13 | """;
14 |
15 | // Act
16 | SyntaxNode[] output = AssertCompileNoDiagnostics(CsmlSyntaxWrapper.WrapInMethod(csml));
17 |
18 | // Assert
19 | if (!output.FirstDescendant(out ThrowStatementSyntax? throwStatement))
20 | {
21 | Assert.Fail();
22 | return;
23 | }
24 |
25 | Assert.True(throwStatement.Expression is ObjectCreationExpressionSyntax);
26 | }
27 |
28 | [Fact]
29 | public void Throw_ExceptionVariable()
30 | {
31 | // Arrange
32 | string csml = """
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | """;
42 |
43 | // Act
44 | SyntaxNode[] output = AssertCompileNoDiagnostics(CsmlSyntaxWrapper.WrapInMethod(csml));
45 |
46 | // Assert
47 | if (!output.FirstDescendant(out ThrowStatementSyntax? throwStatement))
48 | {
49 | Assert.Fail();
50 | return;
51 | }
52 |
53 | Assert.True(throwStatement.Expression is IdentifierNameSyntax);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/tests/CsmlTests/Statements/ForEachTests.cs:
--------------------------------------------------------------------------------
1 | namespace CsmlTests.Statements;
2 |
3 | public class ForEachTests
4 | {
5 | [Fact]
6 | public void ForEachTest()
7 | {
8 | // Arrange
9 | string csml = """
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | """;
18 |
19 | // Act
20 | SyntaxNode[] output = AssertCompileNoDiagnostics(CsmlSyntaxWrapper.WrapInMethod(csml));
21 |
22 | // Assert
23 | if (!output.FirstDescendant(out MethodDeclarationSyntax? methodDeclaration))
24 | {
25 | Assert.Fail();
26 | return;
27 | }
28 |
29 | if (methodDeclaration.GetChildNodes() is not [.., BlockSyntax blockSyntax])
30 | {
31 | Assert.Fail();
32 | return;
33 | }
34 |
35 | if (blockSyntax.GetChildNodes() is not [ForEachStatementSyntax forEachSyntax])
36 | {
37 | Assert.Fail();
38 | return;
39 | }
40 |
41 | Assert.True(forEachSyntax.Type is PredefinedTypeSyntax { Keyword.ValueText: "int" });
42 | Assert.Equal("number", forEachSyntax.Identifier.ValueText);
43 | Assert.True(forEachSyntax.Expression is IdentifierNameSyntax { Identifier.ValueText: "numbers" });
44 | Assert.True(forEachSyntax.Statement is BlockSyntax { Statements: [LocalDeclarationStatementSyntax] });
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/documentation/tags/for.md:
--------------------------------------------------------------------------------
1 | # ``
2 |
3 | ## Description
4 |
5 | Represents a `for` statement.
6 |
7 | ## Attributes
8 |
9 | None.
10 |
11 | ## Elements
12 |
13 | | Name | Type | Default | Mandatory | Multiple allowed | Description |
14 | |---|---|---|---|---|---|
15 | | `` | [``](./variable.md) | *None* | Yes | No | The variable declaration of the for-statements's iterator. |
16 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The condition of the for-statement. |
17 | | `` | [Expressions](../types/expressions.md) | *None* | Yes | No | The incrementor of the for-statement. |
18 | | `` | [`