SetAttributeRaw either replaces the expression of an existing attribute of the given name or adds a new attribute definition to the end of the block, using the given tokens verbatim as the expression. The same caveats apply to this function as for NewExpressionRaw on which it is based. If possible,
(name string, tokens Tokens)
| 160 | // it is based. If possible, prefer to use SetAttributeValue or |
| 161 | // SetAttributeTraversal. |
| 162 | func (b *Body) SetAttributeRaw(name string, tokens Tokens) *Attribute { |
| 163 | attr := b.GetAttribute(name) |
| 164 | expr := NewExpressionRaw(tokens) |
| 165 | if attr != nil { |
| 166 | attr.expr = attr.expr.ReplaceWith(expr) |
| 167 | } else { |
| 168 | attr := newAttribute() |
| 169 | attr.init(name, expr) |
| 170 | b.appendItem(attr) |
| 171 | } |
| 172 | return attr |
| 173 | } |
| 174 | |
| 175 | // SetAttributeValue either replaces the expression of an existing attribute |
| 176 | // of the given name or adds a new attribute definition to the end of the block. |