github.com/waldiirawan/apm-agent-go/v2@v2.2.2/sqlutil/token.go (about)

     1  // Licensed to Elasticsearch B.V. under one or more contributor
     2  // license agreements. See the NOTICE file distributed with
     3  // this work for additional information regarding copyright
     4  // ownership. Elasticsearch B.V. licenses this file to you under
     5  // the Apache License, Version 2.0 (the "License"); you may
     6  // not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing,
    12  // software distributed under the License is distributed on an
    13  // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    14  // KIND, either express or implied.  See the License for the
    15  // specific language governing permissions and limitations
    16  // under the License.
    17  
    18  package sqlutil // import "github.com/waldiirawan/apm-agent-go/v2/sqlutil"
    19  
    20  import "fmt"
    21  
    22  // Token represents a SQL token.
    23  type Token int
    24  
    25  func (t Token) String() string {
    26  	s := tokenStrings[t]
    27  	if s == "" {
    28  		s = fmt.Sprintf("Token(%d)", t)
    29  	}
    30  	return s
    31  }
    32  
    33  // The list of SQL tokens.
    34  const (
    35  	OTHER Token = iota // anything we don't specifically care about
    36  	eof
    37  	COMMENT
    38  
    39  	IDENT  // includes unhandled keywords
    40  	NUMBER // 123, 123.45, 123e+45
    41  	STRING // 'foo'
    42  
    43  	PERIOD // .
    44  	COMMA  // ,
    45  	LPAREN // (
    46  	RPAREN // )
    47  
    48  	AS
    49  	CALL
    50  	DELETE
    51  	FROM
    52  	INSERT
    53  	INTO
    54  	OR
    55  	REPLACE
    56  	SELECT
    57  	SET
    58  	TABLE
    59  	TRUNCATE // Cassandra/CQL-specific
    60  	UPDATE
    61  )
    62  
    63  var tokenStrings = [...]string{
    64  	OTHER:   "OTHER",
    65  	eof:     "EOF",
    66  	COMMENT: "COMMENT",
    67  
    68  	IDENT:  "IDENT",
    69  	NUMBER: "NUMBER",
    70  	STRING: "STRING",
    71  
    72  	PERIOD: "PERIOD",
    73  	COMMA:  "COMMA",
    74  	LPAREN: "LPAREN",
    75  	RPAREN: "RPAREN",
    76  
    77  	AS:       "AS",
    78  	CALL:     "CALL",
    79  	DELETE:   "DELETE",
    80  	FROM:     "FROM",
    81  	INSERT:   "INSERT",
    82  	INTO:     "INTO",
    83  	OR:       "OR",
    84  	REPLACE:  "REPLACE",
    85  	SELECT:   "SELECT",
    86  	SET:      "SET",
    87  	TABLE:    "TABLE",
    88  	TRUNCATE: "TRUNCATE",
    89  	UPDATE:   "UPDATE",
    90  }
    91  
    92  // keywords contains keyword tokens, indexed
    93  // at the position of keyword length.
    94  var keywords = [...][]Token{
    95  	2: []Token{AS, OR},
    96  	3: []Token{SET},
    97  	4: []Token{CALL, FROM, INTO},
    98  	5: []Token{TABLE},
    99  	6: []Token{DELETE, INSERT, SELECT, UPDATE},
   100  	7: []Token{REPLACE},
   101  	8: []Token{TRUNCATE},
   102  }