Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 23a6bd090c | |||
| f8fa9d678a | |||
| 7e2797607d |
Vendored
-7
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"cSpell.words": [
|
|
||||||
"asciigoat",
|
|
||||||
"Subname",
|
|
||||||
"unescapes"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -53,12 +53,6 @@ func (field Field) String() string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GoString generates a string output for "%#v"
|
|
||||||
func (*Field) GoString() string {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
return buf.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeSectionToBuffer(w *bytes.Buffer, sec *Section, nl string) int {
|
func writeSectionToBuffer(w *bytes.Buffer, sec *Section, nl string) int {
|
||||||
var written, n int
|
var written, n int
|
||||||
|
|
||||||
@@ -96,12 +90,6 @@ func (sec *Section) String() string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GoString generates a string output for "%#v"
|
|
||||||
func (*Section) GoString() string {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
return buf.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteTo writes a INI representation of the document
|
// WriteTo writes a INI representation of the document
|
||||||
// onto the provided writer.
|
// onto the provided writer.
|
||||||
func (doc *Document) WriteTo(w io.Writer) (int64, error) {
|
func (doc *Document) WriteTo(w io.Writer) (int64, error) {
|
||||||
@@ -114,9 +102,3 @@ func (doc *Document) String() string {
|
|||||||
buf := doc.AsBuffer(WriteNewLine)
|
buf := doc.AsBuffer(WriteNewLine)
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GoString generates a string output for "%#v"
|
|
||||||
func (Document) GoString() string {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
return buf.String()
|
|
||||||
}
|
|
||||||
|
|||||||
-49
@@ -1,49 +0,0 @@
|
|||||||
package ini
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"asciigoat.org/core"
|
|
||||||
"asciigoat.org/ini/parser"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Decoder ...
|
|
||||||
type Decoder struct {
|
|
||||||
io.Closer
|
|
||||||
|
|
||||||
p *parser.Parser
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode ...
|
|
||||||
func (dec *Decoder) Decode() error {
|
|
||||||
defer dec.Close()
|
|
||||||
|
|
||||||
return dec.p.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDecoder creates a Decoder over the provided [io.Reader]
|
|
||||||
func NewDecoder(r io.Reader) *Decoder {
|
|
||||||
rc := core.NewReadCloser(r)
|
|
||||||
switch {
|
|
||||||
case rc == nil:
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
dec := &Decoder{
|
|
||||||
p: parser.NewParser(rc),
|
|
||||||
Closer: rc,
|
|
||||||
}
|
|
||||||
return dec
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDecoderBytes creates a Decoder over a provided bytes array
|
|
||||||
func NewDecoderBytes(b []byte) *Decoder {
|
|
||||||
return NewDecoder(bytes.NewReader(b))
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDecoderString creates a Decoder over a provided string of data
|
|
||||||
func NewDecoderString(s string) *Decoder {
|
|
||||||
return NewDecoder(strings.NewReader(s))
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ replace (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
asciigoat.org/core v0.3.9
|
asciigoat.org/core v0.3.7
|
||||||
github.com/mgechev/revive v1.3.3
|
github.com/mgechev/revive v1.3.3
|
||||||
golang.org/x/tools v0.12.0
|
golang.org/x/tools v0.12.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -43,11 +43,6 @@ var (
|
|||||||
IsCommentStart = lexer.NewIsIn(RunesComment)
|
IsCommentStart = lexer.NewIsIn(RunesComment)
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsAny accepts any rune
|
|
||||||
func IsAny(_ rune) bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsSpaceNotNewLine indicates a rune is whitespace but not a new line
|
// IsSpaceNotNewLine indicates a rune is whitespace but not a new line
|
||||||
func IsSpaceNotNewLine(r rune) bool {
|
func IsSpaceNotNewLine(r rune) bool {
|
||||||
return IsSpace(r) && !IsNewLine(r)
|
return IsSpace(r) && !IsNewLine(r)
|
||||||
|
|||||||
+5
-6
@@ -39,10 +39,9 @@ func (p *TextParser) InitString(s string) {
|
|||||||
|
|
||||||
// Discard shadows [lexer.Reader]'s, and takes in consideration
|
// Discard shadows [lexer.Reader]'s, and takes in consideration
|
||||||
// new lines on the discarded data when moving the position
|
// new lines on the discarded data when moving the position
|
||||||
func (p *TextParser) Discard() {
|
func (*TextParser) Discard() {
|
||||||
s := p.Reader.Emit()
|
// TODO: consider new lines
|
||||||
l := GetPositionalLength(s)
|
panic("not implemented")
|
||||||
p.pos.Add(l)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit returns the accepted text, its position, and
|
// Emit returns the accepted text, its position, and
|
||||||
@@ -50,8 +49,8 @@ func (p *TextParser) Discard() {
|
|||||||
func (p *TextParser) Emit() (lexer.Position, string) {
|
func (p *TextParser) Emit() (lexer.Position, string) {
|
||||||
pos := p.pos
|
pos := p.pos
|
||||||
s := p.Reader.Emit()
|
s := p.Reader.Emit()
|
||||||
l := GetPositionalLength(s)
|
// TODO: consider new lines
|
||||||
p.pos.Add(l)
|
p.pos.StepN(len(s))
|
||||||
|
|
||||||
return pos, s
|
return pos, s
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package parser
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"asciigoat.org/core/lexer"
|
|
||||||
)
|
|
||||||
|
|
||||||
type positionLengthParser struct {
|
|
||||||
TextParser
|
|
||||||
|
|
||||||
lexer.Position
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *positionLengthParser) lexStart() (lexer.StateFn, error) {
|
|
||||||
for {
|
|
||||||
switch {
|
|
||||||
case p.AcceptNewLine():
|
|
||||||
p.Position.StepLine()
|
|
||||||
case p.Accept(IsAny):
|
|
||||||
p.Position.StepN(1)
|
|
||||||
default:
|
|
||||||
return nil, io.EOF
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPositionalLength calculates the [lexer.Position] at
|
|
||||||
// the end of a text.
|
|
||||||
func GetPositionalLength(s string) lexer.Position {
|
|
||||||
var p positionLengthParser
|
|
||||||
if s == "" {
|
|
||||||
p.InitString(s)
|
|
||||||
|
|
||||||
_ = lexer.Run(p.lexStart)
|
|
||||||
}
|
|
||||||
return p.Position
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package ini
|
|
||||||
|
|
||||||
import "io"
|
|
||||||
|
|
||||||
// ReadInto ...
|
|
||||||
func ReadInto(v any, r io.Reader) error {
|
|
||||||
dec := NewDecoder(r)
|
|
||||||
|
|
||||||
return dec.Unmarshal(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshal ...
|
|
||||||
func (dec *Decoder) Unmarshal(any) error {
|
|
||||||
return dec.p.Run()
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user