-
Notifications
You must be signed in to change notification settings - Fork 39
/
element.go
41 lines (36 loc) · 1007 Bytes
/
element.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package gcss
import "io"
// element represents an element of GCSS source codes.
type element interface {
io.WriterTo
AppendChild(child element)
Base() *elementBase
SetContext(*context)
Context() *context
}
// newElement creates and returns an element.
func newElement(ln *line, parent element) (element, error) {
var e element
var err error
switch {
case ln.isComment():
e = newComment(ln, parent)
case ln.isAtRule():
e = newAtRule(ln, parent)
case ln.isMixinDeclaration():
// error can be ignored becuase the line is checked beforehand
// by calling `ln.isMixinDeclaration()`.
e, _ = newMixinDeclaration(ln, parent)
case ln.isMixinInvocation():
// error can be ignored becuase the line is checked beforehand
// by calling `ln.isMixinInvocation()`.
e, _ = newMixinInvocation(ln, parent)
case ln.isVariable():
e, err = newVariable(ln, parent)
case ln.isDeclaration():
e, err = newDeclaration(ln, parent)
default:
e, err = newSelector(ln, parent)
}
return e, err
}