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