preserve init error

This commit is contained in:
Arpad Ryszka 2025-08-20 00:45:32 +02:00
parent a8bec182b1
commit ab17c3b195
4 changed files with 16 additions and 19 deletions

View File

@ -118,12 +118,10 @@ cpu: cpu.out
go tool pprof -top cpu.out go tool pprof -top cpu.out
fmt: $(SOURCES) fmt: $(SOURCES)
@echo fmt gofmt -w -s $(SOURCES)
@gofmt -w -s $(SOURCES)
checkfmt: $(SOURCES) checkfmt: $(SOURCES)
@echo check fmt if [ "$$(gofmt -s -d $(SOURCES))" != "" ]; then false; else true; fi
@if [ "$$(gofmt -s -d $(SOURCES))" != "" ]; then false; else true; fi
vet: vet:
go vet ./... go vet ./...

View File

@ -2,12 +2,12 @@ package main
import ( import (
"bytes" "bytes"
"code.squareroundforest.org/arpio/treerack"
"flag" "flag"
"golang.org/x/crypto/ssh/terminal"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"code.squareroundforest.org/arpio/treerack"
"golang.org/x/crypto/ssh/terminal"
) )
type fileOptions struct { type fileOptions struct {

View File

@ -1,8 +1,8 @@
package main package main
import ( import (
"encoding/json"
"code.squareroundforest.org/arpio/treerack" "code.squareroundforest.org/arpio/treerack"
"encoding/json"
) )
type showOptions struct { type showOptions struct {

View File

@ -1,10 +1,10 @@
package treerack package treerack
import ( import (
"code.squareroundforest.org/arpio/treerack/self"
"errors" "errors"
"fmt" "fmt"
"io" "io"
"code.squareroundforest.org/arpio/treerack/self"
) )
// if min=0&&max=0, it means min=1,max=1 // if min=0&&max=0, it means min=1,max=1
@ -16,12 +16,12 @@ type SequenceItem struct {
} }
type Syntax struct { type Syntax struct {
registry *registry registry *registry
initialized bool initialized bool
initFailed bool errInitFailed error
explicitRoot bool explicitRoot bool
keywords []definition keywords []definition
root definition root definition
} }
type GeneratorOptions struct { type GeneratorOptions struct {
@ -52,7 +52,6 @@ type definition interface {
var ( var (
ErrSyntaxInitialized = errors.New("syntax initialized") ErrSyntaxInitialized = errors.New("syntax initialized")
ErrInitFailed = errors.New("init failed")
ErrNoParsersDefined = errors.New("no parsers defined") ErrNoParsersDefined = errors.New("no parsers defined")
ErrInvalidEscapeCharacter = errors.New("invalid escape character") ErrInvalidEscapeCharacter = errors.New("invalid escape character")
ErrMultipleRoots = errors.New("multiple roots") ErrMultipleRoots = errors.New("multiple roots")
@ -296,8 +295,8 @@ func (s *Syntax) ReadSyntax(r io.Reader) error {
} }
func (s *Syntax) Init() error { func (s *Syntax) Init() error {
if s.initFailed { if s.errInitFailed != nil {
return ErrInitFailed return s.errInitFailed
} }
if s.initialized { if s.initialized {
@ -324,13 +323,13 @@ func (s *Syntax) Init() error {
for i := range s.keywords { for i := range s.keywords {
if err := s.keywords[i].validate(s.registry); err != nil { if err := s.keywords[i].validate(s.registry); err != nil {
s.initFailed = true s.errInitFailed = err
return err return err
} }
} }
if err := s.root.validate(s.registry); err != nil { if err := s.root.validate(s.registry); err != nil {
s.initFailed = true s.errInitFailed = err
return err return err
} }