33 lines
775 B
Go
33 lines
775 B
Go
package main
|
|
|
|
import (
|
|
"code.squareroundforest.org/arpio/treerack"
|
|
"io"
|
|
)
|
|
|
|
type checkSyntaxOptions struct {
|
|
|
|
// Syntax specifies the filename of the syntax definition file.
|
|
Syntax *string
|
|
|
|
// SyntaxString specifies the syntax as an inline string.
|
|
SyntaxString *string
|
|
}
|
|
|
|
// checkSyntax validates a syntax definition. The syntax may be provided via a file path (using an option or a
|
|
// positional argument), an inline string, or piped from standard input.
|
|
func checkSyntax(o checkSyntaxOptions, stdin io.Reader, args ...string) error {
|
|
syntax, finalize, err := initInput(o.Syntax, o.SyntaxString, stdin, args)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
defer finalize()
|
|
s := &treerack.Syntax{}
|
|
if err := s.ReadSyntax(syntax); err != nil {
|
|
return err
|
|
}
|
|
|
|
return s.Init()
|
|
}
|