diff --git a/lib/lex.go b/lib/lex.go index baa1d01..fdf2f6e 100644 --- a/lib/lex.go +++ b/lib/lex.go @@ -17,8 +17,8 @@ func init() { // LexRoot is the root lex implementation func LexRoot(s *State) (LexType, error) { - if s.buff != nil { - return nil, s.errorUnknown("incomplete buffer: %s", string(s.buff)) + if s.buffer != nil { + return nil, s.errorUnknown("incomplete buffer: %s", string(s.buffer)) } if s.end() { if s.openParenth > 0 { @@ -83,13 +83,13 @@ func lexBackslash(s *State) (LexType, error) { s.move(1) switch c { case 'u': - if s.buff != nil { - return nil, s.errorUnknown("incomplete buffer: %s", string(s.buff)) + if s.buffer != nil { + return nil, s.errorUnknown("incomplete buffer: %s", string(s.buffer)) } return lexRootUnicode, nil case 'U': - if s.buff != nil { - return nil, s.errorUnknown("incomplete buffer: %s", string(s.buff)) + if s.buffer != nil { + return nil, s.errorUnknown("incomplete buffer: %s", string(s.buffer)) } return lexRootUnicodeWide, nil } @@ -114,28 +114,28 @@ func lexIdent(s *State) (LexType, error) { s.openParenth++ return lexIdentFuncCall, nil } - s.buff = append(s.buff, c) + s.buffer = append(s.buffer, c) return lexIdent, nil } -func makeLexUnicode(parentLex LexType, symbol rune, width int, toBuff bool) LexType { +func makeLexUnicode(parentLex LexType, symbol rune, width int, toBuffer bool) LexType { return func(s *State) (LexType, error) { - buff := make([]rune, 0, width) - buff = append(buff, '\\', symbol) - for ; len(buff) < width && !s.end(); s.move(1) { - buff = append(buff, s.input[s.inputPos]) + buffer := make([]rune, 0, width) + buffer = append(buffer, '\\', symbol) + for ; len(buffer) < width && !s.end(); s.move(1) { + buffer = append(buffer, s.input[s.inputPos]) } - if len(buff) != width { - s.errorMarkLen = len(buff) + if len(buffer) != width { + s.errorMarkLen = len(buffer) return nil, s.errorSyntax("invalid escape sequence") } - char, _, _, err := strconv.UnquoteChar(string(buff), '"') + char, _, _, err := strconv.UnquoteChar(string(buffer), '"') if err != nil { s.errorMarkLen = width return nil, s.errorSyntax("invalid escape sequence") } - if toBuff { - s.buff = append(s.buff, char) + if toBuffer { + s.buffer = append(s.buffer, char) } else { err := s.addOutputOne(char) if err != nil { diff --git a/lib/lex_charclass.go b/lib/lex_charclass.go index f8d5764..cf6bb20 100644 --- a/lib/lex_charclass.go +++ b/lib/lex_charclass.go @@ -15,7 +15,7 @@ func processRange(s *State, charset []rune) (LexType, error) { if err != nil { return nil, err } - s.buff = nil + s.buffer = nil s.lastGen = gen return LexRoot, nil } @@ -37,14 +37,14 @@ func lexRange(s *State) (LexType, error) { case '-': return lexRangeDashInit, nil case '^': - if !s.rangeReverse && len(s.buff) == 0 { + if !s.rangeReverse && len(s.buffer) == 0 { s.rangeReverse = true return lexRange, nil } case ']': - return processRange(s, s.buff) + return processRange(s, s.buffer) } - s.buff = append(s.buff, c) + s.buffer = append(s.buffer, c) return lexRange, nil } @@ -65,7 +65,7 @@ func lexRangeColon(s *State) (LexType, error) { s.errorMarkLen = len(name) + 2 return nil, s.errorValue("invalid character class %#v", name) } - s.buff = append(s.buff, charset...) + s.buffer = append(s.buffer, charset...) return lexRange, nil case ']': s.errorMarkLen = len(nameRunes) + 2 @@ -81,10 +81,10 @@ func lexRangeColon(s *State) (LexType, error) { func lexRangeDashInit(s *State) (LexType, error) { if s.end() { s.errorOffset++ - s.errorMarkLen = len(s.buff) + 3 + s.errorMarkLen = len(s.buffer) + 3 return nil, s.errorSyntax("'[' not closed") } - s.buff = append(s.buff, s.input[s.inputPos-1], s.input[s.inputPos]) + s.buffer = append(s.buffer, s.input[s.inputPos-1], s.input[s.inputPos]) s.move(1) if s.end() { return nil, s.errorSyntax("no character after '-'") @@ -93,23 +93,23 @@ func lexRangeDashInit(s *State) (LexType, error) { } func lexRangeDash(s *State) (LexType, error) { - n := len(s.buff) + n := len(s.buffer) if n < 3 { s.errorOffset-- return nil, s.errorSyntax("no character before '-'") } - c1 := s.buff[n-1] + c1 := s.buffer[n-1] if c1 == '\\' { - s.buff = s.buff[:n-1] + s.buffer = s.buffer[:n-1] return lexRangeDashBackslash, nil } - if s.buff[n-2] != '-' { - return nil, s.errorUnknown("expected '-', buffer=%#v", string(s.buff)) + if s.buffer[n-2] != '-' { + return nil, s.errorUnknown("expected '-', buffer=%#v", string(s.buffer)) } - c0 := s.buff[n-3] - s.buff = s.buff[:n-2] + c0 := s.buffer[n-3] + s.buffer = s.buffer[:n-2] for b := int(c0) + 1; b <= int(c1); b++ { - s.buff = append(s.buff, rune(b)) + s.buffer = append(s.buffer, rune(b)) } return lexRange, nil } @@ -126,7 +126,7 @@ func lexRangeBackslash(s *State) (LexType, error) { if c == 'U' { return makeLexUnicode(lexRange, 'U', 10, true), nil } - s.buff = append(s.buff, backslashEscape(c)) + s.buffer = append(s.buffer, backslashEscape(c)) return lexRange, nil } @@ -142,6 +142,6 @@ func lexRangeDashBackslash(s *State) (LexType, error) { if c == 'U' { return makeLexUnicode(lexRangeDash, 'U', 10, true), nil } - s.buff = append(s.buff, backslashEscape(c)) + s.buffer = append(s.buffer, backslashEscape(c)) return lexRangeDash, nil } diff --git a/lib/lex_function.go b/lib/lex_function.go index 534376b..c2f85c5 100644 --- a/lib/lex_function.go +++ b/lib/lex_function.go @@ -1,6 +1,6 @@ package passgen -func _lexIdentFuncCallParanClose(s *State, buff []rune) (LexType, error) { +func _lexIdentFuncCallParanClose(s *State, buffer []rune) (LexType, error) { if s.openBracket { return nil, nil } @@ -10,12 +10,12 @@ func _lexIdentFuncCallParanClose(s *State, buff []rune) (LexType, error) { } s.move(1) s2 := NewState(s.SharedState.Copy(), s.input) - s2.errorOffset -= int64(len(buff) + 1) - funcName := string(s.buff) + s2.errorOffset -= int64(len(buffer) + 1) + funcName := string(s.buffer) if funcName == "" { return nil, s2.errorSyntax("missing function name") } - gen, err := getFuncGenerator(s2, funcName, buff) + gen, err := getFuncGenerator(s2, funcName, buffer) if err != nil { return nil, err } @@ -26,7 +26,7 @@ func _lexIdentFuncCallParanClose(s *State, buff []rune) (LexType, error) { s.output = append(s.output, s2.output...) s.patternEntropy = s2.patternEntropy s.lastGroupId = s2.lastGroupId - s.buff = nil + s.buffer = nil s.lastGen = gen return LexRoot, nil } @@ -39,13 +39,13 @@ func _lexIdentFuncCallEndError(s *State) error { return s.errorSyntax(s_func_call_expected) } -func _lexIdentFuncCallBackslash(s *State, buff []rune) []rune { - buff = append(buff, '\\') +func _lexIdentFuncCallBackslash(s *State, buffer []rune) []rune { + buffer = append(buffer, '\\') s.move(1) if !s.end() { - buff = append(buff, s.input[s.inputPos]) + buffer = append(buffer, s.input[s.inputPos]) } - return buff + return buffer } func lexIdentFuncCall(s *State) (LexType, error) { diff --git a/lib/lex_group.go b/lib/lex_group.go index d08bbe3..9e3c4f5 100644 --- a/lib/lex_group.go +++ b/lib/lex_group.go @@ -19,7 +19,7 @@ func lexGroup(s *State) (LexType, error) { case ')': s.openParenth-- if s.openParenth > 0 { - s.buff = append(s.buff, ')') + s.buffer = append(s.buffer, ')') return lexGroup, nil } return processGroupEnd(s) @@ -28,10 +28,10 @@ func lexGroup(s *State) (LexType, error) { s.errorOffset++ return nil, s.errorSyntax("'|' at the end of group") } - s.moveBack(uint64(len(s.buff) + 1)) + s.moveBack(uint64(len(s.buffer) + 1)) return lexGroupAlter, nil } - s.buff = append(s.buff, c) + s.buffer = append(s.buffer, c) return lexGroup, nil } @@ -82,7 +82,7 @@ Loop: s.move(1) s.openParenth-- s.lastGen = gen - s.buff = nil + s.buffer = nil return LexRoot, nil } @@ -93,7 +93,7 @@ func processGroupBackslash(s *State) (LexType, error) { } c := s.input[s.inputPos] s.move(1) - s.buff = append(s.buff, '\\', c) + s.buffer = append(s.buffer, '\\', c) return lexGroup, nil } @@ -102,8 +102,8 @@ func processGroupEnd(s *State) (LexType, error) { lastOutputSize := len(s.output) s2 := NewState(s.SharedState.Copy(), s.input) s2.output = s.output - s2.errorOffset -= int64(len(s.buff) + 1) - gen := newGroupGenerator(s.buff) + s2.errorOffset -= int64(len(s.buffer) + 1) + gen := newGroupGenerator(s.buffer) err := gen.Generate(s2) if err != nil { return nil, err @@ -113,7 +113,7 @@ func processGroupEnd(s *State) (LexType, error) { s.lastGroupId = s2.lastGroupId s.groupsOutput[groupId] = s.output[lastOutputSize:] s.lastGen = gen - s.buff = nil + s.buffer = nil return LexRoot, nil } diff --git a/lib/lex_repeat.go b/lib/lex_repeat.go index 2f1b483..23ff604 100644 --- a/lib/lex_repeat.go +++ b/lib/lex_repeat.go @@ -22,28 +22,28 @@ func lexRepeat(s *State) (LexType, error) { case '$': return nil, s.errorSyntax("'$' inside {...}") case ',': - if hasRune(s.buff, ',') { + if hasRune(s.buffer, ',') { return nil, s.errorSyntax("multiple ',' inside {...}") } - s.buff = append(s.buff, c) + s.buffer = append(s.buffer, c) return lexRepeat, nil case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': - s.buff = append(s.buff, c) + s.buffer = append(s.buffer, c) return lexRepeat, nil case '-': - if hasRune(s.buff, ',') { + if hasRune(s.buffer, ',') { return nil, s.errorSyntax("invalid natural number") } return nil, s.errorSyntax("repetition range syntax is '{M,N}' not '{M-N}'") case '}': return closeLexRepeat(s) } - s.errorMarkLen = len(s.buff) + 1 + s.errorMarkLen = len(s.buffer) + 1 return nil, s.errorSyntax("invalid natural number inside {...}") } func closeLexRepeat(s *State) (LexType, error) { - if len(s.buff) == 0 { + if len(s.buffer) == 0 { return nil, s.errorSyntax("missing number inside {}") } if s.lastGen == nil { @@ -52,7 +52,7 @@ func closeLexRepeat(s *State) (LexType, error) { } child := s.lastGen // FIXME: lastGen may have used another state - count, err := parseRepeatCount(s, s.buff) + count, err := parseRepeatCount(s, s.buffer) if err != nil { return nil, err } @@ -73,7 +73,7 @@ func closeLexRepeat(s *State) (LexType, error) { // but we need to re-set g.count after gen.Generate(s), because the whole thing // might be repeated again s.lastGen = gen - s.buff = nil + s.buffer = nil return LexRoot, nil } diff --git a/lib/state.go b/lib/state.go index 9c01f18..985ee2f 100644 --- a/lib/state.go +++ b/lib/state.go @@ -30,7 +30,7 @@ type State struct { lastGen generatorIface input []rune - buff []rune + buffer []rune output []rune inputPos uint64