Skip to content

Commit

Permalink
Merge pull request #129 from mattn/fix-typo-quote
Browse files Browse the repository at this point in the history
fix typos
  • Loading branch information
mattn authored Dec 30, 2023
2 parents 298f581 + 9006a82 commit 973c119
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 41 deletions.
14 changes: 7 additions & 7 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (

type RenderOptions struct {
LowerCase bool
IdentifierQuated bool
IdentifierQuoted bool
}

type Node interface {
Expand Down Expand Up @@ -67,7 +67,7 @@ func NewItem(tok *token.Token) Node {
return &Item{NewSQLToken(tok)}
}
func (i *Item) String() string { return i.Tok.String() }
func (i *Item) NoQuateString() string { return i.Tok.NoQuateString() }
func (i *Item) NoQuoteString() string { return i.Tok.NoQuoteString() }
func (i *Item) Render(opts *RenderOptions) string { return i.Tok.Render(opts) }
func (i *Item) Type() NodeType { return TypeItem }
func (i *Item) GetToken() *SQLToken { return i.Tok }
Expand Down Expand Up @@ -241,11 +241,11 @@ func (i *Identifier) String() string { return i.Tok.String() }
func (i *Identifier) Render(opts *RenderOptions) string {
tmpOpts := &RenderOptions{
LowerCase: false,
IdentifierQuated: opts.IdentifierQuated,
IdentifierQuoted: opts.IdentifierQuoted,
}
return i.Tok.Render(tmpOpts)
}
func (i *Identifier) NoQuateString() string { return i.Tok.NoQuateString() }
func (i *Identifier) NoQuoteString() string { return i.Tok.NoQuoteString() }
func (i *Identifier) GetToken() *SQLToken { return i.Tok }
func (i *Identifier) Pos() token.Pos { return i.Tok.From }
func (i *Identifier) End() token.Pos { return i.Tok.To }
Expand Down Expand Up @@ -523,10 +523,10 @@ func (t *SQLToken) String() string {
}
}

func (t *SQLToken) NoQuateString() string {
func (t *SQLToken) NoQuoteString() string {
switch v := t.Value.(type) {
case *token.SQLWord:
return v.NoQuateString()
return v.NoQuoteString()
case string:
return v
default:
Expand All @@ -548,7 +548,7 @@ func (t *SQLToken) Render(opts *RenderOptions) string {
func renderSQLWord(v *token.SQLWord, opts *RenderOptions) string {
isIdentifier := v.Kind == dialect.Unmatched
if isIdentifier {
if opts.IdentifierQuated {
if opts.IdentifierQuoted {
v.QuoteStyle = '`'
return v.String()
}
Expand Down
6 changes: 3 additions & 3 deletions internal/completer/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func getCompletionTypes(nw *parseutil.NodeWalker) *CompletionContext {
}
p = &completionParent{
Type: ParentTypeTable,
Name: mi.ParentTok.NoQuateString(),
Name: mi.ParentTok.NoQuoteString(),
}
} else {
t = []completionType{
Expand All @@ -341,7 +341,7 @@ func getCompletionTypes(nw *parseutil.NodeWalker) *CompletionContext {
}
p = &completionParent{
Type: ParentTypeSchema,
Name: mi.ParentTok.NoQuateString(),
Name: mi.ParentTok.NoQuoteString(),
}
} else {
t = []completionType{
Expand All @@ -363,7 +363,7 @@ func getCompletionTypes(nw *parseutil.NodeWalker) *CompletionContext {
}
p = &completionParent{
Type: ParentTypeTable,
Name: mi.ParentTok.NoQuateString(),
Name: mi.ParentTok.NoQuoteString(),
}
} else {
t = []completionType{
Expand Down
6 changes: 3 additions & 3 deletions internal/formatter/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestRenderIdentifier(t *testing.T) {
input: "SELECT * FROM snake_case_table_name",
opts: &ast.RenderOptions{
LowerCase: false,
IdentifierQuated: false,
IdentifierQuoted: false,
},
expected: []string{
"*",
Expand All @@ -62,7 +62,7 @@ func TestRenderIdentifier(t *testing.T) {
input: "SELECT p.PascalCaseColumnName FROM \"PascalCaseTableName\" p",
opts: &ast.RenderOptions{
LowerCase: false,
IdentifierQuated: false,
IdentifierQuoted: false,
},
expected: []string{
"p.PascalCaseColumnName",
Expand All @@ -74,7 +74,7 @@ func TestRenderIdentifier(t *testing.T) {
input: "SELECT p.\"PascalCaseColumnName\" FROM \"PascalCaseTableName\" p",
opts: &ast.RenderOptions{
LowerCase: false,
IdentifierQuated: false,
IdentifierQuoted: false,
},
expected: []string{
"p.\"PascalCaseColumnName\"",
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ var selectExprCase = []completionTestCase{
},
},
{
name: "filtered single quate table columns",
name: "filtered single quote table columns",
input: "select `Cou from city",
line: 0,
col: 10,
Expand Down
10 changes: 5 additions & 5 deletions internal/handler/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func hover(text string, params lsp.HoverParams, dbCache *database.DBCache) (*lsp
// Create hover contents
var hoverContent *lsp.MarkupContent
if ident != nil && memIdent != nil {
identName := ident.NoQuateString()
parentName := memIdent.ParentTok.NoQuateString()
childName := memIdent.ChildTok.NoQuateString()
identName := ident.NoQuoteString()
parentName := memIdent.ParentTok.NoQuoteString()
childName := memIdent.ChildTok.NoQuoteString()
if identName == parentName {
// The cursor is on the member identifier parent.
// example "w[o]rld.city"
Expand All @@ -101,11 +101,11 @@ func hover(text string, params lsp.HoverParams, dbCache *database.DBCache) (*lsp
} else if ident == nil && memIdent != nil {
// The cursor is on the dot with the member identifier
// example "world[.]city"
hoverContent = hoverContentFromChildIdent(ctx, memIdent.ChildTok.NoQuateString(), dbCache, hoverEnv)
hoverContent = hoverContentFromChildIdent(ctx, memIdent.ChildTok.NoQuoteString(), dbCache, hoverEnv)
} else if ident != nil && memIdent == nil {
// The cursor is on the identifier
// example "c[i]ty"
hoverContent = hoverContentFromIdent(ctx, ident.NoQuateString(), dbCache, hoverEnv)
hoverContent = hoverContentFromIdent(ctx, ident.NoQuoteString(), dbCache, hoverEnv)
}
if hoverContent == nil {
return nil, ErrNoHover
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/hover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ var hoverTestCases = []struct {
col: 15,
},
{
name: "select quated ident head",
name: "select quoted ident head",
input: "SELECT `ID`, Name FROM city",
output: "`city`.`ID` column\n\n`int(11)` PRI auto_increment\n",
line: 0,
col: 8,
},
{
name: "select quated ident head",
name: "select quoted ident head",
input: "SELECT `ID`, Name FROM city",
output: "`city`.`ID` column\n\n`int(11)` PRI auto_increment\n",
line: 0,
Expand Down
10 changes: 5 additions & 5 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func TestParseIdentifier(t *testing.T) {
},
},
{
name: "double quate identifier",
name: "double quote identifier",
input: `"abc"`,
checkFn: func(t *testing.T, stmts []*ast.Statement, input string) {
testStatement(t, stmts[0], 1, input)
Expand All @@ -330,7 +330,7 @@ func TestParseIdentifier(t *testing.T) {
},
},
{
name: "back quate identifier",
name: "back quote identifier",
input: "`abc`",
checkFn: func(t *testing.T, stmts []*ast.Statement, input string) {
testStatement(t, stmts[0], 1, input)
Expand All @@ -339,7 +339,7 @@ func TestParseIdentifier(t *testing.T) {
},
},
{
name: "non close back quate identifier",
name: "non close back quote identifier",
input: "`abc",
checkFn: func(t *testing.T, stmts []*ast.Statement, input string) {
testStatement(t, stmts[0], 1, input)
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestMemberIdentifier(t *testing.T) {
},
},
{
name: "double quate member identifier",
name: "double quote member identifier",
input: `"abc"."def"`,
checkFn: func(t *testing.T, stmts []*ast.Statement, input string) {
testStatement(t, stmts[0], 1, input)
Expand All @@ -416,7 +416,7 @@ func TestMemberIdentifier(t *testing.T) {
},
},
{
name: "back quate member identifier",
name: "back quote member identifier",
input: "`abc`.`def`",
checkFn: func(t *testing.T, stmts []*ast.Statement, input string) {
testStatement(t, stmts[0], 1, input)
Expand Down
22 changes: 11 additions & 11 deletions parser/parseutil/parseutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func parseTableInfo(idents ast.Node) ([]*TableInfo, error) {
res := []*TableInfo{}
switch v := idents.(type) {
case *ast.Identifier:
ti := &TableInfo{Name: v.NoQuateString()}
ti := &TableInfo{Name: v.NoQuoteString()}
res = append(res, ti)
case *ast.IdentifierList:
tis, err := identifierListToTableInfo(v)
Expand Down Expand Up @@ -416,7 +416,7 @@ func identifierListToTableInfo(il *ast.IdentifierList) ([]*TableInfo, error) {
switch v := ident.(type) {
case *ast.Identifier:
ti := &TableInfo{
Name: v.NoQuateString(),
Name: v.NoQuoteString(),
}
tis = append(tis, ti)
case *ast.MemberIdentifier:
Expand All @@ -439,7 +439,7 @@ func aliasedToTableInfo(aliased *ast.Aliased) (*TableInfo, error) {
// fetch table schema and name
switch v := aliased.RealName.(type) {
case *ast.Identifier:
ti.Name = v.NoQuateString()
ti.Name = v.NoQuoteString()
case *ast.MemberIdentifier:
ti.DatabaseSchema = v.Parent.String()
ti.Name = v.GetChild().String()
Expand All @@ -461,7 +461,7 @@ func aliasedToTableInfo(aliased *ast.Aliased) (*TableInfo, error) {
// fetch table aliased name
switch v := aliased.AliasedName.(type) {
case *ast.Identifier:
ti.Alias = v.NoQuateString()
ti.Alias = v.NoQuoteString()
default:
return nil, fmt.Errorf(
"failed parse aliased name of alias, unknown node type %T, value %q",
Expand All @@ -476,7 +476,7 @@ func parseSubQueryColumns(idents ast.Node, tables []*TableInfo) ([]*SubQueryColu
subqueryCols := []*SubQueryColumn{}
switch v := idents.(type) {
case *ast.Identifier:
ident := v.NoQuateString()
ident := v.NoQuoteString()
if ident == "*" {
for _, table := range tables {
subqueryCol := &SubQueryColumn{
Expand Down Expand Up @@ -504,8 +504,8 @@ func parseSubQueryColumns(idents ast.Node, tables []*TableInfo) ([]*SubQueryColu
subqueryCols = append(
subqueryCols,
&SubQueryColumn{
ParentName: v.GetParentIdent().NoQuateString(),
ColumnName: v.GetChildIdent().NoQuateString(),
ParentName: v.GetParentIdent().NoQuoteString(),
ColumnName: v.GetChildIdent().NoQuoteString(),
},
)
case *ast.Aliased:
Expand All @@ -532,18 +532,18 @@ func parseSubQueryColumns(idents ast.Node, tables []*TableInfo) ([]*SubQueryColu

func aliasedToSubQueryColumn(aliased *ast.Aliased) (*SubQueryColumn, error) {
// fetch table schema and name
aliasedName := aliased.GetAliasedNameIdent().NoQuateString()
aliasedName := aliased.GetAliasedNameIdent().NoQuoteString()
switch v := aliased.RealName.(type) {
case *ast.Identifier:
subqueryCol := &SubQueryColumn{
ColumnName: v.NoQuateString(),
ColumnName: v.NoQuoteString(),
AliasName: aliasedName,
}
return subqueryCol, nil
case *ast.MemberIdentifier:
subqueryCol := &SubQueryColumn{
ParentName: v.GetParentIdent().NoQuateString(),
ColumnName: v.GetChildIdent().NoQuateString(),
ParentName: v.GetParentIdent().NoQuoteString(),
ColumnName: v.GetChildIdent().NoQuoteString(),
AliasName: aliasedName,
}
return subqueryCol, nil
Expand Down
2 changes: 1 addition & 1 deletion token/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (s *SQLWord) String() string {
}
}

func (s *SQLWord) NoQuateString() string {
func (s *SQLWord) NoQuoteString() string {
return s.Value
}

Expand Down
6 changes: 3 additions & 3 deletions token/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ select`,
},
},
{
name: "non closed single quate identifier",
name: "non closed single quote identifier",
in: "'foo",
out: []*Token{
{
Expand All @@ -339,7 +339,7 @@ select`,
},
},
{
name: "non closed double quate identifier",
name: "non closed double quote identifier",
in: `"foo`,
out: []*Token{
{
Expand All @@ -356,7 +356,7 @@ select`,
},
},
{
name: "non closed back quate identifier",
name: "non closed back quote identifier",
in: "`foo bar",
out: []*Token{
{
Expand Down

0 comments on commit 973c119

Please sign in to comment.