1
0
treerack/cmd/treerack/checksyntax.go

33 lines
775 B
Go
Raw Normal View History

2018-01-08 21:03:00 +01:00
package main
2026-01-15 23:33:40 +01:00
import (
"code.squareroundforest.org/arpio/treerack"
"io"
)
2018-01-08 22:06:41 +01:00
2026-01-15 23:33:40 +01:00
type checkSyntaxOptions struct {
2018-01-08 22:06:41 +01:00
2026-01-15 23:33:40 +01:00
// Syntax specifies the filename of the syntax definition file.
2026-01-21 20:54:16 +01:00
Syntax *string
2018-01-08 22:06:41 +01:00
2026-01-15 23:33:40 +01:00
// SyntaxString specifies the syntax as an inline string.
2026-01-21 20:54:16 +01:00
SyntaxString *string
2026-01-15 23:33:40 +01:00
}
2018-01-08 21:03:00 +01:00
2026-01-15 23:33:40 +01:00
// 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
}
2026-01-15 23:33:40 +01:00
defer finalize()
s := &treerack.Syntax{}
if err := s.ReadSyntax(syntax); err != nil {
return err
}
2026-01-15 23:33:40 +01:00
return s.Init()
2018-01-08 21:03:00 +01:00
}