Created
June 15, 2020 00:51
-
-
Save bluven/054e59be17d758ccce76bdf432c9d08c to your computer and use it in GitHub Desktop.
a EBNF description of go text/template' grammar
This file contains hidden or 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
Template = {Text | Action} . | |
Action = CommentAction | PipelineAction | IfAction | RangeAction | TemplateAction | BlockAction | WithAction . | |
CommentAction = LD "/*" Text "*/" RD . | |
PipelineAction = LD ( Pipeline | VarDeclarePipeline | VarAssignPipeline ) RD . | |
IfAction = LD "if" Pipeline RD Template [ LD "else" ["if" Pipeline] RD Template ] End . | |
RangeAction = LD "range" ( Pipeline | VarDeclarePipeline ) RD Template [ LD "else" RD Template] End . | |
TemplateAction = LD "template" Name [Pipeline] RD . | |
BlockAction = LD "block" Name [Pipeline] RD . | |
WithAction = LD "with" Pipeline RD Template [ LD "else" RD Template] End . | |
Pipeline = Argument { "|" Argument } | MethodCall | FuncCall { Argument } . | |
VarDeclarePipeline = Variable ["," Variable] ":=" Pipeline | |
VarAssignPipeline = Variable "=" Pipeline | |
Argument = Constant | "nil" | Variable | Fields . | FuncCall | ("(" Argument ")" [Fields] ) . | |
Variable = "$" [Name] . | |
Fields = [Variable] "." Name [ "." Name] . | |
FuncCall = Name . | |
MethodCall = ( Variable | Fields ) { Argument } | |
End = LD "end" RD . | |
LD = "{{" ["-"] . | |
RD = ["-"] "}}" . | |
Name = Letter { Letter | Digit } . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment