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
fmt: $(SOURCES)
@echo fmt
@gofmt -w -s $(SOURCES)
gofmt -w -s $(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:
go vet ./...

View File

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

View File

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

View File

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