Skip to content

Commit b7cd37f

Browse files
committed
minor updates
1 parent b3d82bb commit b7cd37f

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

nfa.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ const (
3434
)
3535

3636
func toNfa(parseContext *parsingContext) (*State, *RegexError) {
37-
startFrom := 0
38-
endAt := len(parseContext.tokens) - 1
39-
40-
token := parseContext.tokens[startFrom]
37+
token := parseContext.tokens[0]
4138
startState, endState, err := tokenToNfa(token, parseContext, &State{
4239
transitions: map[uint8][]*State{},
4340
})
@@ -46,7 +43,7 @@ func toNfa(parseContext *parsingContext) (*State, *RegexError) {
4643
return nil, err
4744
}
4845

49-
for i := startFrom + 1; i <= endAt; i++ {
46+
for i := 1; i < len(parseContext.tokens); i++ {
5047
_, endNext, err := tokenToNfa(parseContext.tokens[i], parseContext, endState)
5148
if err != nil {
5249
return nil, err
@@ -302,12 +299,7 @@ func handleQuantifierToToken(token regexToken, parseContext *parsingContext, sta
302299
total = min
303300
}
304301
}
305-
var value regexToken
306-
if token.tokenType == quantifier {
307-
value = token.value.(quantifierPayload).value.([]regexToken)[0]
308-
} else {
309-
value = token.value.([]regexToken)[0]
310-
}
302+
var value = payload.value
311303
previousStart, previousEnd, err := tokenToNfa(value, parseContext, &State{
312304
transitions: map[uint8][]*State{},
313305
})

parse.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type regexToken struct {
3030
type quantifierPayload struct {
3131
min int
3232
max int
33-
value interface{}
33+
value regexToken
3434
}
3535

3636
type groupTokenPayload struct {
@@ -312,7 +312,7 @@ func parseQuantifier(ch uint8, parseContext *parsingContext) {
312312
value: quantifierPayload{
313313
min: bounds[0],
314314
max: bounds[1],
315-
value: parseContext.removeLast(1),
315+
value: parseContext.removeLast(1)[0],
316316
},
317317
}
318318
parseContext.push(token)
@@ -449,7 +449,7 @@ func parseBoundedQuantifier(regexString string, parseContext *parsingContext) *R
449449
value: quantifierPayload{
450450
min: start,
451451
max: end,
452-
value: parseContext.removeLast(1),
452+
value: parseContext.removeLast(1)[0],
453453
},
454454
}
455455
parseContext.push(token)

0 commit comments

Comments
 (0)