Skip to content

Commit

Permalink
rename all buff to buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Mar 17, 2024
1 parent 1e72d67 commit ac70b67
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 60 deletions.
34 changes: 17 additions & 17 deletions lib/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
34 changes: 17 additions & 17 deletions lib/lex_charclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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 '-'")
Expand All @@ -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
}
Expand All @@ -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
}

Expand All @@ -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
}
18 changes: 9 additions & 9 deletions lib/lex_function.go
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions lib/lex_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -82,7 +82,7 @@ Loop:
s.move(1)
s.openParenth--
s.lastGen = gen
s.buff = nil
s.buffer = nil
return LexRoot, nil
}

Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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
}

Expand Down
16 changes: 8 additions & 8 deletions lib/lex_repeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion lib/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type State struct {
lastGen generatorIface

input []rune
buff []rune
buffer []rune
output []rune

inputPos uint64
Expand Down

0 comments on commit ac70b67

Please sign in to comment.