From 292d7691b7e716c33a92f089307a8f6c2635620a Mon Sep 17 00:00:00 2001 From: Markus Zimmermann Date: Sun, 27 Jul 2014 11:38:14 +0200 Subject: [PATCH] lower case beginning for all error messages --- bin/tavor.go | 32 +++++------ fuzz/strategy/allpermutations.go | 28 ++++----- fuzz/strategy/almostallpermutations.go | 28 ++++----- fuzz/strategy/permuteoptionals.go | 24 ++++---- fuzz/strategy/random.go | 10 ++-- parser/internal.go | 8 +-- parser/tavor.go | 80 +++++++++++++------------- reduce/strategy/binarysearch.go | 32 ++++++----- reduce/strategy/strategy.go | 6 +- tavor.go | 20 +++---- token/primitives/int.go | 8 +-- token/primitives/string.go | 4 +- token/token.go | 8 +-- 13 files changed, 145 insertions(+), 143 deletions(-) diff --git a/bin/tavor.go b/bin/tavor.go index 0e0c5d5..5b974a9 100644 --- a/bin/tavor.go +++ b/bin/tavor.go @@ -72,7 +72,7 @@ var opts struct { Validate struct { InputFile flags.Filename `long:"input-file" description:"Input file which gets parsed and validated via the format file" required:"true"` - } `command:"validate" description:"Validate the given format file"` + } `command:"validate" description:"Validate the given input file"` } type FuzzFilter string @@ -188,7 +188,7 @@ func checkArguments() string { } } - log.Infof("Using seed %d", opts.Global.Seed) + log.Infof("using seed %d", opts.Global.Seed) return p.Active.Name } @@ -231,7 +231,7 @@ func applyFilters(filterNames []FuzzFilter, doc token.Token) token.Token { filters = append(filters, filt) - log.Infof("Using %s fuzzing filter", name) + log.Infof("using %s fuzzing filter", name) } doc, err = fuzzFilter.ApplyFilters(filters, doc) @@ -246,7 +246,7 @@ func applyFilters(filterNames []FuzzFilter, doc token.Token) token.Token { func main() { command := checkArguments() - log.Infof("Open file %s", opts.Format.FormatFile) + log.Infof("open file %s", opts.Format.FormatFile) file, err := os.Open(string(opts.Format.FormatFile)) if err != nil { @@ -259,7 +259,7 @@ func main() { exitError("cannot parse tavor file: %v", err) } - log.Info("Format file is valid") + log.Info("format file is valid") if opts.Format.PrintInternal { tavor.PrettyPrintInternalTree(os.Stdout, doc) @@ -275,14 +275,14 @@ func main() { case "fuzz": doc = applyFilters(opts.Fuzz.Filters, doc) - log.Infof("Counted %d overall permutations", doc.PermutationsAll()) + log.Infof("counted %d overall permutations", doc.PermutationsAll()) strat, err := fuzzStrategy.New(string(opts.Fuzz.Strategy), doc) if err != nil { exitError(err.Error()) } - log.Infof("Using %s fuzzing strategy", opts.Fuzz.Strategy) + log.Infof("using %s fuzzing strategy", opts.Fuzz.Strategy) ch, err := strat.Fuzz(r) if err != nil { @@ -305,7 +305,7 @@ func main() { } } - log.Debug("Result:") + log.Debug("result:") fmt.Print(doc.String()) fmt.Print(opts.Fuzz.ResultSeparator) } else { @@ -314,7 +314,7 @@ func main() { file := fmt.Sprintf("%s%x%s", folder, sum, opts.Fuzz.ResultExtensions) - log.Infof("Write result to %s", file) + log.Infof("write result to %s", file) if err := ioutil.WriteFile(file, []byte(out), 0644); err != nil { exitError("error writing to %s: %v", file, err) @@ -343,9 +343,9 @@ func main() { errs := parser.ParseInternal(doc, input) if len(errs) == 0 { - log.Info("Input file is valid") + log.Info("input file is valid") } else { - log.Info("Input file is invalid") + log.Info("input file is invalid") for _, err := range errs { log.Error(err) @@ -360,7 +360,7 @@ func main() { exitError(err.Error()) } - log.Infof("Using %s reducing strategy", opts.Reduce.Strategy) + log.Infof("using %s reducing strategy", opts.Reduce.Strategy) contin, feedback, err := strat.Reduce() if err != nil { @@ -370,7 +370,7 @@ func main() { readCLI := bufio.NewReader(os.Stdin) for i := range contin { - log.Debug("Result:") + log.Debug("result:") fmt.Print(doc.String()) fmt.Print(opts.Reduce.ResultSeparator) @@ -396,14 +396,14 @@ func main() { contin <- i } - log.Info("Reduced to minimum") + log.Info("reduced to minimum") - log.Debug("Result:") + log.Debug("result:") fmt.Print(doc.String()) fmt.Print(opts.Reduce.ResultSeparator) } default: - exitError("Unknown command %q", command) + exitError("unknown command %q", command) } os.Exit(returnOk) diff --git a/fuzz/strategy/allpermutations.go b/fuzz/strategy/allpermutations.go index d321548..69b1ab2 100644 --- a/fuzz/strategy/allpermutations.go +++ b/fuzz/strategy/allpermutations.go @@ -72,7 +72,7 @@ func (s *AllPermutationsStrategy) getTree(root token.Token, fromChildren bool) [ } func (s *AllPermutationsStrategy) setPermutation(tok token.Token, permutation int) { - log.Debugf("Set %#v(%p) to permutation %d", tok, tok, permutation) + log.Debugf("set %#v(%p) to permutation %d", tok, tok, permutation) if err := tok.Permutation(permutation); err != nil { panic(err) @@ -82,7 +82,7 @@ func (s *AllPermutationsStrategy) setPermutation(tok token.Token, permutation in func (s *AllPermutationsStrategy) Fuzz(r rand.Rand) (chan struct{}, error) { if tavor.LoopExists(s.root) { return nil, &StrategyError{ - Message: "Found endless loop in graph. Cannot proceed.", + Message: "found endless loop in graph. Cannot proceed.", Type: StrategyErrorEndlessLoopDetected, } } @@ -90,17 +90,17 @@ func (s *AllPermutationsStrategy) Fuzz(r rand.Rand) (chan struct{}, error) { continueFuzzing := make(chan struct{}) go func() { - log.Debug("Start all permutations routine") + log.Debug("start all permutations routine") tree := s.getTree(s.root, false) - log.Debug("Start fuzzing step") + log.Debug("start fuzzing step") if contin, _ := s.fuzz(continueFuzzing, tree, false); !contin { return } - log.Debug("Finished fuzzing.") + log.Debug("finished fuzzing.") close(continueFuzzing) }() @@ -109,7 +109,7 @@ func (s *AllPermutationsStrategy) Fuzz(r rand.Rand) (chan struct{}, error) { } func (s *AllPermutationsStrategy) fuzz(continueFuzzing chan struct{}, tree []allPermutationsLevel, justastep bool) (bool, bool) { - log.Debugf("Fuzzing level %d->%#v", len(tree), tree) + log.Debugf("fuzzing level %d->%#v", len(tree), tree) STEP: for { @@ -126,7 +126,7 @@ STEP: log.Debugf("PERMUTATE after child step") } else { - log.Debugf("Permute %d->%#v", 0, tree[0]) + log.Debugf("permute %d->%#v", 0, tree[0]) if tree[0].permutation != 1 { s.setPermutation(tree[0].token, tree[0].permutation) @@ -158,14 +158,14 @@ STEP: if tree[0].permutation > tree[0].maxPermutations { for i := 0; i < len(tree); i++ { - log.Debugf("Check %d vs %d for %#v", tree[i].permutation, tree[i].maxPermutations, tree[i]) + log.Debugf("check %d vs %d for %#v", tree[i].permutation, tree[i].maxPermutations, tree[i]) } i := 0 for { if i == len(tree)-1 { - log.Debugf("Done with fuzzing this level because %#v", tree) + log.Debugf("done with fuzzing this level because %#v", tree) break STEP } @@ -205,7 +205,7 @@ STEP: tree[j].children = s.getTree(tree[j].token, true) } - log.Debugf("Permute %d->%#v", i, tree[i]) + log.Debugf("permute %d->%#v", i, tree[i]) s.setPermutation(tree[i].token, tree[i].permutation) tree[i].children = s.getTree(tree[i].token, true) @@ -233,19 +233,19 @@ STEP: func (s *AllPermutationsStrategy) nextStep(continueFuzzing chan struct{}) bool { s.resetResetTokens() - log.Debug("Done with fuzzing step") + log.Debug("done with fuzzing step") // done with this fuzzing step continueFuzzing <- struct{}{} // wait until we are allowed to continue if _, ok := <-continueFuzzing; !ok { - log.Debug("Fuzzing channel closed from outside") + log.Debug("fuzzing channel closed from outside") return false } - log.Debug("Start fuzzing step") + log.Debug("start fuzzing step") return true } @@ -260,7 +260,7 @@ func (s *AllPermutationsStrategy) resetResetTokens() { switch tok := v.(type) { case token.ResetToken: - log.Debugf("Reset %#v(%p)", tok, tok) + log.Debugf("reset %#v(%p)", tok, tok) tok.Reset() } diff --git a/fuzz/strategy/almostallpermutations.go b/fuzz/strategy/almostallpermutations.go index afea457..1fa176e 100644 --- a/fuzz/strategy/almostallpermutations.go +++ b/fuzz/strategy/almostallpermutations.go @@ -89,7 +89,7 @@ func (s *AlmostAllPermutationsStrategy) getLevel(root token.Token, fromChildren func (s *AlmostAllPermutationsStrategy) Fuzz(r rand.Rand) (chan struct{}, error) { if tavor.LoopExists(s.root) { return nil, &StrategyError{ - Message: "Found endless loop in graph. Cannot proceed.", + Message: "found endless loop in graph. Cannot proceed.", Type: StrategyErrorEndlessLoopDetected, } } @@ -99,12 +99,12 @@ func (s *AlmostAllPermutationsStrategy) Fuzz(r rand.Rand) (chan struct{}, error) s.resetedLookup = make(map[token.Token]int) go func() { - log.Debug("Start almost all permutations routine") + log.Debug("start almost all permutations routine") level := s.getLevel(s.root, false) if len(level) != 0 { - log.Debug("Start fuzzing step") + log.Debug("start fuzzing step") if !s.fuzz(continueFuzzing, level) { return @@ -113,15 +113,15 @@ func (s *AlmostAllPermutationsStrategy) Fuzz(r rand.Rand) (chan struct{}, error) s.resetResetTokens() - log.Debug("Done with fuzzing step") + log.Debug("done with fuzzing step") // done with the last fuzzing step continueFuzzing <- struct{}{} - log.Debug("Finished fuzzing. Wait till the outside is ready to close.") + log.Debug("finished fuzzing. Wait till the outside is ready to close.") if _, ok := <-continueFuzzing; ok { - log.Debug("Close fuzzing channel") + log.Debug("close fuzzing channel") close(continueFuzzing) } @@ -140,7 +140,7 @@ func (s *AlmostAllPermutationsStrategy) resetResetTokens() { switch tok := v.(type) { case token.ResetToken: - log.Debugf("Reset %#v(%p)", tok, tok) + log.Debugf("reset %#v(%p)", tok, tok) tok.Reset() } @@ -170,7 +170,7 @@ func (s *AlmostAllPermutationsStrategy) setTokenPermutation(tok token.Token, per } func (s *AlmostAllPermutationsStrategy) fuzz(continueFuzzing chan struct{}, level []almostAllPermutationsLevel) bool { - log.Debugf("Fuzzing level %d->%#v", len(level), level) + log.Debugf("fuzzing level %d->%#v", len(level), level) last := len(level) - 1 @@ -179,7 +179,7 @@ STEP: for i := range level { if level[i].permutation > level[i].maxPermutations { if i <= last { - log.Debugf("Max reached redo everything <= %d and increment next", i) + log.Debugf("max reached redo everything <= %d and increment next", i) level[i+1].permutation++ s.setTokenPermutation(level[i+1].token, level[i+1].permutation) @@ -195,7 +195,7 @@ STEP: continue STEP } - log.Debugf("Permute %d->%#v", i, level[i]) + log.Debugf("permute %d->%#v", i, level[i]) s.setTokenPermutation(level[i].token, level[i].permutation) @@ -224,7 +224,7 @@ STEP: } } if !found { - log.Debug("Done with fuzzing this level") + log.Debug("done with fuzzing this level") break STEP } @@ -232,19 +232,19 @@ STEP: s.resetResetTokens() - log.Debug("Done with fuzzing step") + log.Debug("done with fuzzing step") // done with this fuzzing step continueFuzzing <- struct{}{} // wait until we are allowed to continue if _, ok := <-continueFuzzing; !ok { - log.Debug("Fuzzing channel closed from outside") + log.Debug("fuzzing channel closed from outside") return false } - log.Debug("Start fuzzing step") + log.Debug("start fuzzing step") s.resetedLookup = make(map[token.Token]int) } diff --git a/fuzz/strategy/permuteoptionals.go b/fuzz/strategy/permuteoptionals.go index 700b7b5..16460e1 100644 --- a/fuzz/strategy/permuteoptionals.go +++ b/fuzz/strategy/permuteoptionals.go @@ -65,7 +65,7 @@ func (s *PermuteOptionalsStrategy) findOptionals(r rand.Rand, root token.Token, continue } - log.Debugf("Found optional %#v", t) + log.Debugf("found optional %#v", t) t.Deactivate() @@ -102,7 +102,7 @@ func (s *PermuteOptionalsStrategy) resetResetTokens() { switch tok := v.(type) { case token.ResetToken: - log.Debugf("Reset %#v(%p)", tok, tok) + log.Debugf("reset %#v(%p)", tok, tok) tok.Reset() } @@ -124,7 +124,7 @@ func (s *PermuteOptionalsStrategy) resetResetTokens() { func (s *PermuteOptionalsStrategy) Fuzz(r rand.Rand) (chan struct{}, error) { if tavor.LoopExists(s.root) { return nil, &StrategyError{ - Message: "Found endless loop in graph. Cannot proceed.", + Message: "found endless loop in graph. Cannot proceed.", Type: StrategyErrorEndlessLoopDetected, } } @@ -132,7 +132,7 @@ func (s *PermuteOptionalsStrategy) Fuzz(r rand.Rand) (chan struct{}, error) { continueFuzzing := make(chan struct{}) go func() { - log.Debug("Start permute optionals routine") + log.Debug("start permute optionals routine") optionals := s.findOptionals(r, s.root, false) @@ -144,15 +144,15 @@ func (s *PermuteOptionalsStrategy) Fuzz(r rand.Rand) (chan struct{}, error) { s.resetResetTokens() - log.Debug("Done with fuzzing step") + log.Debug("done with fuzzing step") // done with the last fuzzing step continueFuzzing <- struct{}{} - log.Debug("Finished fuzzing. Wait till the outside is ready to close.") + log.Debug("finished fuzzing. Wait till the outside is ready to close.") if _, ok := <-continueFuzzing; ok { - log.Debug("Close fuzzing channel") + log.Debug("close fuzzing channel") close(continueFuzzing) } @@ -162,7 +162,7 @@ func (s *PermuteOptionalsStrategy) Fuzz(r rand.Rand) (chan struct{}, error) { } func (s *PermuteOptionalsStrategy) fuzz(r rand.Rand, continueFuzzing chan struct{}, optionals []token.OptionalToken) bool { - log.Debugf("Fuzzing optionals %#v", optionals) + log.Debugf("fuzzing optionals %#v", optionals) // TODO make this WAYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY smarter // since we can only fuzz 64 optionals at max @@ -171,7 +171,7 @@ func (s *PermuteOptionalsStrategy) fuzz(r rand.Rand, continueFuzzing chan struct maxSteps := int(math.Pow(2, float64(len(optionals)))) for { - log.Debugf("Fuzzing step %b", p) + log.Debugf("fuzzing step %b", p) ith := 1 @@ -196,21 +196,21 @@ func (s *PermuteOptionalsStrategy) fuzz(r rand.Rand, continueFuzzing chan struct p++ if p == maxSteps { - log.Debug("Done with fuzzing these optionals") + log.Debug("done with fuzzing these optionals") break } s.resetResetTokens() - log.Debug("Done with fuzzing step") + log.Debug("done with fuzzing step") // done with this fuzzing step continueFuzzing <- struct{}{} // wait until we are allowed to continue if _, ok := <-continueFuzzing; !ok { - log.Debug("Fuzzing channel closed from outside") + log.Debug("fuzzing channel closed from outside") return false } diff --git a/fuzz/strategy/random.go b/fuzz/strategy/random.go index 050a2ae..6fbb7ea 100644 --- a/fuzz/strategy/random.go +++ b/fuzz/strategy/random.go @@ -27,7 +27,7 @@ func init() { func (s *RandomStrategy) Fuzz(r rand.Rand) (chan struct{}, error) { if tavor.LoopExists(s.root) { return nil, &StrategyError{ - Message: "Found endless loop in graph. Cannot proceed.", + Message: "found endless loop in graph. Cannot proceed.", Type: StrategyErrorEndlessLoopDetected, } } @@ -35,19 +35,19 @@ func (s *RandomStrategy) Fuzz(r rand.Rand) (chan struct{}, error) { continueFuzzing := make(chan struct{}) go func() { - log.Debug("Start random fuzzing routine") + log.Debug("start random fuzzing routine") s.fuzz(s.root, r) - log.Debug("Done with fuzzing step") + log.Debug("done with fuzzing step") // done with the last fuzzing step continueFuzzing <- struct{}{} - log.Debug("Finished fuzzing. Wait till the outside is ready to close.") + log.Debug("finished fuzzing. Wait till the outside is ready to close.") if _, ok := <-continueFuzzing; ok { - log.Debug("Close fuzzing channel") + log.Debug("close fuzzing channel") close(continueFuzzing) } diff --git a/parser/internal.go b/parser/internal.go index c327a03..2aec840 100644 --- a/parser/internal.go +++ b/parser/internal.go @@ -10,11 +10,11 @@ import ( ) func ParseInternal(root token.Token, src io.Reader) []error { - log.Debug("Start internal parsing") + log.Debug("start internal parsing") if root == nil { return []error{&token.ParserError{ - Message: "Root token is nil", + Message: "root token is nil", Type: token.ParseErrorRootIsNil, }} } @@ -31,7 +31,7 @@ func ParseInternal(root token.Token, src io.Reader) []error { nex, errs := root.Parse(p, 0) if len(errs) != 0 { - log.Debugf("Internal parsing failed %v", errs) + log.Debugf("internal parsing failed %v", errs) return errs } else if nex != p.DataLen { @@ -50,7 +50,7 @@ func ParseInternal(root token.Token, src io.Reader) []error { }} } - log.Debugf("Finished internal parsing") + log.Debugf("finished internal parsing") return nil } diff --git a/parser/tavor.go b/parser/tavor.go index 5241fd7..a5853d5 100644 --- a/parser/tavor.go +++ b/parser/tavor.go @@ -51,7 +51,7 @@ type tavorParser struct { func (p *tavorParser) expectRune(expect rune, got rune) (rune, error) { if got != expect { return got, &token.ParserError{ - Message: fmt.Sprintf("Expected %q but got %q", scanner.TokenString(expect), scanner.TokenString(got)), + Message: fmt.Sprintf("expected %q but got %q", scanner.TokenString(expect), scanner.TokenString(got)), Type: token.ParseErrorExpectRune, Position: p.scan.Pos(), } @@ -94,7 +94,7 @@ func (p *tavorParser) parseGlobalScope() error { continue default: return &token.ParserError{ - Message: fmt.Sprintf("Token names have to start with a letter and not with %s", scanner.TokenString(c)), + Message: fmt.Sprintf("token names have to start with a letter and not with %s", scanner.TokenString(c)), Type: token.ParseErrorInvalidTokenName, Position: p.scan.Pos(), } @@ -207,7 +207,7 @@ OUT: tok = ntok } } else { - log.Debugf("Use token (%p)%#v", tok, tok) + log.Debugf("use token (%p)%#v", tok, tok) } p.lookupUsage[tok] = struct{}{} @@ -226,7 +226,7 @@ OUT: if s[len(s)-1] != '"' { return zeroRune, nil, nil, &token.ParserError{ - Message: "String is not terminated", + Message: "string is not terminated", Type: token.ParseErrorNonTerminatedString, Position: p.scan.Pos(), } @@ -382,7 +382,7 @@ OUT: if c == '\n' { return zeroRune, nil, nil, &token.ParserError{ - Message: "Multi line token definition unexpectedly terminated", + Message: "multi line token definition unexpectedly terminated", Type: token.ParseErrorUnexpectedTokenDefinitionTermination, Position: p.scan.Pos(), } @@ -421,7 +421,7 @@ func (p *tavorParser) parseExpression(c rune) (token.Token, error) { return nil, err } else if tok == nil { return nil, &token.ParserError{ - Message: "Empty expressions are not allowed", + Message: "empty expressions are not allowed", Type: token.ParseErrorEmptyExpressionIsInvalid, Position: p.scan.Pos(), // TODO correct position } @@ -475,7 +475,7 @@ func (p *tavorParser) parseExpressionTerm(c rune) (rune, token.Token, error) { return zeroRune, nil, err } else if t == nil { return zeroRune, nil, &token.ParserError{ - Message: "Expected another expression term after operator", + Message: "expected another expression term after operator", Type: token.ParseErrorExpectedExpressionTerm, Position: p.scan.Pos(), } @@ -497,7 +497,7 @@ func (p *tavorParser) parseExpressionTerm(c rune) (rune, token.Token, error) { } func (p *tavorParser) parseTokenAttribute(c rune) (token.Token, error) { - log.Debug("New token attribute") + log.Debug("new token attribute") _, err := p.expectRune(scanner.Ident, c) if err != nil { @@ -523,7 +523,7 @@ func (p *tavorParser) parseTokenAttribute(c rune) (token.Token, error) { use, ok := p.lookup[name] if !ok { return nil, &token.ParserError{ - Message: fmt.Sprintf("Token %q is not defined", name), + Message: fmt.Sprintf("token %q is not defined", name), Type: token.ParseErrorTokenNotDefined, Position: p.scan.Pos(), } @@ -531,11 +531,11 @@ func (p *tavorParser) parseTokenAttribute(c rune) (token.Token, error) { tok := use.token - log.Debugf("Use (%p)%#v as token", tok, tok) + log.Debugf("use (%p)%#v as token", tok, tok) p.used[name] = tokenPosition - log.Debug("Finished token attribute (or will be unknown token attribute)") + log.Debug("finished token attribute (or will be unknown token attribute)") switch i := tok.(type) { case lists.List: @@ -560,7 +560,7 @@ func (p *tavorParser) parseTokenAttribute(c rune) (token.Token, error) { } return nil, &token.ParserError{ - Message: fmt.Sprintf("Unknown token attribute %q for token type %q", attribute, reflect.TypeOf(tok)), + Message: fmt.Sprintf("unknown token attribute %q for token type %q", attribute, reflect.TypeOf(tok)), Type: token.ParseErrorUnknownTokenAttribute, Position: p.scan.Pos(), } @@ -655,7 +655,7 @@ func (p *tavorParser) parseTokenDefinition() (rune, error) { // if there is a pointer in the lookup hash we can say that it was just used before if _, ok := use.token.(*primitives.Pointer); !ok { return zeroRune, &token.ParserError{ - Message: "Token already defined", + Message: "token already defined", Type: token.ParseErrorTokenAlreadyDefined, Position: p.scan.Pos(), } @@ -668,7 +668,7 @@ func (p *tavorParser) parseTokenDefinition() (rune, error) { // unexpected new line? if c == '\n' { return zeroRune, &token.ParserError{ - Message: "New line inside single line token definitions is not allowed", + Message: "new line inside single line token definitions is not allowed", Type: token.ParseErrorEarlyNewLine, Position: p.scan.Pos(), } @@ -687,14 +687,14 @@ func (p *tavorParser) parseTokenDefinition() (rune, error) { p.embeddedTokensInTerm[name] = embeddedToks - log.Debugf("Token %s embeds %+v", name, embeddedToks) + log.Debugf("token %s embeds %+v", name, embeddedToks) log.Debugf("back to token definition with c=%c", c) // we always want a new line at the end of the file if c == scanner.EOF { return zeroRune, &token.ParserError{ - Message: "New line at end of token definition needed", + Message: "new line at end of token definition needed", Type: token.ParseErrorNewLineNeeded, Position: p.scan.Pos(), } @@ -709,7 +709,7 @@ func (p *tavorParser) parseTokenDefinition() (rune, error) { switch len(tokens) { case 0: return zeroRune, &token.ParserError{ - Message: "Empty token definition", + Message: "empty token definition", Type: token.ParseErrorEmptyTokenDefinition, Position: p.scan.Pos(), } @@ -724,12 +724,12 @@ func (p *tavorParser) parseTokenDefinition() (rune, error) { log.Debugf("parseTokenDefinition fill empty pointer for %s", name) for _, use := range uses { - log.Debugf("Use (%p)%#v for pointer (%p)%#v", tok, tok, use.token, use.token) + log.Debugf("use (%p)%#v for pointer (%p)%#v", tok, tok, use.token, use.token) err = use.token.(*primitives.Pointer).Set(tok) if err != nil { return zeroRune, &token.ParserError{ - Message: fmt.Sprintf("Wrong token type for %s because of earlier usage: %s", name, err), + Message: fmt.Sprintf("wrong token type for %s because of earlier usage: %s", name, err), Type: token.ParseErrorInvalidTokenType, Position: p.scan.Pos(), } @@ -743,8 +743,8 @@ func (p *tavorParser) parseTokenDefinition() (rune, error) { if len(embeddedToks) != 0 { foundExit := false - log.Debugf("Need to check for loops in %s with embedding %+v", name, embeddedToks) - log.Debugf("Use embedding lookup map %+v", p.embeddedTokensInTerm) + log.Debugf("need to check for loops in %s with embedding %+v", name, embeddedToks) + log.Debugf("use embedding lookup map %+v", p.embeddedTokensInTerm) EMBEDDEDTOKS: for _, toks := range embeddedToks { @@ -760,7 +760,7 @@ func (p *tavorParser) parseTokenDefinition() (rune, error) { n := i.(string) if name == n { - log.Debug("Found one loop") + log.Debug("found one loop") continue EMBEDDEDTOKS } @@ -776,7 +776,7 @@ func (p *tavorParser) parseTokenDefinition() (rune, error) { } } - log.Debug("Found exit, everything is fine.") + log.Debug("found exit, everything is fine.") foundExit = true @@ -784,10 +784,10 @@ func (p *tavorParser) parseTokenDefinition() (rune, error) { } if !foundExit { - log.Debug("There is no loop exit for this token, I'll throw an error.") + log.Debug("there is no loop exit for this token, I'll throw an error.") return zeroRune, &token.ParserError{ - Message: fmt.Sprintf("Token %q has an endless loop without exit\n", name), + Message: fmt.Sprintf("token %q has an endless loop without exit\n", name), Type: token.ParseErrorEndlessLoopDetected, Position: p.scan.Pos(), // TODO correct position } @@ -799,7 +799,7 @@ func (p *tavorParser) parseTokenDefinition() (rune, error) { position: tokenPosition, } - log.Debugf("Added (%p)%#v as token %s", tok, tok, name) + log.Debugf("added (%p)%#v as token %s", tok, tok, name) c = p.scan.Scan() log.Debugf("parseTokenDefinition after newline %d:%v -> %v", p.scan.Line, scanner.TokenString(c), p.scan.TokenText()) @@ -819,7 +819,7 @@ func (p *tavorParser) parseSpecialTokenDefinition() (rune, error) { name := p.scan.TokenText() if _, ok := p.lookup[name]; ok { return zeroRune, &token.ParserError{ - Message: "Token already defined", + Message: "token already defined", Type: token.ParseErrorTokenAlreadyDefined, Position: p.scan.Pos(), } @@ -854,7 +854,7 @@ func (p *tavorParser) parseSpecialTokenDefinition() (rune, error) { arguments[arg] = p.scan.TokenText() default: return zeroRune, &token.ParserError{ - Message: fmt.Sprintf("Invalid argument value %v", c), + Message: fmt.Sprintf("invalid argument value %v", c), Type: token.ParseErrorInvalidArgumentValue, Position: p.scan.Pos(), } @@ -875,7 +875,7 @@ func (p *tavorParser) parseSpecialTokenDefinition() (rune, error) { // we always want a new line at the end of the file if c == scanner.EOF { return zeroRune, &token.ParserError{ - Message: "New line at end of token definition needed", + Message: "new line at end of token definition needed", Type: token.ParseErrorNewLineNeeded, Position: p.scan.Pos(), } @@ -888,7 +888,7 @@ func (p *tavorParser) parseSpecialTokenDefinition() (rune, error) { typ, ok := arguments["type"] if !ok { return zeroRune, &token.ParserError{ - Message: "Special token has no type argument", + Message: "special token has no type argument", Type: token.ParseErrorUnknownTypeForSpecialToken, Position: p.scan.Pos(), } @@ -907,13 +907,13 @@ func (p *tavorParser) parseSpecialTokenDefinition() (rune, error) { if okFrom || okTo { if okFrom && !okTo { return zeroRune, &token.ParserError{ - Message: "Argument \"to\" is missing", + Message: "argument \"to\" is missing", Type: token.ParseErrorMissingSpecialTokenArgument, Position: p.scan.Pos(), } } else if !okFrom && okTo { return zeroRune, &token.ParserError{ - Message: "Argument \"from\" is missing", + Message: "argument \"from\" is missing", Type: token.ParseErrorMissingSpecialTokenArgument, Position: p.scan.Pos(), } @@ -991,7 +991,7 @@ func (p *tavorParser) parseSpecialTokenDefinition() (rune, error) { tok = sequences.NewSequence(start, step) default: return zeroRune, &token.ParserError{ - Message: fmt.Sprintf("Unknown special token type %q", typ), + Message: fmt.Sprintf("unknown special token type %q", typ), Type: token.ParseErrorUnknownSpecialTokenType, Position: p.scan.Pos(), } @@ -1000,7 +1000,7 @@ func (p *tavorParser) parseSpecialTokenDefinition() (rune, error) { for arg := range arguments { if _, ok := usedArguments[arg]; !ok { return zeroRune, &token.ParserError{ - Message: fmt.Sprintf("Unknown special token argument %q", arg), + Message: fmt.Sprintf("unknown special token argument %q", arg), Type: token.ParseErrorUnknownSpecialTokenArgument, Position: p.scan.Pos(), } @@ -1012,7 +1012,7 @@ func (p *tavorParser) parseSpecialTokenDefinition() (rune, error) { position: tokenPosition, } - log.Debugf("Added (%p)%#v as token %s", tok, tok, name) + log.Debugf("added (%p)%#v as token %s", tok, tok, name) c = p.scan.Scan() log.Debugf("parseSpecialTokenDefinition after newline %d:%v -> %v", p.scan.Line, scanner.TokenString(c), p.scan.TokenText()) @@ -1031,7 +1031,7 @@ func ParseTavor(src io.Reader) (token.Token, error) { used: make(map[string]scanner.Position), } - log.Debug("Start parsing tavor file") + log.Debug("start parsing tavor file") p.scan.Init(src) @@ -1046,7 +1046,7 @@ func ParseTavor(src io.Reader) (token.Token, error) { if _, ok := p.lookup["START"]; !ok { return nil, &token.ParserError{ - Message: "No START token defined", + Message: "no START token defined", Type: token.ParseErrorNoStart, Position: p.scan.Pos(), // TODO correct position } @@ -1058,7 +1058,7 @@ func ParseTavor(src io.Reader) (token.Token, error) { for _, use := range uses { if use.token.(*primitives.Pointer).Get() == nil { return nil, &token.ParserError{ - Message: fmt.Sprintf("Token %q is not defined", name), + Message: fmt.Sprintf("token %q is not defined", name), Type: token.ParseErrorTokenNotDefined, Position: use.position, } @@ -1069,7 +1069,7 @@ func ParseTavor(src io.Reader) (token.Token, error) { for name, use := range p.lookup { if _, ok := p.used[name]; !ok { return nil, &token.ParserError{ - Message: fmt.Sprintf("Token %q declared but not used", name), + Message: fmt.Sprintf("token %q declared but not used", name), Type: token.ParseErrorUnusedToken, Position: use.position, } @@ -1080,7 +1080,7 @@ func ParseTavor(src io.Reader) (token.Token, error) { start = tavor.UnrollPointers(start) - log.Debug("Finished parsing") + log.Debug("finished parsing") return start, nil } diff --git a/reduce/strategy/binarysearch.go b/reduce/strategy/binarysearch.go index 57c5878..088943e 100644 --- a/reduce/strategy/binarysearch.go +++ b/reduce/strategy/binarysearch.go @@ -101,7 +101,7 @@ func (s *BinarySearchStrategy) resetResetTokens() { switch tok := v.(type) { case token.ResetToken: - log.Debugf("Reset %#v(%p)", tok, tok) + log.Debugf("reset %#v(%p)", tok, tok) tok.Reset() } @@ -121,7 +121,7 @@ func (s *BinarySearchStrategy) resetResetTokens() { } func (s *BinarySearchStrategy) setReduction(tok token.ReduceToken, reduction int) { - log.Debugf("Set (%p)%#v to reduction %d", tok, tok, reduction) + log.Debugf("set (%p)%#v to reduction %d", tok, tok, reduction) if err := tok.Reduce(reduction); err != nil { panic(err) @@ -131,7 +131,7 @@ func (s *BinarySearchStrategy) setReduction(tok token.ReduceToken, reduction int func (s *BinarySearchStrategy) Reduce() (chan struct{}, chan<- ReduceFeedbackType, error) { if tavor.LoopExists(s.root) { return nil, nil, &StrategyError{ - Message: "Found endless loop in graph. Cannot proceed.", + Message: "found endless loop in graph. Cannot proceed.", Type: StrategyErrorEndlessLoopDetected, } } @@ -140,21 +140,21 @@ func (s *BinarySearchStrategy) Reduce() (chan struct{}, chan<- ReduceFeedbackTyp feedbackReducing := make(chan ReduceFeedbackType) go func() { - log.Debug("Start binary search routine") + log.Debug("start binary search routine") tree := s.getTree(s.root, false) if len(tree) != 0 { - log.Debug("Start reducing step") + log.Debug("start reducing step") if contin := s.reduce(continueReducing, feedbackReducing, tree); !contin { return } } else { - log.Debug("No reduceable tokens to begin with") + log.Debug("no reduceable tokens to begin with") } - log.Debug("Finished reducing") + log.Debug("finished reducing") close(continueReducing) close(feedbackReducing) @@ -164,13 +164,15 @@ func (s *BinarySearchStrategy) Reduce() (chan struct{}, chan<- ReduceFeedbackTyp } func (s *BinarySearchStrategy) reduce(continueReducing chan struct{}, feedbackReducing <-chan ReduceFeedbackType, tree []binarySearchLevel) bool { - log.Debugf("Reducing level %d->%#v", len(tree), tree) + log.Debugf("reducing level %d->%#v", len(tree), tree) // we always asume that the initial values are bad so we ignore them right away // TODO do a binary search on the level entries for _, c := range tree { + // reduce beginning from the first reduction c.reduction = 0 + for { // TODO do a binary search on the 1..maxReductions for this level entry c.reduction++ @@ -184,7 +186,7 @@ func (s *BinarySearchStrategy) reduce(continueReducing chan struct{}, feedbackRe } if c.reduction == c.maxReductions-1 { - log.Debug("Use initial value, nothing to reduce") + log.Debug("use initial value, nothing to reduce") c.reduction = c.maxReductions c.token.Reduce(c.reduction) @@ -193,12 +195,12 @@ func (s *BinarySearchStrategy) reduce(continueReducing chan struct{}, feedbackRe } } - log.Debugf("Reduced (%p)%#v to reduction %d/%d", c.token, c.token, c.reduction, c.maxReductions) + log.Debugf("reduced (%p)%#v to reduction %d/%d", c.token, c.token, c.reduction, c.maxReductions) c.children = s.getTree(c.token, true) if len(c.children) != 0 { - log.Debugf("Reduce the children of (%p)%#v", c.token, c.token, c.reduction, c.maxReductions) + log.Debugf("reduce the children of (%p)%#v", c.token, c.token, c.reduction, c.maxReductions) s.reduce(continueReducing, feedbackReducing, c.children) } @@ -210,7 +212,7 @@ func (s *BinarySearchStrategy) reduce(continueReducing chan struct{}, feedbackRe func (s *BinarySearchStrategy) nextStep(continueReducing chan struct{}, feedbackReducing <-chan ReduceFeedbackType) (bool, ReduceFeedbackType) { s.resetResetTokens() - log.Debug("Done with reducing step") + log.Debug("done with reducing step") // done with this reduce step continueReducing <- struct{}{} @@ -221,19 +223,19 @@ func (s *BinarySearchStrategy) nextStep(continueReducing chan struct{}, feedback // TODO implement the usage of the feedback log.Debugf("GOT FEEDBACK -> Looks %s", feedback) } else { - log.Debug("Reducing feedback channel closed from outside") + log.Debug("reducing feedback channel closed from outside") return false, Unknown } // wait until we are allowed to continue if _, ok := <-continueReducing; !ok { - log.Debug("Reducing continue channel closed from outside") + log.Debug("reducing continue channel closed from outside") return false, Unknown } - log.Debug("Start reducing step") + log.Debug("start reducing step") return true, feedback } diff --git a/reduce/strategy/strategy.go b/reduce/strategy/strategy.go index cdf4431..a499176 100644 --- a/reduce/strategy/strategy.go +++ b/reduce/strategy/strategy.go @@ -33,11 +33,11 @@ const ( func (f ReduceFeedbackType) String() string { switch f { case Bad: - return "Bad" + return "bad" case Good: - return "Good" + return "good" default: - return "Unknown feedback" + return "unknown feedback" } } diff --git a/tavor.go b/tavor.go index b3b93c8..a2dac72 100644 --- a/tavor.go +++ b/tavor.go @@ -79,7 +79,7 @@ func LoopExists(root token.Token) bool { case *primitives.Pointer: if v := tok.InternalGet(); v != nil { if _, ok := lookup[v]; ok { - log.Debugf("Found a loop through (%p)%#v", t, t) + log.Debugf("found a loop through (%p)%#v", t, t) return true } @@ -108,7 +108,7 @@ func UnrollPointers(root token.Token) token.Token { parent *unrollToken } - log.Debug("Start unrolling pointers by cloning them") + log.Debug("start unrolling pointers by cloning them") checked := make(map[token.Token]token.Token) counters := make(map[token.Token]int) @@ -143,7 +143,7 @@ func UnrollPointers(root token.Token) token.Token { } if times != MaxRepeat { - log.Debugf("Clone (%p)%#v with parent (%p)%#v", t, t, parent, parent) + log.Debugf("clone (%p)%#v with parent (%p)%#v", t, t, parent, parent) c := parent.Clone() @@ -153,7 +153,7 @@ func UnrollPointers(root token.Token) token.Token { checked[c] = parent if iTok.parent != nil { - log.Debugf("Replace in (%p)%#v", iTok.parent.tok, iTok.parent.tok) + log.Debugf("replace in (%p)%#v", iTok.parent.tok, iTok.parent.tok) changed[iTok.parent.tok] = struct{}{} @@ -164,7 +164,7 @@ func UnrollPointers(root token.Token) token.Token { tt.InternalReplace(t, c) } } else { - log.Debugf("Replace as root") + log.Debugf("replace as root") root = c } @@ -174,7 +174,7 @@ func UnrollPointers(root token.Token) token.Token { parent: iTok.parent, }) } else { - log.Debugf("Reached max repeat of %d for (%p)%#v with parent (%p)%#v", MaxRepeat, t, t, parent, parent) + log.Debugf("reached max repeat of %d for (%p)%#v with parent (%p)%#v", MaxRepeat, t, t, parent, parent) t.Set(nil) @@ -188,7 +188,7 @@ func UnrollPointers(root token.Token) token.Token { switch l := tt.tok.(type) { case token.ForwardToken: - log.Debugf("Remove (%p)%#v from (%p)%#v", ta, ta, l, l) + log.Debugf("remove (%p)%#v from (%p)%#v", ta, ta, l, l) c := l.InternalLogicalRemove(ta) @@ -199,7 +199,7 @@ func UnrollPointers(root token.Token) token.Token { ta = l tt = tt.parent case lists.List: - log.Debugf("Remove (%p)%#v from (%p)%#v", ta, ta, l, l) + log.Debugf("remove (%p)%#v from (%p)%#v", ta, ta, l, l) c := l.InternalLogicalRemove(ta) @@ -243,7 +243,7 @@ func UnrollPointers(root token.Token) token.Token { continue } - log.Debugf("Update (%p)%#v with child (%p)%#v", parent, parent, child, child) + log.Debugf("update (%p)%#v with child (%p)%#v", parent, parent, child, child) switch tt := parent.(type) { case token.ForwardToken: @@ -253,7 +253,7 @@ func UnrollPointers(root token.Token) token.Token { } } - log.Debug("Finished unrolling") + log.Debug("finished unrolling") return root } diff --git a/token/primitives/int.go b/token/primitives/int.go index 340b193..d19426f 100644 --- a/token/primitives/int.go +++ b/token/primitives/int.go @@ -40,14 +40,14 @@ func (p *ConstantInt) Parse(pars *token.InternalParser, cur int) (int, []error) if nextIndex > pars.DataLen { return cur, []error{&token.ParserError{ - Message: fmt.Sprintf("Expected %q but got early EOF", v), + Message: fmt.Sprintf("expected %q but got early EOF", v), Type: token.ParseErrorUnexpectedEOF, }} } if got := pars.Data[cur:nextIndex]; v != got { return cur, []error{&token.ParserError{ - Message: fmt.Sprintf("Expected %q but got %q", v, got), + Message: fmt.Sprintf("expected %q but got %q", v, got), Type: token.ParseErrorUnexpectedData, }} } @@ -212,7 +212,7 @@ func (p *RangeInt) FuzzAll(r rand.Rand) { func (p *RangeInt) Parse(pars *token.InternalParser, cur int) (int, []error) { if cur == pars.DataLen { return cur, []error{&token.ParserError{ - Message: fmt.Sprintf("Expected integer in range %d-%d with step %d but got early EOF", p.from, p.to, p.step), + Message: fmt.Sprintf("expected integer in range %d-%d with step %d but got early EOF", p.from, p.to, p.step), Type: token.ParseErrorUnexpectedEOF, }} } @@ -253,7 +253,7 @@ func (p *RangeInt) Parse(pars *token.InternalParser, cur int) (int, []error) { } return cur, []error{&token.ParserError{ - Message: fmt.Sprintf("Expected integer in range %d-%d with step %d but got %q", p.from, p.to, p.step, pars.Data[cur:i]), + Message: fmt.Sprintf("expected integer in range %d-%d with step %d but got %q", p.from, p.to, p.step, pars.Data[cur:i]), Type: token.ParseErrorUnexpectedData, }} } diff --git a/token/primitives/string.go b/token/primitives/string.go index 0823dfa..ed1fa44 100644 --- a/token/primitives/string.go +++ b/token/primitives/string.go @@ -38,14 +38,14 @@ func (p *ConstantString) Parse(pars *token.InternalParser, cur int) (int, []erro if nextIndex > pars.DataLen { return cur, []error{&token.ParserError{ - Message: fmt.Sprintf("Expected %q but got early EOF", p.value), + Message: fmt.Sprintf("expected %q but got early EOF", p.value), Type: token.ParseErrorUnexpectedEOF, }} } if got := pars.Data[cur:nextIndex]; p.value != got { return cur, []error{&token.ParserError{ - Message: fmt.Sprintf("Expected %q but got %q", p.value, got), + Message: fmt.Sprintf("expected %q but got %q", p.value, got), Type: token.ParseErrorUnexpectedData, }} } diff --git a/token/token.go b/token/token.go index 18e283c..9463b2b 100644 --- a/token/token.go +++ b/token/token.go @@ -53,9 +53,9 @@ type PermutationError struct { func (err *PermutationError) Error() string { switch err.Type { case PermutationErrorIndexOutOfBound: - return "Permutation index out of bound" + return "permutation index out of bound" default: - return fmt.Sprintf("Unknown permutation error type %#v", err.Type) + return fmt.Sprintf("unknown permutation error type %#v", err.Type) } } @@ -78,9 +78,9 @@ type ReduceError struct { func (err *ReduceError) Error() string { switch err.Type { case ReduceErrorIndexOutOfBound: - return "Reduce index out of bound" + return "reduce index out of bound" default: - return fmt.Sprintf("Unknown reduce error type %#v", err.Type) + return fmt.Sprintf("unknown reduce error type %#v", err.Type) } }