Skip to content

Commit

Permalink
fix lexeer issue, it's value to have numbers inside the field (just n…
Browse files Browse the repository at this point in the history
…ot at the start)

Also simplified logic
  • Loading branch information
splitice committed Jun 12, 2022
1 parent 3cff1d0 commit 6cdbaec
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pkg/logql/log/jsonexpr/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (sc *Scanner) lex(lval *JSONExprSymType) int {
return RSB
case r == '.':
return DOT
case isIdentifier(r):
case isStartIdentifier(r):
sc.unread()
lval.field = sc.scanField()
return FIELD
Expand All @@ -83,21 +83,20 @@ func (sc *Scanner) lex(lval *JSONExprSymType) int {
}
}

func isIdentifier(r rune) bool {
func isStartIdentifier(r rune) bool {
return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || r == '_'
}

func isIdentifier(r rune) bool {
return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '_'
}

func (sc *Scanner) scanField() string {
var str []rune

for {
r := sc.read()
if !isIdentifier(r) {
sc.unread()
break
}

if r == '.' || isEndOfInput(r) {
if !isIdentifier(r) || isEndOfInput(r) {
sc.unread()
break
}
Expand Down

0 comments on commit 6cdbaec

Please sign in to comment.