MCPcopy Create free account
hub / github.com/CloudyKit/jet / parseControl

Method parseControl

parse.go:891–927  ·  view source on GitHub ↗
(allowElseIf bool, context string)

Source from the content-addressed store, hash-verified

889}
890
891func (t *Template) parseControl(allowElseIf bool, context string) (pos Pos, line int, set *SetNode, expression Expression, list, elseList *ListNode) {
892 line = t.lex.lineNumber()
893
894 expression = t.assignmentOrExpression(context)
895 pos = expression.Position()
896 if expression.Type() == NodeSet {
897 set = expression.(*SetNode)
898 if context != "range" {
899 t.expect(itemSemicolon, context, "semicolon between assignment and expression")
900 expression = t.expression(context, "expression after assignment")
901 } else {
902 expression = nil
903 }
904 }
905
906 t.expectRightDelim(context)
907 var next Node
908 list, next = t.itemList(nodeElse, nodeEnd)
909 if next.Type() == nodeElse {
910 if allowElseIf && t.peek().typ == itemIf {
911 // Special case for "else if". If the "else" is followed immediately by an "if",
912 // the elseControl will have left the "if" token pending. Treat
913 // {{if a}}_{{else if b}}_{{end}}
914 // as
915 // {{if a}}_{{else}}{{if b}}_{{end}}{{end}}.
916 // To do this, parse the if as usual and stop at it {{end}}; the subsequent{{end}}
917 // is assumed. This technique works even for long if-else-if chains.
918 t.next() // Consume the "if" token.
919 elseList = t.newList(next.Position())
920 elseList.append(t.ifControl())
921 // Do not consume the next item - only one {{end}} required.
922 } else {
923 elseList, _ = t.itemList(nodeEnd)
924 }
925 }
926 return pos, line, set, expression, list, elseList
927}
928
929// If:
930//

Callers 2

ifControlMethod · 0.95
rangeControlMethod · 0.95

Calls 13

PositionMethod · 0.95
TypeMethod · 0.95
expectMethod · 0.95
expressionMethod · 0.95
expectRightDelimMethod · 0.95
itemListMethod · 0.95
peekMethod · 0.95
nextMethod · 0.95
newListMethod · 0.95
ifControlMethod · 0.95
lineNumberMethod · 0.80

Tested by

no test coverage detected