dotnet / dotnet/vblang

[WIP] Templates

Open
#68 13 comments 1 reaction 0 assignees View on GitHub
Proposal
Dominant language
No language data
Stars
328
Forks
71
PR merge metrics
No merged PRs in 30d

Description

# Templates [WIP]

### Synopsis

Simplify how code is constructed, via code.

```vbnet
Template DecalarationAndCreateInstance( ... )
Dim ${0}$ As ${1}$ = New ${1}$(${2}$)
End Template
```
When invoked with the correct parameters, outputs as its result a `SyntaxNode` object model representing the code ascribed within the template.

```vbnet
Dim thisNode = DeclarationAndCreateInstance( ... )
```

-----------------

### Internals

The compiler / ide produces on the coder's behalf a code-behind implementation.
```vbnet
Private Class Templates

Shared Function DeclarationAndCreateInstance( ) As SyntaxNode

End Function

End Class
```
The internals of the method is could be generated via some mechanism like [RoslynQuoter](https://github.com/KirillOsenkov/RoslynQuoter).

### Syntax Error and Highlighting
Within the template only basic syntax highlighting is provided, **No diagnostics** are supported. The template is provide "as seen / as is". *Note this doesn't rule out support for functionality at later date, just is won't be in this proposal.*

### Parsing
The parsing of the template *I think* would very similar to the parsing of Interpolation Strings.

------------------
### CSharp
Since the RoslynQuoter supports CSharp, I'll provide a fuller example in that language.
```c#

template Foo
{
class C { }
}
```
*Code-Behind*
```c#
class templates
{
static SyntaxNode Foo()
{
return CompilationUnit().WithMembers(
SingletonList(
ClassDeclaration("Foo")
)
).NormalizeWhitespace()
}
}
```
---------
### Future

### Template Mask
Akin to how regex produces regex matches contained with a piece of text. This will produce a collection of `TemplateMatch`. A `Template Match` is contains the nodes the match the corresponding arguments.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.