C# ANTLR |
, . , !, 25 . , - :
.
, , - 1 , 2 , 5 , . , . C#, :
, . , , , :
-, . , , :
, , :
, Liquid Mustache, . - , . - , , , , . Razor , - : , .NET- , .
, . .
-. : , , , . - -, : . , , , .
-, HTML, , escape-, .
:
${ }
, @{ }
Razor. , HTML-, , .
, TypeScript string interpolation ( C# , ). : , .
-, , . , javascript. , , javascript, . , and
, or
, not
.
:
- javascript, , . . .
-: ANTLR. , , , , . , Antlr ?
ANTLR (ANother Tool for Language Recognition) , , - . Ÿ Google, Oracle Microsoft (, ASP.NET MVC). Antlr , .
, . Antlr java-, , , C#-, StyleCop. , , , , , ( ) . C# , Java, .
, , , , , .
. , Antlr , , , .
. , , , .
. , ${ ... }
@{ .... }
, . , , , . , . .
, Antlr . , , :
. , .
, .
popMode pushMode , , - , .
, , , :
Fluff (, , ) , @
$
, $
@
. Fluff .
, , , , . , ${
, OutputInstructionStart, Fluff .
, . , , , , . , .
Python , , . , Antlr :
, , , .
: , , DIGIT
(IF, ELSE, AND ):
, , , . . else if
( ), elsif
elseif
, .
- , , , IDENTIFIER , :
, .
: . . . ( ):
, , (), ( ) ( ).
, - :
, . 50 :
, if
, else if
( ) else
. If templateBlock , , .
- - , . , ANTLR , , .
Antlr 4 , concrete syntax tree, . concrete , , , . , , . ( ) . , abstract syntax tree .
:
if
, else if
else
)( , ):
internal interface ITemplateNode
{
void PerformSemanticAnalysis(AnalysisContext context);
void Render(StringBuilder resultBuilder, RenderContext renderContext);
}
Roslyn - , , immutable. -, , . -, , . , , .
, Antlr, Visitor. Antlr , , , .
, , , , 50. , .
, @{ if } {else if } {else } .. @{ end if }
:
internal class ConditionsVisitor : QuokkaBaseVisitor
{
public ConditionsVisitor(VisitingContext visitingContext)
: base(visitingContext)
{
}
public override ConditionBlock VisitIfCondition(QuokkaParser.IfConditionContext context)
{
return new ConditionBlock(
context.ifInstruction().booleanExpression().Accept(
new BooleanExpressionVisitor(visitingContext)),
context.templateBlock()?.Accept(
new TemplateVisitor(visitingContext)));
}
public override ConditionBlock VisitElseIfCondition(QuokkaParser.ElseIfConditionContext context)
{
return new ConditionBlock(
context.elseIfInstruction().booleanExpression().Accept(
new BooleanExpressionVisitor(visitingContext)),
context.templateBlock()?.Accept(
new TemplateVisitor(visitingContext)));
}
public override ConditionBlock VisitElseCondition(QuokkaParser.ElseConditionContext context)
{
return new ConditionBlock(
new TrueExpression(),
context.templateBlock()?.Accept(
new TemplateVisitor(visitingContext)));
}
}
ConditionBlock
, . (- ), . , .
: , , , , , .
, , , , - .
, , , .
. , .
. : , , . , Recipient.Email
, Recipietn.Eamil
. , , .
. ${ Recipient.Email + 5 }
, , Email
? , . , , . , ( ), ( , ). , . , . .
:
: , , , , . , .
, . , . , , . , , , -, .
, , , , Id
, Name
. , , . .
: , , - ( ).
: , , , .
, ? , :
, B = 0. , , - :
, , , , :
: , . , . fail fast, , , .
, . , - : - , , . , . , , :
internal class ToUpperTemplateFunction : ScalarTemplateFunction
{
public ToUpperTemplateFunction()
: base(
"toUpper",
new StringFunctionArgument("string"))
{
}
public override string Invoke(string argument1)
{
return argument1.ToUpper(CultureInfo.CurrentCulture);
}
}
: , - , , .
, . , , , Not invented here , , , .
, , , , , .
, , - , , .