Create and get field types

This commit is contained in:
2024-10-31 13:18:25 -06:00
parent 84f927b918
commit c6922d220a
3 changed files with 100 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
"io"
"slices"
"strconv"
"strings"
"git.codemonkeysoftware.net/b/gigaparsec"
pbytes "git.codemonkeysoftware.net/b/gigaparsec/bytes"
@ -146,12 +147,20 @@ func parseList(input gigaparsec.State[byte]) (gigaparsec.Result[byte, Sexp], err
}
func Parse(data []byte) (Sexp, error) {
return parse(bytes.NewReader(data))
}
func ParseString(data string) (Sexp, error) {
return parse(strings.NewReader(data))
}
func parse(r io.ReaderAt) (Sexp, error) {
parser := gigaparsec.Seq2(
parseSexp,
gigaparsec.End[byte](),
func(s Sexp, _ struct{}) Sexp { return s },
)
result, err := gigaparsec.Run(parser, bytes.NewReader(data))
result, err := gigaparsec.Run(parser, r)
if err != nil {
return nil, fmt.Errorf("csexp.Parse: %w", err)
}