(allowElseIf bool, context string)
| 889 | } |
| 890 | |
| 891 | func (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 | // |
no test coverage detected