schema

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

package schema provides a mechanism to validate the structure of a CONL document.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitLine added in v0.5.1

func SplitLine(line string) (int, int, int, int, int)

returns the range for the key or list item, value, and comment

Types

type Result added in v0.3.1

type Result struct {
	// contains filtered or unexported fields
}

A Result is produced when validating a document against a Schema.

func Validate added in v0.3.0

func Validate(input []byte, load func(schema string) (*Schema, error)) *Result

Validate a CONL document. If load is nil (or returns nil) then Any is used. If the document contains a top-level key 'schema' then its value is passed to load, otherwise load is called with "". The Result can be queried for further information about the match.

func (*Result) DocsForKey added in v0.4.0

func (r *Result) DocsForKey(line int) string

DocsForKey returns the docs for the key on line (1-based)

func (*Result) DocsForValue added in v0.4.0

func (r *Result) DocsForValue(lno int) string

DocsForValue returns the docs for the value on line (1-based)

func (*Result) Errors added in v0.3.1

func (r *Result) Errors() []ValidationError

Errors returns a non-empty list of errors if the result is not valid. As there are many potential ways for a schema to match a document, the exact errors returned may change over time.

func (*Result) SuggestedKeys added in v0.3.1

func (r *Result) SuggestedKeys(line int) []*Suggestion

SuggestedKeys returns possible keys for the map defined on line, or for the root of the document if line == 0. If the value defined on this line is a list, "=" is returned.

func (*Result) SuggestedValues added in v0.3.1

func (r *Result) SuggestedValues(line int) []*Suggestion

SuggestedValues returns possible values to autocomplete on line (1-based)

func (*Result) Valid added in v0.3.1

func (r *Result) Valid() bool

Valid returns true if the document matches the schema. The result may still be queried for other properties even if the document was not valid.

type Schema

type Schema struct {
	// contains filtered or unexported fields
}

A Schema allows you to validate a CONL document against a set of rules.

func Any added in v0.3.0

func Any() *Schema

Any is a schema that validates any CONL document.

func Parse

func Parse(input []byte) (*Schema, error)

Parse a schema from the given input. An error is returned if the input is not valid CONL, or if the schema contains references to definitions that don't exist, invalid regular expressions, or circular references.

func (*Schema) Validate

func (s *Schema) Validate(input []byte) *Result

Validate the input against the schema. The Result can be queried in various ways to determine properties of the input document.

type Suggestion added in v0.4.0

type Suggestion struct {
	Value string
	Docs  string
}

Suggestion is returned by Result.SuggestedKeys or Result.SuggestedValues

type ValidationError

type ValidationError struct {
	// contains filtered or unexported fields
}

A ValidationError represents a single validation error.

func (*ValidationError) Error

func (ve *ValidationError) Error() string

Error returns the error message prefixed by the line number.

func (*ValidationError) Lno

func (ve *ValidationError) Lno() int

Lno returns the line number (1-based) on which the error occurred.

func (*ValidationError) Msg added in v0.3.0

func (ve *ValidationError) Msg() string

Msg returns a human-readable description of the problem suitable for showing to end-users.

func (*ValidationError) RuneRange added in v0.3.0

func (ve *ValidationError) RuneRange(line string) (int, int)

RuneRange returns the 0-based range at which the error occurred (assuming that the provided line corresponds to Lno in the original document).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL