-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] Quotations (Not Macros) #8065
Comments
Dup of #1911 with a different syntax. |
Roughing out the structures. class template
.Header : Template_Header
.Body : Template_Body
class Template_Header
.Name : Template_Identifier
.Parameters : Template_Parameters
class Template_Identifier { }
class Template_Parameters
.Count : Integer
.Parameters : IEnumerable< Template_Parameter >
class Template_Parameter
.Name : Parameter_Identifier
class Template_Body
.Parts : Templates_BodyParts
.Holes : Templates_Holes
base Template_BodyPart
.Index : Integer
.Length : Integer
class Template_Text <: Template_BodyPart { }
class Template_Hole <: Template_BodyPart
.Edge_Left : Hole_EdgeLeft
.Edge_Right : Hole_EdgeRight
.Parameter : Hole_Parameter
class Hole_BodyPart <: Template_BodyPart { }
class Hole_EdgeRight <: Template_BodyPart { }
class Hole_Parameter <: Template_BodyPart
.Name : Parameter_Identifier |
Wrote a little parser and engine for the templating methods. Grammar
Things left to do.
|
We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages. |
Looking the through the issues, it seem that we could benefit from having some mechanism to quote code (aka Quotations).
Everything within the
{ ... }
of the template is considered text, except if it a parameter hole<#= #>
Not Macros
Within the parameter holes, it contents can one refer to parameters of the template. The surrounding context does not exist, each exist independent of each other. Scope is restriction to only parameters of the template.
The target return type (in above example
CompilationUnit
) could be used to help validate the body on the template, within the IDE.During compilation, invocation of a template would produce an instance of
Template
.ToString
would produce a string version of the body of the template (quotation). Just as if it was just a interpolation string.Similar to String Interpolation the argument supplied in a parameter hole would be checked to see if it is in scope. Scope is restriction to only parameters of the template. If it isn't valid then it is compile-time error.
The Compilers could have factory method similar to:=
SyntaxFactory.ParseExpression(string expr)
for example
The text was updated successfully, but these errors were encountered: