Skip to content

Commit

Permalink
Rename Ident to Unquoted
Browse files Browse the repository at this point in the history
  • Loading branch information
grobinson-grafana committed Aug 19, 2023
1 parent baf6e0c commit daa7cdf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion matchers/parse/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (l *Lexer) scanIdent() (Token, error) {
break
}
}
return l.emit(TokenIdent), nil
return l.emit(TokenUnquoted), nil
}

func (l *Lexer) scanOperator() (Token, error) {
Expand Down
44 changes: 22 additions & 22 deletions matchers/parse/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ func TestLexer_Scan(t *testing.T) {
},
}},
}, {
name: "ident",
name: "unquoted",
input: "hello",
expected: []Token{{
Kind: TokenIdent,
Kind: TokenUnquoted,
Value: "hello",
Position: Position{
OffsetStart: 0,
Expand All @@ -135,10 +135,10 @@ func TestLexer_Scan(t *testing.T) {
},
}},
}, {
name: "ident with underscore",
name: "unquoted with underscore",
input: "hello_world",
expected: []Token{{
Kind: TokenIdent,
Kind: TokenUnquoted,
Value: "hello_world",
Position: Position{
OffsetStart: 0,
Expand All @@ -148,10 +148,10 @@ func TestLexer_Scan(t *testing.T) {
},
}},
}, {
name: "ident with colon",
name: "unquoted with colon",
input: "hello:world",
expected: []Token{{
Kind: TokenIdent,
Kind: TokenUnquoted,
Value: "hello:world",
Position: Position{
OffsetStart: 0,
Expand All @@ -161,10 +161,10 @@ func TestLexer_Scan(t *testing.T) {
},
}},
}, {
name: "ident with numbers",
name: "unquoted with numbers",
input: "hello0123456789",
expected: []Token{{
Kind: TokenIdent,
Kind: TokenUnquoted,
Value: "hello0123456789",
Position: Position{
OffsetStart: 0,
Expand All @@ -174,10 +174,10 @@ func TestLexer_Scan(t *testing.T) {
},
}},
}, {
name: "ident can start with underscore",
name: "unquoted can start with underscore",
input: "_hello",
expected: []Token{{
Kind: TokenIdent,
Kind: TokenUnquoted,
Value: "_hello",
Position: Position{
OffsetStart: 0,
Expand All @@ -187,10 +187,10 @@ func TestLexer_Scan(t *testing.T) {
},
}},
}, {
name: "idents separated with space",
name: "unquoted separated with space",
input: "hello world",
expected: []Token{{
Kind: TokenIdent,
Kind: TokenUnquoted,
Value: "hello",
Position: Position{
OffsetStart: 0,
Expand All @@ -199,7 +199,7 @@ func TestLexer_Scan(t *testing.T) {
ColumnEnd: 5,
},
}, {
Kind: TokenIdent,
Kind: TokenUnquoted,
Value: "world",
Position: Position{
OffsetStart: 6,
Expand Down Expand Up @@ -364,14 +364,14 @@ func TestLexer_Scan(t *testing.T) {
input: "Σ",
err: "0:1: Σ: invalid input",
}, {
name: "unexpected : at start of ident",
name: "unexpected : at start of unquoted",
input: ":hello",
err: "0:1: :: invalid input",
}, {
name: "unexpected $ in ident",
name: "unexpected $ in unquoted",
input: "hello$",
expected: []Token{{
Kind: TokenIdent,
Kind: TokenUnquoted,
Value: "hello",
Position: Position{
OffsetStart: 0,
Expand All @@ -382,10 +382,10 @@ func TestLexer_Scan(t *testing.T) {
}},
err: "5:6: $: invalid input",
}, {
name: "unexpected unicode letter in ident",
name: "unexpected unicode letter in unquoted",
input: "helloΣ",
expected: []Token{{
Kind: TokenIdent,
Kind: TokenUnquoted,
Value: "hello",
Position: Position{
OffsetStart: 0,
Expand All @@ -396,10 +396,10 @@ func TestLexer_Scan(t *testing.T) {
}},
err: "5:6: Σ: invalid input",
}, {
name: "unexpected emoji in ident",
name: "unexpected emoji in unquoted",
input: "hello🙂",
expected: []Token{{
Kind: TokenIdent,
Kind: TokenUnquoted,
Value: "hello",
Position: Position{
OffsetStart: 0,
Expand Down Expand Up @@ -507,7 +507,7 @@ func TestLexer_ScanError(t *testing.T) {
func TestLexer_Peek(t *testing.T) {
l := NewLexer("hello world")
expected1 := Token{
Kind: TokenIdent,
Kind: TokenUnquoted,
Value: "hello",
Position: Position{
OffsetStart: 0,
Expand All @@ -517,7 +517,7 @@ func TestLexer_Peek(t *testing.T) {
},
}
expected2 := Token{
Kind: TokenIdent,
Kind: TokenUnquoted,
Value: "world",
Position: Position{
OffsetStart: 6,
Expand Down
12 changes: 6 additions & 6 deletions matchers/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (p *Parser) parseComma(l *Lexer) (parseFn, error) {
}
// The token after the comma can be another matcher, a close brace or the
// end of input.
tok, err := p.expect(l.Peek, TokenCloseBrace, TokenIdent, TokenQuoted)
tok, err := p.expect(l.Peek, TokenCloseBrace, TokenUnquoted, TokenQuoted)
if err != nil {
if errors.Is(err, ErrEOF) {
// If this is the end of input we still need to check if the optional
Expand Down Expand Up @@ -217,10 +217,10 @@ func (p *Parser) parseLabelMatcher(l *Lexer) (parseFn, error) {
ty labels.MatchType
)

// The next token is the label name. This can either be an ident which
// The next token is the label name. This can either be an unquoted which
// accepts just [a-zA-Z_] or a quoted which accepts all UTF-8 characters
// in double quotes.
if tok, err = p.expect(l.Scan, TokenIdent, TokenQuoted); err != nil {
if tok, err = p.expect(l.Scan, TokenUnquoted, TokenQuoted); err != nil {
return nil, fmt.Errorf("%s: %w", err, ErrNoLabelName)
}
labelName = tok.Value
Expand All @@ -233,13 +233,13 @@ func (p *Parser) parseLabelMatcher(l *Lexer) (parseFn, error) {
panic("Unexpected operator")
}

// The next token is the label value. This too can either be an ident
// The next token is the label value. This too can either be an unquoted
// which accepts just [a-zA-Z_] or a quoted which accepts all UTF-8
// characters in double quotes.
if tok, err = p.expect(l.Scan, TokenIdent, TokenQuoted); err != nil {
if tok, err = p.expect(l.Scan, TokenUnquoted, TokenQuoted); err != nil {
return nil, fmt.Errorf("%s: %s", err, ErrNoLabelValue)
}
if tok.Kind == TokenIdent {
if tok.Kind == TokenUnquoted {
labelValue = tok.Value
} else {
labelValue, err = strconv.Unquote(tok.Value)
Expand Down
6 changes: 3 additions & 3 deletions matchers/parse/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ const (
TokenNone TokenKind = iota
TokenCloseBrace
TokenComma
TokenIdent
TokenOpenBrace
TokenOperator
TokenQuoted
TokenUnquoted
)

func (k TokenKind) String() string {
Expand All @@ -35,14 +35,14 @@ func (k TokenKind) String() string {
return "CloseBrace"
case TokenComma:
return "Comma"
case TokenIdent:
return "Ident"
case TokenOpenBrace:
return "OpenBrace"
case TokenOperator:
return "Op"
case TokenQuoted:
return "Quoted"
case TokenUnquoted:
return "Unquoted"
default:
return "None"
}
Expand Down

0 comments on commit daa7cdf

Please sign in to comment.