aboutsummaryrefslogtreecommitdiff
path: root/parser/parser.go
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-09-10 22:13:52 +0200
committerThomas Voss <mail@thomasvoss.com> 2023-09-10 22:13:52 +0200
commit04fbbb7ee058680de2ee1794d84be7a2a3ac5f2d (patch)
treeea6d9938269190f2574409de59def15f155c0360 /parser/parser.go
parent19a1bfada7752fe195de92f838823029146c963d (diff)
Support multiple root-level nodes
Diffstat (limited to 'parser/parser.go')
-rw-r--r--parser/parser.go29
1 files changed, 19 insertions, 10 deletions
diff --git a/parser/parser.go b/parser/parser.go
index d8f7eb6..09a6f49 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -31,18 +31,27 @@ type AstNode struct {
func ParseFile(file *os.File) (AstNode, error) {
r := reader{r: bufio.NewReader(file)}
- return r.parseDocument()
-}
-
-func (reader *reader) parseDocument() (AstNode, error) {
document := AstNode{Type: Tagless}
- if node, err := reader.parseNode(); err != nil {
- return AstNode{}, err
- } else {
- document.Children = append(document.Children, node)
- }
- return document, nil
+ for {
+ if _, err := r.readNonSpaceRune(); err == io.EOF {
+ return document, nil
+ } else if err != nil {
+ return AstNode{}, err
+ } else if err := r.unreadRune(); err != nil {
+ return AstNode{}, err
+ }
+
+ if err := r.skipSpaces(); err != nil {
+ return AstNode{}, err
+ }
+
+ if node, err := r.parseNode(); err != nil {
+ return AstNode{}, err
+ } else {
+ document.Children = append(document.Children, node)
+ }
+ }
}
func (reader *reader) parseNode() (AstNode, error) {