-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


C# ANTLR

, 30 2017 . 13:45 +


, . , !, 25 . , - :



.


, , - 1 , 2 , 5 , . , . C#, :


    ,        .


, . , , , :


  • (Recipient.Address.City.Name)

-, . , , :


  • ( )

, , :



, Liquid Mustache, . - , . - , , , , . Razor , - : , .NET- , .


, . .



-. : , , , . - -, : . , , , .


-, HTML, , escape-, .


:



${ } , @{ } Razor. , HTML-, , .


, TypeScript string interpolation ( C# , ). : , .


-, , . , javascript. , , javascript, . , and, or, not .


:


,    ,  , ,  ,


: , , , .


ANTLR


, - LL-, , , LL(*)-. : .


- javascript, , . . .


-: ANTLR. , , , , . , Antlr ?


ANTLR (ANother Tool for Language Recognition) , , - . Ÿ Google, Oracle Microsoft (, ASP.NET MVC). Antlr , .


, . Antlr java-, , , C#-, StyleCop. , , , , , ( ) . C# , Java, .


, , , , , .


. , Antlr , , , .


:


ANTLR . , - , , .


. , , , .


. , ${ ... } @{ .... }, . , , , . , . .


, Antlr . , , :


       ,           ,


. , .


, .



popMode pushMode , , - , .


, , , :


 - ,     .


Fluff (, , ) , @ $, $ @. Fluff .


, , , , . , ${, OutputInstructionStart, Fluff .


, . , , , , . , .


Python , , . , Antlr :


        ,      - ,        .


, , , .


: , , DIGIT


 Number  : Digit+ ('.'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 , . (- ), . , .


: , , , , , .



, , , , - .



  -  ,    .



        ,   . Powered by Paint.Net


, , , .


. , .



. : , , . , Recipient.Email , Recipietn.Eamil . , , .


. ${ Recipient.Email + 5 }, , Email ? , . , , . , ( ), ( , ). , . , . .


:



    • -
  • ,
  • (, , , ),

: , , , , . , .


, . , . , , . , , , -, .


    ,


, , , , Id, Name. , , . .



: , , - ( ).


: , , , .
, ? , :



, B = 0. , , - :



, , , , :


  • reasonable defaults ( null- , null- false, NaN )
  • fail fast

: , . , . 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 , , , .


, , , , , .


, , - , , .


:


  1. Mindbox
  2. ANTLR
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/329772/

:  

: [1] []
 

:
: 

: ( )

:

  URL