internal/third_party/yaml: parse into CUE ast
Also:
- remove support for parsing into Go-structs
- remove support for encoding
- add comment parsing
- port non-standard test harness to standard go
- add testdata
- fix some bugs related to merging
Change-Id: I7fbd2bed6f76bb5da8a309f8d3fb3fb6228048ab
diff --git a/internal/third_party/yaml/yamlh.go b/internal/third_party/yaml/yamlh.go
index e25cee5..93ab268 100644
--- a/internal/third_party/yaml/yamlh.go
+++ b/internal/third_party/yaml/yamlh.go
@@ -3,6 +3,8 @@
import (
"fmt"
"io"
+
+ "cuelang.org/go/cue/token"
)
// The version directive data.
@@ -518,6 +520,29 @@
mark yaml_mark_t // The anchor mark.
}
+type yaml_comment_t struct {
+ pos token.RelPos
+ mark yaml_mark_t
+ text string
+}
+
+func (p *yaml_parser_t) relPos() (pos token.RelPos) {
+ switch {
+ case p.linesSinceLast > 1:
+ pos = token.NewSection
+ case p.linesSinceLast == 1:
+ pos = token.Newline
+ case p.spacesSinceLast > 0:
+ pos = token.Blank
+ default:
+ pos = token.NoSpace
+ }
+ p.linesSinceLast = 0
+ p.spacesSinceLast = 0
+ // fmt.Println("REL", pos)
+ return token.NoRelPos
+}
+
// The parser structure.
//
// All members are internal. Manage the structure using the
@@ -526,6 +551,8 @@
// Error handling
+ filename string
+
error yaml_error_type_t // Error type.
problem string // Error description.
@@ -557,11 +584,16 @@
raw_buffer []byte // The raw buffer.
raw_buffer_pos int // The current position of the buffer.
+ comment_buffer []byte
+
encoding yaml_encoding_t // The input encoding.
offset int // The offset of the current position (in bytes).
mark yaml_mark_t // The mark of the current position.
+ linesSinceLast int
+ spacesSinceLast int
+
// Scanner stuff
stream_start_produced bool // Have we started to scan the input stream?
@@ -574,6 +606,8 @@
tokens_parsed int // The number of tokens fetched from the queue.
token_available bool // Does the tokens queue contain a token ready for dequeueing.
+ comments []yaml_comment_t
+
indent int // The current indentation level.
indents []int // The indentation levels stack.