-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup and migration of verbatim code files to resources.
- Loading branch information
1 parent
a74a21d
commit f276e0d
Showing
10 changed files
with
135 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Reflection; | ||
using System.Text; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Text; | ||
|
||
namespace Tsu.Trees.RedGreen.SourceGenerator; | ||
|
||
internal static class ResourceCopier | ||
{ | ||
private static readonly Assembly _assembly = typeof(TemplateGenerator).Assembly; | ||
|
||
public static void RegisterResourcesToCopy(this IncrementalGeneratorInitializationContext context, IEnumerable<string> paths) | ||
{ | ||
context.RegisterPostInitializationOutput(ctx => | ||
{ | ||
foreach (var path in paths) | ||
{ | ||
SourceText sourceText; | ||
|
||
using (var stream = _assembly.GetManifestResourceStream(path)) | ||
using (var reader = new StreamReader(stream)) | ||
{ | ||
sourceText = SourceText.From(reader, (int) stream.Length, Encoding.UTF8); | ||
} | ||
|
||
ctx.AddSource(path, sourceText); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Tsu.Trees.RedGreen; | ||
|
||
/// <summary> | ||
/// Marks this struct as a green list base. | ||
/// </summary> | ||
/// <param name="kinds"> | ||
/// The kind that all lists will have. | ||
/// This should be the value on the enum (e.g.: SyntaxKind.List) | ||
/// </param> | ||
[global::System.AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] | ||
internal sealed class GreenListAttribute(object kind) : global::System.Attribute | ||
{ | ||
/// <summary> | ||
/// The List Kind. | ||
/// </summary> | ||
public object Kind { get; } = kind; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Tsu.Trees.RedGreen; | ||
|
||
/// <summary> | ||
/// Marks this class as a green node. | ||
/// </summary> | ||
/// <param name="kinds"> | ||
/// The kinds this node could have. | ||
/// This should be the value on the enum (e.g.: SyntaxKind.ClassDeclarationSyntax) | ||
/// </param> | ||
[global::System.AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] | ||
internal sealed class GreenNodeAttribute(params object[] kinds) : global::System.Attribute | ||
{ | ||
/// <summary> | ||
/// This node's Kind. | ||
/// </summary> | ||
public object[] Kinds { get; } = kinds; | ||
} |
49 changes: 49 additions & 0 deletions
49
Tsu.Trees.RedGreen/src/Templates/GreenTreeRootAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
namespace Tsu.Trees.RedGreen; | ||
|
||
/// <summary> | ||
/// An attribute that marks the given class as the base class for all nodes in a green node tree. | ||
/// </summary> | ||
[global::System.AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] | ||
internal sealed class GreenTreeRootAttribute(Type redBase, string suffix, Type kindEnum) : global::System.Attribute | ||
{ | ||
/// <summary> | ||
/// The suffix for nodes in this tree. | ||
/// </summary> | ||
public string Suffix { get; } = suffix; | ||
|
||
/// <summary> | ||
/// The base node type for all nodes in the red tree. | ||
/// </summary> | ||
public global::System.Type RedBase { get; } = redBase; | ||
|
||
/// <summary> | ||
/// The enum type that contains the definitions for the node kinds. | ||
/// </summary> | ||
public global::System.Type KindEnum { get; } = kindEnum; | ||
|
||
/// <summary> | ||
/// Whether to create base visitor implementations for this tree. | ||
/// </summary> | ||
public bool CreateVisitors { get; set; } | ||
|
||
/// <summary> | ||
/// Whether to create a base walker implementation for this tree. | ||
/// </summary> | ||
public bool CreateWalker { get; set; } | ||
|
||
/// <summary> | ||
/// Whether to generate a base rewriter implementation for this tree. | ||
/// </summary> | ||
public bool CreateRewriter { get; set; } | ||
|
||
/// <summary> | ||
/// Whether to generate list types and infrastructure for this tree. | ||
/// This implies in having roslyn MIT-licensed code being added to your project. | ||
/// </summary> | ||
public bool CreateLists { get; set; } | ||
|
||
/// <summary> | ||
/// Whether to generate a file with only comments dumping the entire tree structure. | ||
/// </summary> | ||
public bool DebugDump { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters