From 0cd9750aa5e1e6919d7bfe16dd4680f13c35ada1 Mon Sep 17 00:00:00 2001 From: Denis Cheremisov Date: Fri, 16 Sep 2022 11:07:18 +0300 Subject: [PATCH] feat: add rule name into constants Add rule name into constants to prevent package-wide constants names clashes. --- internal/generator/gogen/util.go | 19 +- internal/ldetesting/parsing_lde.go | 346 +++++++++++++------------ internal/ldetesting/regressions_lde.go | 48 ++-- internal/ldetesting/string_lde.go | 73 +++--- 4 files changed, 252 insertions(+), 234 deletions(-) diff --git a/internal/generator/gogen/util.go b/internal/generator/gogen/util.go index d19b90e..8f79bfc 100644 --- a/internal/generator/gogen/util.go +++ b/internal/generator/gogen/util.go @@ -19,11 +19,11 @@ func (g *Generator) constNameFromContent(value string) string { res := w.String() if ok, err := regexp.MatchString(`^\d.*$`, res); ok { - res = "const_" + res + res = "const_" + g.ruleName + res } else if err != nil { panic(err) } - res = g.goish.Private("const_" + g.goish.Private(res)) + res = g.goish.Private("const_" + g.ruleName + "_" + g.goish.Private(res)) newRes := res i := 2 for { @@ -63,7 +63,8 @@ func (g *Generator) regVar(name, varType string) error { if oldType != varType { return fmt.Errorf( "local variable \033[1m%s\033[0m has been registered already with type \033[1m%s\033[0m", - name, varType, + name, + varType, ) } } @@ -85,7 +86,9 @@ func (g *Generator) RegImport(importAs, path string) error { return fmt.Errorf( `Attempt to register import of "\033[1m%s\033[0m" as '\033[1m%s\033' while it has already been `+ `imported as '\033[1m%s\033[0m'`, - path, importAs, importedAs, + path, + importAs, + importedAs, ) } } @@ -140,8 +143,12 @@ func (g *Generator) addField(name string, t antlr.Token) string { if ppp, ok := g.fields[g.fullName(name)]; ok { panic(fmt.Sprintf( "%d:%d: Field `\033[1m%s\033[0m` redefinition, previously declared at (%d, %d)", - t.GetLine(), t.GetColumn()+1, - name, ppp.token.GetLine(), ppp.token.GetColumn()+1)) + t.GetLine(), + t.GetColumn()+1, + name, + ppp.token.GetLine(), + ppp.token.GetColumn()+1, + )) } g.fields[g.fullName(name)] = Name{ name: namespaced, diff --git a/internal/ldetesting/parsing_lde.go b/internal/ldetesting/parsing_lde.go index 5e4644e..f523178 100644 --- a/internal/ldetesting/parsing_lde.go +++ b/internal/ldetesting/parsing_lde.go @@ -10,16 +10,26 @@ import ( "unsafe" ) -var constAb = []byte("ab") -var constAbcd = []byte("abcd") -var constBa = []byte("ba") -var constBar = []byte("|") -var constConst123456789 = []byte("123456789") -var constConst34 = []byte("34") -var constDogs = []byte("@@") -var constEe = []byte("ee") -var constLl = []byte("ll") -var constSpace = []byte(" ") +var constAnonymousAreasSpace = []byte(" ") +var constDecodersBoundedStringSpace = []byte(" ") +var constDecodersBoundedStringStressSpace = []byte(" ") +var constDecodersLimitedStringSpace = []byte(" ") +var constDecodersLimitedStringStressSpace = []byte(" ") +var constDecodersStringSpace = []byte(" ") +var constDecodersStringStressSpace = []byte(" ") +var constFixedLookConstFixedLook123456789 = []byte("123456789") +var constFixedLookConstFixedLook34 = []byte("34") +var constIncludeStringAb = []byte("ab") +var constJumpDogs = []byte("@@") +var constJustToCompileStringAbcd = []byte("abcd") +var constLookupJumpDogs = []byte("@@") +var constLookupJumpEe = []byte("ee") +var constLookupJumpLl = []byte("ll") +var constPrefixesConstPrefixes123456789 = []byte("123456789") +var constShift1Ba = []byte("ba") +var constShift3Ba = []byte("ba") +var constSplitStringBar = []byte("|") +var constStarBar = []byte("|") // Decoders ... type Decoders struct { @@ -476,10 +486,10 @@ func (p *DecodersString) Extract(line []byte) (bool, error) { var tmpUint uint64 // Take until " " as Int8(int8) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringSpace):] } else { return false, nil } @@ -489,10 +499,10 @@ func (p *DecodersString) Extract(line []byte) (bool, error) { p.Int8 = int8(tmpInt) // Take until " " as Int16(int16) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringSpace):] } else { return false, nil } @@ -502,10 +512,10 @@ func (p *DecodersString) Extract(line []byte) (bool, error) { p.Int16 = int16(tmpInt) // Take until " " as Int32(int32) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringSpace):] } else { return false, nil } @@ -515,10 +525,10 @@ func (p *DecodersString) Extract(line []byte) (bool, error) { p.Int32 = int32(tmpInt) // Take until " " as Int64(int64) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringSpace):] } else { return false, nil } @@ -528,10 +538,10 @@ func (p *DecodersString) Extract(line []byte) (bool, error) { p.Int64 = int64(tmpInt) // Take until " " as Uint8(uint8) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringSpace):] } else { return false, nil } @@ -541,10 +551,10 @@ func (p *DecodersString) Extract(line []byte) (bool, error) { p.Uint8 = uint8(tmpUint) // Take until " " as Uint16(uint16) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringSpace):] } else { return false, nil } @@ -554,10 +564,10 @@ func (p *DecodersString) Extract(line []byte) (bool, error) { p.Uint16 = uint16(tmpUint) // Take until " " as Uint32(uint32) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringSpace):] } else { return false, nil } @@ -567,10 +577,10 @@ func (p *DecodersString) Extract(line []byte) (bool, error) { p.Uint32 = uint32(tmpUint) // Take until " " as Uint64(uint64) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringSpace):] } else { return false, nil } @@ -580,10 +590,10 @@ func (p *DecodersString) Extract(line []byte) (bool, error) { p.Uint64 = uint64(tmpUint) // Take until " " as Float32(float32) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringSpace):] } else { return false, nil } @@ -593,10 +603,10 @@ func (p *DecodersString) Extract(line []byte) (bool, error) { p.Float32 = float32(tmpFloat) // Take until " " as Float64(float64) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringSpace):] } else { return false, nil } @@ -606,10 +616,10 @@ func (p *DecodersString) Extract(line []byte) (bool, error) { p.Float64 = float64(tmpFloat) // Take until " " as String(string) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringSpace) if pos >= 0 { p.String = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringSpace):] } else { return false, nil } @@ -650,10 +660,10 @@ func (p *DecodersLimitedString) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringSpace):] } else { return false, nil } @@ -668,10 +678,10 @@ func (p *DecodersLimitedString) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringSpace):] } else { return false, nil } @@ -686,10 +696,10 @@ func (p *DecodersLimitedString) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringSpace):] } else { return false, nil } @@ -704,10 +714,10 @@ func (p *DecodersLimitedString) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringSpace):] } else { return false, nil } @@ -722,10 +732,10 @@ func (p *DecodersLimitedString) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringSpace):] } else { return false, nil } @@ -740,10 +750,10 @@ func (p *DecodersLimitedString) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringSpace):] } else { return false, nil } @@ -758,10 +768,10 @@ func (p *DecodersLimitedString) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringSpace):] } else { return false, nil } @@ -776,10 +786,10 @@ func (p *DecodersLimitedString) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringSpace):] } else { return false, nil } @@ -794,10 +804,10 @@ func (p *DecodersLimitedString) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringSpace):] } else { return false, nil } @@ -812,10 +822,10 @@ func (p *DecodersLimitedString) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringSpace):] } else { return false, nil } @@ -830,10 +840,10 @@ func (p *DecodersLimitedString) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringSpace) if pos >= 0 { p.String = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringSpace):] } else { return false, nil } @@ -862,10 +872,10 @@ func (p *DecodersBoundedString) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest[8:] } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersBoundedStringSpace) if pos >= 0 { tmp = p.Rest[:pos+8] - p.Rest = p.Rest[pos+len(constSpace)+8:] + p.Rest = p.Rest[pos+len(constDecodersBoundedStringSpace)+8:] } else { return false, nil } @@ -1332,12 +1342,12 @@ func (p *DecodersStringStress) Extract(line []byte) (bool, error) { var tmpUint uint64 // Take until " " as Int8(int8) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int8", constSpace, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int8", constDecodersStringStressSpace, string(p.Rest)) } if tmpInt, err = strconv.ParseInt(*(*string)(unsafe.Pointer(&tmp)), 10, 8); err != nil { return false, fmt.Errorf("parsing `%s` into field Int8(int8): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1345,12 +1355,12 @@ func (p *DecodersStringStress) Extract(line []byte) (bool, error) { p.Int8 = int8(tmpInt) // Take until " " as Int16(int16) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int16", constSpace, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int16", constDecodersStringStressSpace, string(p.Rest)) } if tmpInt, err = strconv.ParseInt(*(*string)(unsafe.Pointer(&tmp)), 10, 16); err != nil { return false, fmt.Errorf("parsing `%s` into field Int16(int16): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1358,12 +1368,12 @@ func (p *DecodersStringStress) Extract(line []byte) (bool, error) { p.Int16 = int16(tmpInt) // Take until " " as Int32(int32) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int32", constSpace, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int32", constDecodersStringStressSpace, string(p.Rest)) } if tmpInt, err = strconv.ParseInt(*(*string)(unsafe.Pointer(&tmp)), 10, 32); err != nil { return false, fmt.Errorf("parsing `%s` into field Int32(int32): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1371,12 +1381,12 @@ func (p *DecodersStringStress) Extract(line []byte) (bool, error) { p.Int32 = int32(tmpInt) // Take until " " as Int64(int64) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int64", constSpace, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int64", constDecodersStringStressSpace, string(p.Rest)) } if tmpInt, err = strconv.ParseInt(*(*string)(unsafe.Pointer(&tmp)), 10, 64); err != nil { return false, fmt.Errorf("parsing `%s` into field Int64(int64): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1384,12 +1394,12 @@ func (p *DecodersStringStress) Extract(line []byte) (bool, error) { p.Int64 = int64(tmpInt) // Take until " " as Uint8(uint8) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint8", constSpace, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint8", constDecodersStringStressSpace, string(p.Rest)) } if tmpUint, err = strconv.ParseUint(*(*string)(unsafe.Pointer(&tmp)), 10, 8); err != nil { return false, fmt.Errorf("parsing `%s` into field Uint8(uint8): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1397,12 +1407,12 @@ func (p *DecodersStringStress) Extract(line []byte) (bool, error) { p.Uint8 = uint8(tmpUint) // Take until " " as Uint16(uint16) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint16", constSpace, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint16", constDecodersStringStressSpace, string(p.Rest)) } if tmpUint, err = strconv.ParseUint(*(*string)(unsafe.Pointer(&tmp)), 10, 16); err != nil { return false, fmt.Errorf("parsing `%s` into field Uint16(uint16): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1410,12 +1420,12 @@ func (p *DecodersStringStress) Extract(line []byte) (bool, error) { p.Uint16 = uint16(tmpUint) // Take until " " as Uint32(uint32) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint32", constSpace, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint32", constDecodersStringStressSpace, string(p.Rest)) } if tmpUint, err = strconv.ParseUint(*(*string)(unsafe.Pointer(&tmp)), 10, 32); err != nil { return false, fmt.Errorf("parsing `%s` into field Uint32(uint32): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1423,12 +1433,12 @@ func (p *DecodersStringStress) Extract(line []byte) (bool, error) { p.Uint32 = uint32(tmpUint) // Take until " " as Uint64(uint64) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint64", constSpace, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint64", constDecodersStringStressSpace, string(p.Rest)) } if tmpUint, err = strconv.ParseUint(*(*string)(unsafe.Pointer(&tmp)), 10, 64); err != nil { return false, fmt.Errorf("parsing `%s` into field Uint64(uint64): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1436,12 +1446,12 @@ func (p *DecodersStringStress) Extract(line []byte) (bool, error) { p.Uint64 = uint64(tmpUint) // Take until " " as Float32(float32) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Float32", constSpace, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Float32", constDecodersStringStressSpace, string(p.Rest)) } if tmpFloat, err = strconv.ParseFloat(*(*string)(unsafe.Pointer(&tmp)), 32); err != nil { return false, fmt.Errorf("parsing `%s` into field Float32(float32): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1449,12 +1459,12 @@ func (p *DecodersStringStress) Extract(line []byte) (bool, error) { p.Float32 = float32(tmpFloat) // Take until " " as Float64(float64) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Float64", constSpace, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Float64", constDecodersStringStressSpace, string(p.Rest)) } if tmpFloat, err = strconv.ParseFloat(*(*string)(unsafe.Pointer(&tmp)), 64); err != nil { return false, fmt.Errorf("parsing `%s` into field Float64(float64): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1462,12 +1472,12 @@ func (p *DecodersStringStress) Extract(line []byte) (bool, error) { p.Float64 = float64(tmpFloat) // Take until " " as String(string) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constDecodersStringStressSpace) if pos >= 0 { p.String = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field String", constSpace, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field String", constDecodersStringStressSpace, string(p.Rest)) } return true, nil @@ -1506,12 +1516,12 @@ func (p *DecodersLimitedStringStress) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int8", constSpace, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int8", constDecodersLimitedStringStressSpace, string(tmpRest)) } if tmpInt, err = strconv.ParseInt(*(*string)(unsafe.Pointer(&tmp)), 10, 8); err != nil { return false, fmt.Errorf("parsing `%s` into field Int8(int8): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1524,12 +1534,12 @@ func (p *DecodersLimitedStringStress) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int16", constSpace, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int16", constDecodersLimitedStringStressSpace, string(tmpRest)) } if tmpInt, err = strconv.ParseInt(*(*string)(unsafe.Pointer(&tmp)), 10, 16); err != nil { return false, fmt.Errorf("parsing `%s` into field Int16(int16): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1542,12 +1552,12 @@ func (p *DecodersLimitedStringStress) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int32", constSpace, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int32", constDecodersLimitedStringStressSpace, string(tmpRest)) } if tmpInt, err = strconv.ParseInt(*(*string)(unsafe.Pointer(&tmp)), 10, 32); err != nil { return false, fmt.Errorf("parsing `%s` into field Int32(int32): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1560,12 +1570,12 @@ func (p *DecodersLimitedStringStress) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int64", constSpace, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Int64", constDecodersLimitedStringStressSpace, string(tmpRest)) } if tmpInt, err = strconv.ParseInt(*(*string)(unsafe.Pointer(&tmp)), 10, 64); err != nil { return false, fmt.Errorf("parsing `%s` into field Int64(int64): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1578,12 +1588,12 @@ func (p *DecodersLimitedStringStress) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint8", constSpace, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint8", constDecodersLimitedStringStressSpace, string(tmpRest)) } if tmpUint, err = strconv.ParseUint(*(*string)(unsafe.Pointer(&tmp)), 10, 8); err != nil { return false, fmt.Errorf("parsing `%s` into field Uint8(uint8): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1596,12 +1606,12 @@ func (p *DecodersLimitedStringStress) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint16", constSpace, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint16", constDecodersLimitedStringStressSpace, string(tmpRest)) } if tmpUint, err = strconv.ParseUint(*(*string)(unsafe.Pointer(&tmp)), 10, 16); err != nil { return false, fmt.Errorf("parsing `%s` into field Uint16(uint16): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1614,12 +1624,12 @@ func (p *DecodersLimitedStringStress) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint32", constSpace, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint32", constDecodersLimitedStringStressSpace, string(tmpRest)) } if tmpUint, err = strconv.ParseUint(*(*string)(unsafe.Pointer(&tmp)), 10, 32); err != nil { return false, fmt.Errorf("parsing `%s` into field Uint32(uint32): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1632,12 +1642,12 @@ func (p *DecodersLimitedStringStress) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint64", constSpace, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Uint64", constDecodersLimitedStringStressSpace, string(tmpRest)) } if tmpUint, err = strconv.ParseUint(*(*string)(unsafe.Pointer(&tmp)), 10, 64); err != nil { return false, fmt.Errorf("parsing `%s` into field Uint64(uint64): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1650,12 +1660,12 @@ func (p *DecodersLimitedStringStress) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Float32", constSpace, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Float32", constDecodersLimitedStringStressSpace, string(tmpRest)) } if tmpFloat, err = strconv.ParseFloat(*(*string)(unsafe.Pointer(&tmp)), 32); err != nil { return false, fmt.Errorf("parsing `%s` into field Float32(float32): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1668,12 +1678,12 @@ func (p *DecodersLimitedStringStress) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Float64", constSpace, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Float64", constDecodersLimitedStringStressSpace, string(tmpRest)) } if tmpFloat, err = strconv.ParseFloat(*(*string)(unsafe.Pointer(&tmp)), 64); err != nil { return false, fmt.Errorf("parsing `%s` into field Float64(float64): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -1686,12 +1696,12 @@ func (p *DecodersLimitedStringStress) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersLimitedStringStressSpace) if pos >= 0 { p.String = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constDecodersLimitedStringStressSpace):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field String", constSpace, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field String", constDecodersLimitedStringStressSpace, string(tmpRest)) } return true, nil @@ -1718,12 +1728,12 @@ func (p *DecodersBoundedStringStress) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest[8:] } - pos = bytes.Index(tmpRest, constSpace) + pos = bytes.Index(tmpRest, constDecodersBoundedStringStressSpace) if pos >= 0 { tmp = p.Rest[:pos+8] - p.Rest = p.Rest[pos+len(constSpace)+8:] + p.Rest = p.Rest[pos+len(constDecodersBoundedStringStressSpace)+8:] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Float64", constSpace, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Float64", constDecodersBoundedStringStressSpace, string(tmpRest)) } if tmpFloat, err = strconv.ParseFloat(*(*string)(unsafe.Pointer(&tmp)), 64); err != nil { return false, fmt.Errorf("parsing `%s` into field Float64(float64): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) @@ -2080,8 +2090,8 @@ func (p *Prefixes) Extract(line []byte) (bool, error) { var tmpInt int64 // Checks if the rest starts with `"123456789"` and pass it - if bytes.HasPrefix(p.Rest, constConst123456789) { - p.Rest = p.Rest[len(constConst123456789):] + if bytes.HasPrefix(p.Rest, constPrefixesConstPrefixes123456789) { + p.Rest = p.Rest[len(constPrefixesConstPrefixes123456789):] } else { return false, fmt.Errorf("`\033[1m%s\033[0m` is expected to start with `\033[1m%s\033[0m`", string(p.Rest), "123456789") } @@ -2137,11 +2147,11 @@ func (p *FixedLook) Extract(line []byte) (bool, error) { var tmpInt int64 // Take until 3rd character if that part is started by "123456789" substring as Data(int32) - if len(p.Rest) < len(constConst123456789)+2 || !bytes.HasPrefix(p.Rest[2:], constConst123456789) { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Data", constConst123456789, string(p.Rest)) + if len(p.Rest) < len(constFixedLookConstFixedLook123456789)+2 || !bytes.HasPrefix(p.Rest[2:], constFixedLookConstFixedLook123456789) { + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Data", constFixedLookConstFixedLook123456789, string(p.Rest)) } tmp = p.Rest[:2] - p.Rest = p.Rest[2+len(constConst123456789):] + p.Rest = p.Rest[2+len(constFixedLookConstFixedLook123456789):] if tmpInt, err = strconv.ParseInt(*(*string)(unsafe.Pointer(&tmp)), 10, 32); err != nil { return false, fmt.Errorf("parsing `%s` into field Data(int32): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) } @@ -2149,10 +2159,10 @@ func (p *FixedLook) Extract(line []byte) (bool, error) { // Take until 4th character if that part is started by "34" substring as Rest1(int32) if len(p.Rest)-3 < 2 || *(*uint64)(unsafe.Pointer(&p.Rest[3]))&0xffff != 0x3433 { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Rest1", constConst34, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Rest1", constFixedLookConstFixedLook34, string(p.Rest)) } tmp = p.Rest[:3] - p.Rest = p.Rest[3+len(constConst34):] + p.Rest = p.Rest[3+len(constFixedLookConstFixedLook34):] if tmpInt, err = strconv.ParseInt(*(*string)(unsafe.Pointer(&tmp)), 10, 32); err != nil { return false, fmt.Errorf("parsing `%s` into field Rest1(int32): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) } @@ -2208,10 +2218,10 @@ anonymousareasAnonymousAreaLabel: anonymousareasAnonymousAreaLabel2: // Take until " " (or all the rest if not found) as Data(string) - pos = bytes.Index(p.Rest, constSpace) + pos = bytes.Index(p.Rest, constAnonymousAreasSpace) if pos >= 0 { p.Data = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpace):] + p.Rest = p.Rest[pos+len(constAnonymousAreasSpace):] } else { p.Data = p.Rest p.Rest = p.Rest[len(p.Rest):] @@ -2291,12 +2301,12 @@ func (p *SplitString) Extract(line []byte) (bool, error) { var pos int // Take until "|" as Name(string) - pos = bytes.Index(p.Rest, constBar) + pos = bytes.Index(p.Rest, constSplitStringBar) if pos >= 0 { p.Name = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constBar):] + p.Rest = p.Rest[pos+len(constSplitStringBar):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Name", constBar, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Name", constSplitStringBar, string(p.Rest)) } // Checks if rest[1:] starts with `"|"` and pass it @@ -2322,10 +2332,10 @@ func (p *SplitString) Extract(line []byte) (bool, error) { // Take until 2nd character if that part is started by "|" substring as Count(string) if len(p.Rest)-1 < 1 || *(*uint64)(unsafe.Pointer(&p.Rest[1]))&0xff != 0x7c { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Count", constBar, string(p.Rest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Count", constSplitStringBar, string(p.Rest)) } p.Count = p.Rest[:1] - p.Rest = p.Rest[1+len(constBar):] + p.Rest = p.Rest[1+len(constSplitStringBar):] return true, nil } @@ -2348,12 +2358,12 @@ func (p *Shift1) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest[3:] } - pos = bytes.Index(tmpRest, constBa) + pos = bytes.Index(tmpRest, constShift1Ba) if pos >= 0 { p.B = p.Rest[:pos+3] - p.Rest = p.Rest[pos+len(constBa)+3:] + p.Rest = p.Rest[pos+len(constShift1Ba)+3:] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field B", constBa, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field B", constShift1Ba, string(tmpRest)) } return true, nil @@ -2406,12 +2416,12 @@ func (p *Shift3) Extract(line []byte) (bool, error) { } else { tmpRest = p.Rest[3:] } - pos = bytes.Index(tmpRest, constBa) + pos = bytes.Index(tmpRest, constShift3Ba) if pos >= 0 { p.B = p.Rest[:pos+3] - p.Rest = p.Rest[pos+len(constBa)+3:] + p.Rest = p.Rest[pos+len(constShift3Ba)+3:] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field B", constBa, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field B", constShift3Ba, string(tmpRest)) } return true, nil @@ -2500,24 +2510,24 @@ func (p *Jump) Extract(line []byte) (bool, error) { if len(p.Rest) < 2 { return false, fmt.Errorf("cannot slice from %d as only %d characters left in the rest (`\033[1m%s\033[0m`)", 2, len(p.Rest), string(p.Rest)) } - pos = bytes.Index(p.Rest[2:], constDogs) + pos = bytes.Index(p.Rest[2:], constJumpDogs) if pos >= 0 { p.Third = p.Rest[:pos+2] - p.Rest = p.Rest[pos+len(constDogs)+2:] + p.Rest = p.Rest[pos+len(constJumpDogs)+2:] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Third", constDogs, string(p.Rest[2:])) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Third", constJumpDogs, string(p.Rest[2:])) } // Take until "@@" as Fourth(string) if len(p.Rest) < 2 { return false, fmt.Errorf("cannot slice from %d as only %d characters left in the rest (`\033[1m%s\033[0m`)", 2, len(p.Rest), string(p.Rest)) } - pos = bytes.Index(p.Rest[2:], constDogs) + pos = bytes.Index(p.Rest[2:], constJumpDogs) if pos >= 0 { p.Fourth = p.Rest[:pos+2] - p.Rest = p.Rest[pos+len(constDogs)+2:] + p.Rest = p.Rest[pos+len(constJumpDogs)+2:] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Fourth", constDogs, string(p.Rest[2:])) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m` to bound data for field Fourth", constJumpDogs, string(p.Rest[2:])) } return true, nil @@ -2549,11 +2559,11 @@ func (p *LookupJump) Extract(line []byte) (bool, error) { return false, fmt.Errorf("cannot slice from %d as only %d characters left in the rest (`\033[1m%s\033[0m`)", 2, len(p.Rest), string(p.Rest)) } // Looking for "@@" and then pass it - pos = bytes.Index(p.Rest[2:], constDogs) + pos = bytes.Index(p.Rest[2:], constLookupJumpDogs) if pos >= 0 { - p.Rest = p.Rest[pos+len(constDogs)+2:] + p.Rest = p.Rest[pos+len(constLookupJumpDogs)+2:] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m`", constDogs, string(p.Rest[2:])) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m`", constLookupJumpDogs, string(p.Rest[2:])) } if len(p.Rest) >= 12 { @@ -2562,11 +2572,11 @@ func (p *LookupJump) Extract(line []byte) (bool, error) { tmpRest = p.Rest } // Looking for "ll" and then pass it - pos = bytes.Index(tmpRest, constLl) + pos = bytes.Index(tmpRest, constLookupJumpLl) if pos >= 0 { - p.Rest = p.Rest[pos+len(constLl):] + p.Rest = p.Rest[pos+len(constLookupJumpLl):] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m`", constLl, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m`", constLookupJumpLl, string(tmpRest)) } if len(p.Rest) >= 12 { @@ -2575,11 +2585,11 @@ func (p *LookupJump) Extract(line []byte) (bool, error) { tmpRest = p.Rest[2:] } // Looking for "ee" and then pass it - pos = bytes.Index(tmpRest, constEe) + pos = bytes.Index(tmpRest, constLookupJumpEe) if pos >= 0 { - p.Rest = p.Rest[pos+len(constEe)+2:] + p.Rest = p.Rest[pos+len(constLookupJumpEe)+2:] } else { - return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m`", constEe, string(tmpRest)) + return false, fmt.Errorf("cannot find `\033[1m%s\033[0m` in `\033[1m%s\033[0m`", constLookupJumpEe, string(tmpRest)) } // Looking for 'e' and then pass it @@ -2837,19 +2847,19 @@ func (p *IncludeString) Extract(line []byte) (bool, error) { var tmpInt int64 // Take until "ab" including it as Data(string) - pos = bytes.Index(p.Rest, constAb) + pos = bytes.Index(p.Rest, constIncludeStringAb) if pos >= 0 { - p.Data = p.Rest[:pos+len(constAb)] - p.Rest = p.Rest[pos+len(constAb):] + p.Data = p.Rest[:pos+len(constIncludeStringAb)] + p.Rest = p.Rest[pos+len(constIncludeStringAb):] } else { return false, nil } // Take until "ab" as Field2(int) - pos = bytes.Index(p.Rest, constAb) + pos = bytes.Index(p.Rest, constIncludeStringAb) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constAb):] + p.Rest = p.Rest[pos+len(constIncludeStringAb):] } else { return false, nil } @@ -3153,10 +3163,10 @@ func (p *Star) Extract(line []byte) (bool, error) { } // Take until "|" as F(int) - pos = bytes.Index(p.Rest, constBar) + pos = bytes.Index(p.Rest, constStarBar) if pos >= 0 { tmp = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constBar):] + p.Rest = p.Rest[pos+len(constStarBar):] } else { return false, nil } @@ -3238,7 +3248,7 @@ func (p *JustToCompileString) Extract(line []byte) (bool, error) { return false, nil } tmp = p.Rest[:4] - p.Rest = p.Rest[4+len(constAbcd):] + p.Rest = p.Rest[4+len(constJustToCompileStringAbcd):] if tmpUint, err = strconv.ParseUint(*(*string)(unsafe.Pointer(&tmp)), 16, 16); err != nil { return false, fmt.Errorf("parsing `%s` into field Head(hex16): %s", string(*(*string)(unsafe.Pointer(&tmp))), err) } diff --git a/internal/ldetesting/regressions_lde.go b/internal/ldetesting/regressions_lde.go index 06fe378..acd3824 100644 --- a/internal/ldetesting/regressions_lde.go +++ b/internal/ldetesting/regressions_lde.go @@ -8,14 +8,14 @@ import ( "strings" ) -var constLessBar = ""` and pass it - if strings.HasPrefix(p.Rest, constLessFooMore) { - p.Rest = p.Rest[len(constLessFooMore):] + if strings.HasPrefix(p.Rest, constFooBarBazLessFooMore) { + p.Rest = p.Rest[len(constFooBarBazLessFooMore):] } else { return false, nil } // Take until "" as Stuff(string) - pos = strings.Index(p.Rest, constLessSlashFooMore) + pos = strings.Index(p.Rest, constFooBarBazLessSlashFooMore) if pos >= 0 { p.Stuff = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constLessSlashFooMore):] + p.Rest = p.Rest[pos+len(constFooBarBazLessSlashFooMore):] } else { return false, nil } barRest = p.Rest // Checks if the rest starts with `"= 0 { p.Bar.ID.Foobarbaz = barIDRest[:pos] - barIDRest = barIDRest[pos+len(constRbrace):] + barIDRest = barIDRest[pos+len(constFooBarBazRbrace):] } else { p.Bar.ID.Valid = false goto foobarbazBarIDLabel @@ -152,8 +152,8 @@ func (p *FooBarBaz) Extract(line string) (bool, error) { foobarbazBarIDLabel: // Checks if the rest starts with `"/>"` and pass it - if strings.HasPrefix(barRest, constSlashMore) { - barRest = barRest[len(constSlashMore):] + if strings.HasPrefix(barRest, constFooBarBazSlashMore) { + barRest = barRest[len(constFooBarBazSlashMore):] } else { p.Bar.Valid = false goto foobarbazBarLabel @@ -164,17 +164,17 @@ foobarbazBarIDLabel: foobarbazBarLabel: // Checks if the rest starts with `""` and pass it - if strings.HasPrefix(p.Rest, constLessBazMore) { - p.Rest = p.Rest[len(constLessBazMore):] + if strings.HasPrefix(p.Rest, constFooBarBazLessBazMore) { + p.Rest = p.Rest[len(constFooBarBazLessBazMore):] } else { return false, nil } // Take until "" as Baz(string) - pos = strings.Index(p.Rest, constLessSlashBazMore) + pos = strings.Index(p.Rest, constFooBarBazLessSlashBazMore) if pos >= 0 { p.Baz = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constLessSlashBazMore):] + p.Rest = p.Rest[pos+len(constFooBarBazLessSlashBazMore):] } else { return false, nil } diff --git a/internal/ldetesting/string_lde.go b/internal/ldetesting/string_lde.go index 87b5857..864e4db 100644 --- a/internal/ldetesting/string_lde.go +++ b/internal/ldetesting/string_lde.go @@ -10,17 +10,18 @@ import ( time "time" ) -var constAbc = "abc" -var constAddrColonSpace = "addr: " -var constAmountColon = "Amount:" -var constChangeSpaceInternalSpaceStateSpace = "change internal state " -var constColonC = ":c" -var constLsbrck = "[" -var constSpacePumpSpace = " Pump " -var constSpaceToSpace = " to " -var constStarsSpaceTimeColonSpace = "*** Time: " -var constStateSpaceChangeSpace = "State change " -var constUnrecognizedSequence = "" +var constBeforeLookupAbc = "abc" +var constCheckPrefixAbc = "abc" +var constCustomAddrColonSpace = "addr: " +var constRegressionCheck1ChangeSpaceInternalSpaceStateSpace = "change internal state " +var constRegressionCheck1Lsbrck = "[" +var constRegressionCheck1SpacePumpSpace = " Pump " +var constRegressionCheck1SpaceToSpace = " to " +var constRegressionCheck1StateSpaceChangeSpace = "State change " +var constRegressionCheck2StarsSpaceTimeColonSpace = "*** Time: " +var constRegressionCheck2UnrecognizedSequence = "" +var constRegressionCheck3ColonC = ":c" +var constSilentAreasAmountColon = "Amount:" // Rule ... type Rule struct { @@ -128,10 +129,10 @@ func (p *RegressionCheck1) Extract(line string) (bool, error) { var tmpInt int64 // Take until " Pump " as Time(string) - pos = strings.Index(p.Rest, constSpacePumpSpace) + pos = strings.Index(p.Rest, constRegressionCheck1SpacePumpSpace) if pos >= 0 { p.Time = p.Rest[:pos] - p.Rest = p.Rest[pos+len(constSpacePumpSpace):] + p.Rest = p.Rest[pos+len(constRegressionCheck1SpacePumpSpace):] } else { return false, nil } @@ -157,27 +158,27 @@ func (p *RegressionCheck1) Extract(line string) (bool, error) { pStateRest = p.Rest // Checks if the rest starts with `"State change "` and pass it - if strings.HasPrefix(pStateRest, constStateSpaceChangeSpace) { - pStateRest = pStateRest[len(constStateSpaceChangeSpace):] + if strings.HasPrefix(pStateRest, constRegressionCheck1StateSpaceChangeSpace) { + pStateRest = pStateRest[len(constRegressionCheck1StateSpaceChangeSpace):] } else { p.PState.Valid = false goto regressioncheck1PStateLabel } // Looking for " to " and then pass it - pos = strings.Index(pStateRest, constSpaceToSpace) + pos = strings.Index(pStateRest, constRegressionCheck1SpaceToSpace) if pos >= 0 { - pStateRest = pStateRest[pos+len(constSpaceToSpace):] + pStateRest = pStateRest[pos+len(constRegressionCheck1SpaceToSpace):] } else { p.PState.Valid = false goto regressioncheck1PStateLabel } // Take until "[" as State(string) - pos = strings.Index(pStateRest, constLsbrck) + pos = strings.Index(pStateRest, constRegressionCheck1Lsbrck) if pos >= 0 { p.PState.State = pStateRest[:pos] - pStateRest = pStateRest[pos+len(constLsbrck):] + pStateRest = pStateRest[pos+len(constRegressionCheck1Lsbrck):] } else { p.PState.Valid = false goto regressioncheck1PStateLabel @@ -189,17 +190,17 @@ regressioncheck1PStateLabel: iStateRest = p.Rest // Checks if the rest starts with `"change internal state "` and pass it - if strings.HasPrefix(iStateRest, constChangeSpaceInternalSpaceStateSpace) { - iStateRest = iStateRest[len(constChangeSpaceInternalSpaceStateSpace):] + if strings.HasPrefix(iStateRest, constRegressionCheck1ChangeSpaceInternalSpaceStateSpace) { + iStateRest = iStateRest[len(constRegressionCheck1ChangeSpaceInternalSpaceStateSpace):] } else { p.IState.Valid = false goto regressioncheck1IStateLabel } // Looking for " to " and then pass it - pos = strings.Index(iStateRest, constSpaceToSpace) + pos = strings.Index(iStateRest, constRegressionCheck1SpaceToSpace) if pos >= 0 { - iStateRest = iStateRest[pos+len(constSpaceToSpace):] + iStateRest = iStateRest[pos+len(constRegressionCheck1SpaceToSpace):] } else { p.IState.Valid = false goto regressioncheck1IStateLabel @@ -242,15 +243,15 @@ func (p *RegressionCheck2) Extract(line string) (bool, error) { p.Rest = line // Checks if the rest starts with `""` and pass it - if strings.HasPrefix(p.Rest, constUnrecognizedSequence) { - p.Rest = p.Rest[len(constUnrecognizedSequence):] + if strings.HasPrefix(p.Rest, constRegressionCheck2UnrecognizedSequence) { + p.Rest = p.Rest[len(constRegressionCheck2UnrecognizedSequence):] } else { return false, nil } // Checks if the rest starts with `"*** Time: "` and pass it - if strings.HasPrefix(p.Rest, constStarsSpaceTimeColonSpace) { - p.Rest = p.Rest[len(constStarsSpaceTimeColonSpace):] + if strings.HasPrefix(p.Rest, constRegressionCheck2StarsSpaceTimeColonSpace) { + p.Rest = p.Rest[len(constRegressionCheck2StarsSpaceTimeColonSpace):] } else { return false, nil } @@ -276,7 +277,7 @@ func (p *RegressionCheck3) Extract(line string) (bool, error) { } // Checks if rest[2:] starts with `":c"` - if len(p.Rest) < 2+len(constColonC) || !strings.HasPrefix(p.Rest[2:], constColonC) { + if len(p.Rest) < 2+len(constRegressionCheck3ColonC) || !strings.HasPrefix(p.Rest[2:], constRegressionCheck3ColonC) { return false, nil } @@ -295,7 +296,7 @@ func (p *BeforeLookup) Extract(line string) (bool, error) { var pos int // Looking for "abc" and then pass it - pos = strings.Index(p.Rest, constAbc) + pos = strings.Index(p.Rest, constBeforeLookupAbc) if pos >= 0 { p.Rest = p.Rest[pos:] } else { @@ -319,7 +320,7 @@ func (p *CheckPrefix) Extract(line string) (bool, error) { p.Rest = line // Checks if the rest starts with `"abc"` - if !strings.HasPrefix(p.Rest, constAbc) { + if !strings.HasPrefix(p.Rest, constCheckPrefixAbc) { return false, nil } @@ -389,8 +390,8 @@ func (p *Custom) Extract(line string) (bool, error) { addrRest = p.Rest // Checks if the rest starts with `"addr: "` and pass it - if strings.HasPrefix(addrRest, constAddrColonSpace) { - addrRest = addrRest[len(constAddrColonSpace):] + if strings.HasPrefix(addrRest, constCustomAddrColonSpace) { + addrRest = addrRest[len(constCustomAddrColonSpace):] } else { p.Addr.Valid = false goto customAddrLabel @@ -485,8 +486,8 @@ func (p *SilentAreas) Extract(line string) (bool, error) { alt1Rest = p.Rest // Checks if the rest starts with `"Amount:"` and pass it - if strings.HasPrefix(alt1Rest, constAmountColon) { - alt1Rest = alt1Rest[len(constAmountColon):] + if strings.HasPrefix(alt1Rest, constSilentAreasAmountColon) { + alt1Rest = alt1Rest[len(constSilentAreasAmountColon):] } else { p.Alt1.Valid = false goto silentareasAlt1Label @@ -511,8 +512,8 @@ silentareasAlt1Label: alt2Rest = p.Rest // Checks if the rest starts with `"Amount:"` and pass it - if strings.HasPrefix(alt2Rest, constAmountColon) { - alt2Rest = alt2Rest[len(constAmountColon):] + if strings.HasPrefix(alt2Rest, constSilentAreasAmountColon) { + alt2Rest = alt2Rest[len(constSilentAreasAmountColon):] } else { p.Alt2.Valid = false goto silentareasAlt2Label