github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/parser/scanner.l (about)

     1  %{
     2  // Copyright 2013 The ql Authors. All rights reserved.
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSES/QL-LICENSE file.
     5  
     6  // Copyright 2015 PingCAP, Inc.
     7  //
     8  // Licensed under the Apache License, Version 2.0 (the "License");
     9  // you may not use this file except in compliance with the License.
    10  // You may obtain a copy of the License at
    11  //
    12  //     http://www.apache.org/licenses/LICENSE-2.0
    13  //
    14  // Unless required by applicable law or agreed to in writing, software
    15  // distributed under the License is distributed on an "AS IS" BASIS,
    16  // See the License for the specific language governing permissions and
    17  // limitations under the License.
    18  
    19  package parser
    20  
    21  import (
    22  	"fmt"
    23  	"math"
    24  	"strconv"
    25  	"strings"
    26  	"unicode"
    27  
    28  	"github.com/pingcap/tidb/ast"
    29  	"github.com/pingcap/tidb/mysql"
    30  	"github.com/pingcap/tidb/util/charset"
    31  	"github.com/pingcap/tidb/util/stringutil"
    32  )
    33  
    34  type lexer struct {
    35  	c		int
    36  	col		int
    37  	errs		[]error
    38  	expr		ast.ExprNode
    39  	i		int
    40  	inj		int
    41  	lcol		int
    42  	line		int
    43  	list		[]ast.StmtNode
    44  	ncol		int
    45  	nline		int
    46  	sc		int
    47  	src		string
    48  	val		[]byte
    49  	ungetBuf	[]byte
    50  	root		bool
    51  	prepare		bool
    52  	stmtStartPos 	int
    53  	stringLit 	[]byte
    54  
    55  	// record token's offset of the input
    56  	tokenEndOffset   int
    57  	tokenStartOffset int
    58  
    59  	// Charset information
    60  	charset		string
    61  	collation	string
    62  }
    63  
    64  
    65  // NewLexer builds a new lexer.
    66  func NewLexer(src string) (l *lexer) {
    67  	l = &lexer{
    68  		src:	src,
    69  		nline:	1,
    70  		ncol:	0,
    71  	}
    72  	l.next()
    73  	return
    74  }
    75  
    76  func (l *lexer) Errors() []error {
    77  	return l.errs
    78  }
    79  
    80  func (l *lexer) Stmts() []ast.StmtNode {
    81  	return l.list
    82  }
    83  
    84  func (l *lexer) Expr() ast.ExprNode {
    85  	return l.expr
    86  }
    87  
    88  func (l *lexer) Inj() int {
    89  	return l.inj
    90  }
    91  
    92  func (l *lexer) SetInj(inj int) {
    93  	l.inj = inj
    94  }
    95  
    96  func (l *lexer) SetPrepare() {
    97  	l.prepare = true
    98  }
    99  
   100  func (l *lexer) IsPrepare() bool {
   101  	return l.prepare
   102  }
   103  
   104  func (l *lexer) Root() bool {
   105  	return l.root
   106  }
   107  
   108  func (l *lexer) SetRoot(root bool) {
   109  	l.root = root
   110  }
   111  
   112  func (l *lexer) SetCharsetInfo(charset, collation string) {
   113  	l.charset = charset
   114  	l.collation = collation
   115  }
   116  
   117  func (l *lexer) GetCharsetInfo() (string, string) {
   118  	return l.charset, l.collation
   119  }
   120  
   121  // The select statement is not at the end of the whole statement, if the last
   122  // field text was set from its offset to the end of the src string, update
   123  // the last field text.
   124  func (l *lexer) SetLastSelectFieldText(st *ast.SelectStmt, lastEnd int) {
   125  	lastField := st.Fields.Fields[len(st.Fields.Fields)-1]
   126  	if lastField.Offset + len(lastField.Text()) >= len(l.src)-1 {
   127  		lastField.SetText(l.src[lastField.Offset:lastEnd])
   128  	}
   129  }
   130  
   131  func (l *lexer) startOffset(offset int) int {
   132  	offset--
   133  	for unicode.IsSpace(rune(l.src[offset])) {
   134  		offset++
   135  	}
   136  	return offset
   137  }
   138  
   139  func (l *lexer) endOffset(offset int) int {
   140  	offset--
   141  	for offset > 0 && unicode.IsSpace(rune(l.src[offset-1])) {
   142  		offset--
   143  	}
   144  	return offset
   145  }
   146  
   147  func (l *lexer) unget(b byte) {
   148  	l.ungetBuf = append(l.ungetBuf, b)
   149  	l.i--
   150  	l.ncol--
   151  	l.tokenEndOffset--
   152  }
   153  
   154  func (l *lexer) next() int {
   155  	if un := len(l.ungetBuf); un > 0 {
   156  		nc := l.ungetBuf[0]
   157  		l.ungetBuf = l.ungetBuf[1:]
   158  		l.c = int(nc)
   159  		return  l.c
   160  	}
   161  
   162  	if l.c != 0 {
   163  		l.val = append(l.val, byte(l.c))
   164  	}
   165  	l.c = 0
   166  	if l.i < len(l.src) {
   167  		l.c = int(l.src[l.i])
   168  		l.i++
   169  	}
   170  	switch l.c {
   171  	case '\n':
   172  		l.lcol = l.ncol
   173  		l.nline++
   174  		l.ncol = 0
   175  	default:
   176  		l.ncol++
   177  	}
   178  	l.tokenEndOffset++
   179  	return l.c
   180  }
   181  
   182  func (l *lexer) err0(ln, c int, arg interface{}) {
   183  	var argStr string
   184  	if arg != nil {
   185  		argStr = fmt.Sprintf(" %v", arg)
   186  	}
   187  
   188  	err := fmt.Errorf("line %d column %d near \"%s\"%s", ln, c, l.val, argStr)
   189  	l.errs = append(l.errs, err)
   190  }
   191  
   192  func (l *lexer) err(arg interface{}) {
   193  	l.err0(l.line, l.col, arg)
   194  }
   195  
   196  func (l *lexer) errf(format string, args ...interface{}) {
   197  	s := fmt.Sprintf(format, args...)
   198  	l.err0(l.line, l.col, s)
   199  }
   200  
   201  func (l *lexer) Error(s string) {
   202  	// Notice: ignore origin error info.
   203  	l.err(nil)
   204  }
   205  
   206  func (l *lexer) stmtText() string {
   207  	endPos := l.i
   208  	if l.src[l.i-1] == '\n' {
   209  		endPos = l.i-1 // trim new line	
   210  	}
   211  	if l.src[l.stmtStartPos] == '\n' {
   212  		l.stmtStartPos++	
   213  	}
   214  
   215  	text := l.src[l.stmtStartPos:endPos] 
   216  
   217  	l.stmtStartPos = l.i
   218  	return text
   219  }
   220  
   221  
   222  func (l *lexer) Lex(lval *yySymType) (r int) {
   223  	defer func() {
   224  		lval.line, lval.col, lval.offset = l.line, l.col, l.tokenStartOffset
   225  		l.tokenStartOffset = l.tokenEndOffset
   226  	}()
   227  	const (
   228  		INITIAL = iota
   229  		S1
   230  		S2
   231  		S3
   232  		S4
   233  	)
   234  
   235  	if n := l.inj; n != 0 {
   236  		l.inj = 0
   237  		return n
   238  	}
   239  
   240  	c0, c := 0, l.c
   241  %}
   242  
   243  int_lit		{decimal_lit}|{octal_lit}
   244  decimal_lit	[1-9][0-9]*
   245  octal_lit	0[0-7]*
   246  hex_lit		0[xX][0-9a-fA-F]+|[xX]"'"[0-9a-fA-F]+"'"
   247  bit_lit 	0[bB][01]+|[bB]"'"[01]+"'"
   248  
   249  float_lit	{D}"."{D}?{E}?|{D}{E}|"."{D}{E}?
   250  D		[0-9]+
   251  E		[eE][-+]?[0-9]+
   252  
   253  imaginary_ilit	{D}i
   254  imaginary_lit	{float_lit}i
   255  
   256  a		[aA]
   257  b		[bB]
   258  c		[cC]
   259  d		[dD]
   260  e		[eE]
   261  f		[fF]
   262  g		[gG]
   263  h		[hH]
   264  i		[iI]
   265  j		[jJ]
   266  k		[kK]
   267  l		[lL]
   268  m		[mM]
   269  n		[nN]
   270  o		[oO]
   271  p		[pP]
   272  q		[qQ]
   273  r		[rR]
   274  s		[sS]
   275  t		[tT]
   276  u		[uU]
   277  v		[vV]
   278  w		[wW]
   279  x		[xX]
   280  y		[yY]
   281  z		[zZ]
   282  
   283  abs		{a}{b}{s}
   284  add		{a}{d}{d}
   285  adddate		{a}{d}{d}{d}{a}{t}{e}
   286  admin		{a}{d}{m}{i}{n}
   287  after		{a}{f}{t}{e}{r}
   288  all		{a}{l}{l}
   289  alter		{a}{l}{t}{e}{r}
   290  and		{a}{n}{d}
   291  any 		{a}{n}{y}
   292  as		{a}{s}
   293  asc		{a}{s}{c}
   294  ascii		{a}{s}{c}{i}{i}
   295  auto_increment	{a}{u}{t}{o}_{i}{n}{c}{r}{e}{m}{e}{n}{t}
   296  avg		{a}{v}{g}
   297  avg_row_length	{a}{v}{g}_{r}{o}{w}_{l}{e}{n}{g}{t}{h}
   298  begin		{b}{e}{g}{i}{n}
   299  between		{b}{e}{t}{w}{e}{e}{n}
   300  both		{b}{o}{t}{h}
   301  btree		{b}{t}{r}{e}{e}
   302  by		{b}{y}
   303  case		{c}{a}{s}{e}
   304  cast		{c}{a}{s}{t}
   305  character	{c}{h}{a}{r}{a}{c}{t}{e}{r}
   306  charset		{c}{h}{a}{r}{s}{e}{t}
   307  check 		{c}{h}{e}{c}{k}
   308  checksum 	{c}{h}{e}{c}{k}{s}{u}{m}
   309  coalesce	{c}{o}{a}{l}{e}{s}{c}{e}
   310  collate		{c}{o}{l}{l}{a}{t}{e}
   311  collation	{c}{o}{l}{l}{a}{t}{i}{o}{n}
   312  column		{c}{o}{l}{u}{m}{n}
   313  columns		{c}{o}{l}{u}{m}{n}{s}
   314  comment 	{c}{o}{m}{m}{e}{n}{t}
   315  commit		{c}{o}{m}{m}{i}{t}
   316  committed	{c}{o}{m}{m}{i}{t}{t}{e}{d}
   317  compact		{c}{o}{m}{p}{a}{c}{t}
   318  compressed	{c}{o}{m}{p}{r}{e}{s}{s}{e}{d}
   319  compression	{c}{o}{m}{p}{r}{e}{s}{s}{i}{o}{n}
   320  concat		{c}{o}{n}{c}{a}{t}
   321  concat_ws	{c}{o}{n}{c}{a}{t}_{w}{s}
   322  connection	{c}{o}{n}{n}{e}{c}{t}{i}{o}{n}
   323  connection_id	{c}{o}{n}{n}{e}{c}{t}{i}{o}{n}_{i}{d}
   324  constraint	{c}{o}{n}{s}{t}{r}{a}{i}{n}{t}
   325  convert		{c}{o}{n}{v}{e}{r}{t}
   326  count		{c}{o}{u}{n}{t}
   327  create		{c}{r}{e}{a}{t}{e}
   328  cross		{c}{r}{o}{s}{s}
   329  curdate 	{c}{u}{r}{d}{a}{t}{e}
   330  current_date	{c}{u}{r}{r}{e}{n}{t}_{d}{a}{t}{e}
   331  curtime 	{c}{u}{r}{t}{i}{m}{e}
   332  current_time	{c}{u}{r}{r}{e}{n}{t}_{t}{i}{m}{e}
   333  current_user	{c}{u}{r}{r}{e}{n}{t}_{u}{s}{e}{r}
   334  database	{d}{a}{t}{a}{b}{a}{s}{e}
   335  databases	{d}{a}{t}{a}{b}{a}{s}{e}{s}
   336  date_add	{d}{a}{t}{e}_{a}{d}{d}
   337  date_sub	{d}{a}{t}{e}_{s}{u}{b}
   338  day		{d}{a}{y}
   339  dayname	{d}{a}{y}{n}{a}{m}{e}
   340  dayofweek	{d}{a}{y}{o}{f}{w}{e}{e}{k}
   341  dayofmonth	{d}{a}{y}{o}{f}{m}{o}{n}{t}{h}
   342  dayofyear	{d}{a}{y}{o}{f}{y}{e}{a}{r}
   343  ddl		{d}{d}{l}
   344  deallocate	{d}{e}{a}{l}{l}{o}{c}{a}{t}{e}
   345  default		{d}{e}{f}{a}{u}{l}{t}
   346  delayed		{d}{e}{l}{a}{y}{e}{d}
   347  delay_key_write	{d}{e}{l}{a}{y}_{k}{e}{y}_{w}{r}{i}{t}{e}
   348  delete		{d}{e}{l}{e}{t}{e}
   349  drop		{d}{r}{o}{p}
   350  desc		{d}{e}{s}{c}
   351  describe	{d}{e}{s}{c}{r}{i}{b}{e}
   352  distinct	{d}{i}{s}{t}{i}{n}{c}{t}
   353  div		{d}{i}{v}
   354  disable		{d}{i}{s}{a}{b}{l}{e}
   355  do		{d}{o}
   356  dual 		{d}{u}{a}{l}
   357  duplicate	{d}{u}{p}{l}{i}{c}{a}{t}{e}
   358  dynamic		{d}{y}{n}{a}{m}{i}{c}
   359  else		{e}{l}{s}{e}
   360  enable		{e}{n}{a}{b}{l}{e}
   361  end		{e}{n}{d}
   362  engine		{e}{n}{g}{i}{n}{e}
   363  engines		{e}{n}{g}{i}{n}{e}{s}
   364  escape		{e}{s}{c}{a}{p}{e}
   365  execute		{e}{x}{e}{c}{u}{t}{e}
   366  exists		{e}{x}{i}{s}{t}{s}
   367  explain		{e}{x}{p}{l}{a}{i}{n}
   368  extract		{e}{x}{t}{r}{a}{c}{t}
   369  fields		{f}{i}{e}{l}{d}{s}
   370  first		{f}{i}{r}{s}{t}
   371  fixed		{f}{i}{x}{e}{d}
   372  for		{f}{o}{r}
   373  force		{f}{o}{r}{c}{e}
   374  foreign		{f}{o}{r}{e}{i}{g}{n}
   375  found_rows	{f}{o}{u}{n}{d}_{r}{o}{w}{s}
   376  from		{f}{r}{o}{m}
   377  full		{f}{u}{l}{l}
   378  fulltext	{f}{u}{l}{l}{t}{e}{x}{t}
   379  global		{g}{l}{o}{b}{a}{l}
   380  grant		{g}{r}{a}{n}{t}
   381  grants		{g}{r}{a}{n}{t}{s}
   382  group		{g}{r}{o}{u}{p}
   383  group_concat	{g}{r}{o}{u}{p}_{c}{o}{n}{c}{a}{t}
   384  hash		{h}{a}{s}{h}
   385  having		{h}{a}{v}{i}{n}{g}
   386  high_priority	{h}{i}{g}{h}_{p}{r}{i}{o}{r}{i}{t}{y}
   387  hour		{h}{o}{u}{r}
   388  identified	{i}{d}{e}{n}{t}{i}{f}{i}{e}{d}
   389  if		{i}{f}
   390  ifnull		{i}{f}{n}{u}{l}{l}
   391  ignore		{i}{g}{n}{o}{r}{e}
   392  in		{i}{n}
   393  index		{i}{n}{d}{e}{x}
   394  inner 		{i}{n}{n}{e}{r}
   395  insert		{i}{n}{s}{e}{r}{t}
   396  interval	{i}{n}{t}{e}{r}{v}{a}{l}
   397  into		{i}{n}{t}{o}
   398  is		{i}{s}
   399  isnull		{i}{s}{n}{u}{l}{l}
   400  isolation	{i}{s}{o}{l}{a}{t}{i}{o}{n}
   401  join		{j}{o}{i}{n}
   402  key		{k}{e}{y}
   403  keys		{k}{e}{y}{s}
   404  key_block_size	{k}{e}{y}_{b}{l}{o}{c}{k}_{s}{i}{z}{e}
   405  leading		{l}{e}{a}{d}{i}{n}{g}
   406  left		{l}{e}{f}{t}
   407  length		{l}{e}{n}{g}{t}{h}
   408  level		{l}{e}{v}{e}{l}
   409  like		{l}{i}{k}{e}
   410  limit		{l}{i}{m}{i}{t}
   411  local		{l}{o}{c}{a}{l}
   412  locate		{l}{o}{c}{a}{t}{e}
   413  lock		{l}{o}{c}{k}
   414  lower		{l}{o}{w}{e}{r}
   415  lcase		{l}{c}{a}{s}{e}
   416  low_priority	{l}{o}{w}_{p}{r}{i}{o}{r}{i}{t}{y}
   417  ltrim		{l}{t}{r}{i}{m}
   418  max_rows	{m}{a}{x}_{r}{o}{w}{s}
   419  microsecond	{m}{i}{c}{r}{o}{s}{e}{c}{o}{n}{d}
   420  minute		{m}{i}{n}{u}{t}{e}
   421  min_rows	{m}{i}{n}_{r}{o}{w}{s}
   422  mod 		{m}{o}{d}
   423  mode		{m}{o}{d}{e}
   424  month		{m}{o}{n}{t}{h}
   425  names		{n}{a}{m}{e}{s}
   426  national	{n}{a}{t}{i}{o}{n}{a}{l}
   427  not		{n}{o}{t}
   428  offset		{o}{f}{f}{s}{e}{t}
   429  on		{o}{n}
   430  only		{o}{n}{l}{y}
   431  option		{o}{p}{t}{i}{o}{n}
   432  or		{o}{r}
   433  order		{o}{r}{d}{e}{r}
   434  outer		{o}{u}{t}{e}{r}
   435  password	{p}{a}{s}{s}{w}{o}{r}{d}
   436  pow 		{p}{o}{w}
   437  power		{p}{o}{w}{e}{r}
   438  prepare		{p}{r}{e}{p}{a}{r}{e}
   439  primary		{p}{r}{i}{m}{a}{r}{y}
   440  procedure	{p}{r}{o}{c}{e}{d}{u}{r}{e}
   441  quarter		{q}{u}{a}{r}{t}{e}{r}
   442  quick		{q}{u}{i}{c}{k}
   443  rand		{r}{a}{n}{d}
   444  read		{r}{e}{a}{d}
   445  repeat		{r}{e}{p}{e}{a}{t}
   446  repeatable	{r}{e}{p}{e}{a}{t}{a}{b}{l}{e}
   447  references	{r}{e}{f}{e}{r}{e}{n}{c}{e}{s}
   448  regexp		{r}{e}{g}{e}{x}{p}
   449  replace		{r}{e}{p}{l}{a}{c}{e}
   450  redundant	{r}{e}{d}{u}{n}{d}{a}{n}{t}
   451  reverse		{r}{e}{v}{e}{r}{s}{e}
   452  right		{r}{i}{g}{h}{t}
   453  rlike		{r}{l}{i}{k}{e}
   454  rollback	{r}{o}{l}{l}{b}{a}{c}{k}
   455  round		{r}{o}{u}{n}{d}
   456  row 		{r}{o}{w}
   457  row_format	{r}{o}{w}_{f}{o}{r}{m}{a}{t}
   458  rtrim		{r}{t}{r}{i}{m}
   459  schema		{s}{c}{h}{e}{m}{a}
   460  schemas		{s}{c}{h}{e}{m}{a}{s}
   461  second		{s}{e}{c}{o}{n}{d}
   462  select		{s}{e}{l}{e}{c}{t}
   463  serializable	{s}{e}{r}{i}{a}{l}{i}{z}{a}{b}{l}{e}
   464  session		{s}{e}{s}{s}{i}{o}{n}
   465  set		{s}{e}{t}
   466  share		{s}{h}{a}{r}{e}
   467  show		{s}{h}{o}{w}
   468  some		{s}{o}{m}{e}
   469  start		{s}{t}{a}{r}{t}
   470  status          {s}{t}{a}{t}{u}{s}
   471  subdate		{s}{u}{b}{d}{a}{t}{e}
   472  strcmp		{s}{t}{r}{c}{m}{p}
   473  substr		{s}{u}{b}{s}{t}{r}
   474  substring	{s}{u}{b}{s}{t}{r}{i}{n}{g}
   475  substring_index	{s}{u}{b}{s}{t}{r}{i}{n}{g}_{i}{n}{d}{e}{x}
   476  sum		{s}{u}{m}
   477  sysdate		{s}{y}{s}{d}{a}{t}{e}
   478  table		{t}{a}{b}{l}{e}
   479  tables		{t}{a}{b}{l}{e}{s}
   480  then		{t}{h}{e}{n}
   481  to		{t}{o}
   482  trailing	{t}{r}{a}{i}{l}{i}{n}{g}
   483  transaction	{t}{r}{a}{n}{s}{a}{c}{t}{i}{o}{n}
   484  triggers	{t}{r}{i}{g}{g}{e}{r}{s}
   485  trim		{t}{r}{i}{m}
   486  truncate	{t}{r}{u}{n}{c}{a}{t}{e}
   487  max		{m}{a}{x}
   488  min		{m}{i}{n}
   489  uncommitted	{u}{n}{c}{o}{m}{m}{i}{t}{t}{e}{d}
   490  unknown		{u}{n}{k}{n}{o}{w}{n}
   491  union		{u}{n}{i}{o}{n}
   492  unique		{u}{n}{i}{q}{u}{e}
   493  unlock		{u}{n}{l}{o}{c}{k}
   494  nullif		{n}{u}{l}{l}{i}{f}
   495  update		{u}{p}{d}{a}{t}{e}
   496  upper		{u}{p}{p}{e}{r}
   497  ucase		{u}{c}{a}{s}{e}
   498  utc_date	{u}{t}{c}_{d}{a}{t}{e}
   499  value		{v}{a}{l}{u}{e}
   500  values		{v}{a}{l}{u}{e}{s}
   501  variables	{v}{a}{r}{i}{a}{b}{l}{e}{s}
   502  version		{v}{e}{r}{s}{i}{o}{n}
   503  warnings	{w}{a}{r}{n}{i}{n}{g}{s}
   504  week		{w}{e}{e}{k}
   505  weekday		{w}{e}{e}{k}{d}{a}{y}
   506  weekofyear	{w}{e}{e}{k}{o}{f}{y}{e}{a}{r}
   507  where		{w}{h}{e}{r}{e}
   508  when		{w}{h}{e}{n}
   509  write		{w}{r}{i}{t}{e}
   510  xor		{x}{o}{r}
   511  yearweek	{y}{e}{a}{r}{w}{e}{e}{k}
   512  
   513  null		{n}{u}{l}{l}
   514  false		{f}{a}{l}{s}{e}
   515  true		{t}{r}{u}{e}
   516  
   517  calc_found_rows	{s}{q}{l}_{c}{a}{l}{c}_{f}{o}{u}{n}{d}_{r}{o}{w}{s}
   518  sql_cache	{s}{q}{l}_{c}{a}{c}{h}{e}
   519  sql_no_cache	{s}{q}{l}_{n}{o}_{c}{a}{c}{h}{e}
   520  
   521  current_ts	{c}{u}{r}{r}{e}{n}{t}_{t}{i}{m}{e}{s}{t}{a}{m}{p}
   522  localtime	{l}{o}{c}{a}{l}{t}{i}{m}{e}
   523  localts		{l}{o}{c}{a}{l}{t}{i}{m}{e}{s}{t}{a}{m}{p}
   524  now		{n}{o}{w}
   525  
   526  bit		{b}{i}{t}
   527  tiny		{t}{i}{n}{y}
   528  tinyint		{t}{i}{n}{y}{i}{n}{t}
   529  smallint	{s}{m}{a}{l}{l}{i}{n}{t}
   530  mediumint	{m}{e}{d}{i}{u}{m}{i}{n}{t}
   531  int		{i}{n}{t}
   532  integer		{i}{n}{t}{e}{g}{e}{r}
   533  bigint		{b}{i}{g}{i}{n}{t}
   534  real		{r}{e}{a}{l}
   535  double		{d}{o}{u}{b}{l}{e}
   536  float		{f}{l}{o}{a}{t}
   537  decimal		{d}{e}{c}{i}{m}{a}{l}
   538  numeric		{n}{u}{m}{e}{r}{i}{c}
   539  date		{d}{a}{t}{e}
   540  time		{t}{i}{m}{e}
   541  timestamp	{t}{i}{m}{e}{s}{t}{a}{m}{p}
   542  datetime	{d}{a}{t}{e}{t}{i}{m}{e}
   543  year		{y}{e}{a}{r}
   544  char		{c}{h}{a}{r}
   545  varchar		{v}{a}{r}{c}{h}{a}{r}
   546  binary		{b}{i}{n}{a}{r}{y}
   547  varbinary	{v}{a}{r}{b}{i}{n}{a}{r}{y}
   548  tinyblob	{t}{i}{n}{y}{b}{l}{o}{b}
   549  blob		{b}{l}{o}{b}
   550  mediumblob	{m}{e}{d}{i}{u}{m}{b}{l}{o}{b}
   551  longblob	{l}{o}{n}{g}{b}{l}{o}{b}
   552  tinytext	{t}{i}{n}{y}{t}{e}{x}{t}
   553  text		{t}{e}{x}{t}
   554  mediumtext	{m}{e}{d}{i}{u}{m}{t}{e}{x}{t}
   555  longtext	{l}{o}{n}{g}{t}{e}{x}{t}
   556  enum		{e}{n}{u}{m}
   557  precision	{p}{r}{e}{c}{i}{s}{i}{o}{n}
   558  
   559  signed		{s}{i}{g}{n}{e}{d}
   560  unsigned	{u}{n}{s}{i}{g}{n}{e}{d}
   561  zerofill	{z}{e}{r}{o}{f}{i}{l}{l}
   562  
   563  bigrat		{b}{i}{g}{r}{a}{t}
   564  bool		{b}{o}{o}{l}
   565  boolean		{b}{o}{o}{l}{e}{a}{n}
   566  byte		{b}{y}{t}{e}
   567  duration	{d}{u}{r}{a}{t}{i}{o}{n}
   568  rune		{r}{u}{n}{e}
   569  string		{s}{t}{r}{i}{n}{g}
   570  use		{u}{s}{e}
   571  user		{u}{s}{e}{r}
   572  using		{u}{s}{i}{n}{g}
   573  
   574  idchar0		[a-zA-Z_]
   575  idchars		{idchar0}|[0-9$] // See: https://dev.mysql.com/doc/refman/5.7/en/identifiers.html
   576  ident		{idchar0}{idchars}*
   577  
   578  user_var	"@"{ident}
   579  sys_var		"@@"(({global}".")|({session}".")|{local}".")?{ident}
   580  
   581  second_microsecond	{s}{e}{c}{o}{n}{d}_{m}{i}{c}{r}{o}{s}{e}{c}{o}{n}{d}
   582  minute_microsecond	{m}{i}{n}{u}{t}{e}_{m}{i}{c}{r}{o}{s}{e}{c}{o}{n}{d}
   583  minute_second 		{m}{i}{n}{u}{t}{e}_{s}{e}{c}{o}{n}{d}
   584  hour_microsecond	{h}{o}{u}{r}_{m}{i}{c}{r}{o}{s}{e}{c}{o}{n}{d}
   585  hour_second 		{h}{o}{u}{r}_{s}{e}{c}{o}{n}{d}
   586  hour_minute		{h}{o}{u}{r}_{m}{i}{n}{u}{t}{e}
   587  day_microsecond		{d}{a}{y}_{m}{i}{c}{r}{o}{s}{e}{c}{o}{n}{d}
   588  day_second 		{d}{a}{y}_{s}{e}{c}{o}{n}{d}
   589  day_minute		{d}{a}{y}_{m}{i}{n}{u}{t}{e}
   590  day_hour		{d}{a}{y}_{h}{o}{u}{r}
   591  year_month		{y}{e}{a}{r}_{m}{o}{n}{t}{h}
   592  
   593  restrict	{r}{e}{s}{t}{r}{i}{c}{t}
   594  cascade		{c}{a}{s}{c}{a}{d}{e}
   595  no		{n}{o}
   596  action		{a}{c}{t}{i}{o}{n}
   597  
   598  %yyc c
   599  %yyn c = l.next()
   600  %yyt l.sc
   601  
   602  %x S1 S2 S3 S4
   603  
   604  %%
   605  		l.val = l.val[:0]
   606  		c0, l.line, l.col = l.c, l.nline, l.ncol
   607                          
   608  <*>\0		return 0
   609  
   610  [ \t\n\r]+
   611  #.*
   612  \/\/.*
   613  \/\*([^*]|\*+[^*/])*\*+\/
   614  --			l.sc = S3
   615  <S3>[ \t]+.*		{l.sc = 0} 
   616  <S3>[^ \t]		{
   617  				l.sc = 0
   618  				l.c = '-'
   619  				n := len(l.val)
   620  				l.unget(l.val[n-1])
   621  				return '-' 
   622  			}
   623  
   624  {int_lit}		return l.int(lval)
   625  {float_lit}		return l.float(lval)
   626  {hex_lit}		return l.hex(lval)
   627  {bit_lit}		return l.bit(lval)
   628  
   629  \"			l.sc = S1
   630  '			l.sc = S2
   631  `			l.sc = S4
   632  
   633  <S1>[^\"\\]*		l.stringLit = append(l.stringLit, l.val...)	
   634  <S1>\\.			l.stringLit = append(l.stringLit, l.val...)
   635  <S1>\"\"		l.stringLit = append(l.stringLit, '"')
   636  <S1>\"			l.stringLit = append(l.stringLit, '"')
   637  			l.sc = 0
   638  			return l.str(lval, "\"")	
   639  <S2>[^'\\]*		l.stringLit = append(l.stringLit, l.val...)	
   640  <S2>\\.			l.stringLit = append(l.stringLit, l.val...)
   641  <S2>''			l.stringLit = append(l.stringLit, '\'')
   642  <S2>'			l.stringLit = append(l.stringLit, '\'')
   643  			l.sc = 0
   644  			return l.str(lval, "'")
   645  <S4>[^`]*		l.stringLit = append(l.stringLit, l.val...)	
   646  <S4>``			l.stringLit = append(l.stringLit, '`')
   647  <S4>`			l.sc = 0
   648  			lval.item = string(l.stringLit)
   649  			l.stringLit = l.stringLit[0:0]
   650  			return identifier
   651  
   652  "&&"			return andand
   653  "&^"			return andnot
   654  "<<"			return lsh
   655  "<="			return le
   656  "=" 			return eq
   657  ":="			return assignmentEq
   658  ">="			return ge
   659  "!="			return neq
   660  "<>"			return neq
   661  "||"			return oror
   662  ">>"			return rsh
   663  "<=>"			return nulleq
   664  
   665  "@"			return at
   666  "?"			return placeholder
   667  
   668  {abs}			lval.item = string(l.val)
   669  			return abs
   670  {add}			return add
   671  {adddate}		lval.item = string(l.val)
   672  			return addDate
   673  {admin}			lval.item = string(l.val)
   674  			return admin
   675  {after}			lval.item = string(l.val)
   676  			return after
   677  {all}			return all
   678  {alter}			return alter
   679  {and}			return and
   680  {any}			lval.item = string(l.val)
   681  			return any
   682  {asc}			return asc
   683  {as}			return as
   684  {ascii}			lval.item = string(l.val)
   685  			return ascii
   686  {auto_increment}	lval.item = string(l.val)
   687  			return autoIncrement
   688  {avg}			lval.item = string(l.val)
   689  			return avg
   690  {avg_row_length}	lval.item = string(l.val)
   691  			return avgRowLength
   692  {begin}			lval.item = string(l.val)
   693  			return begin
   694  {between}		return between
   695  {both}			return both
   696  {btree}			lval.item = string(l.val)
   697  			return btree
   698  {by}			return by
   699  {case}			return caseKwd
   700  {cast}			lval.item = string(l.val)
   701  			return cast
   702  {character}		return character
   703  {charset}		lval.item = string(l.val)
   704  			return charsetKwd
   705  {check}			return check
   706  {checksum}		lval.item = string(l.val)
   707  			return checksum
   708  {coalesce}		lval.item = string(l.val)
   709  			return coalesce
   710  {collate}		return collate
   711  {collation}		lval.item = string(l.val)
   712  			return collation
   713  {column}		return column
   714  {columns}		lval.item = string(l.val)
   715  			return columns
   716  {comment}		lval.item = string(l.val)
   717  			return comment
   718  {commit}		lval.item = string(l.val)
   719  			return commit
   720  {committed}		lval.item = string(l.val)
   721  			return committed
   722  {compact}		lval.item = string(l.val)
   723  			return compact
   724  {compressed}		lval.item = string(l.val)
   725  			return compressed
   726  {compression}		lval.item = string(l.val)
   727  			return compression
   728  {concat}		lval.item = string(l.val)
   729  			return concat
   730  {concat_ws}		lval.item = string(l.val)
   731  			return concatWs
   732  {connection}		lval.item = string(l.val)
   733  			return connection
   734  {connection_id}		lval.item = string(l.val)
   735  			return connectionID
   736  {constraint}		return constraint
   737  {convert}		lval.item = string(l.val)
   738  			return convert
   739  {count}			lval.item = string(l.val)
   740  			return count
   741  {create}		return create
   742  {cross}			return cross
   743  {curdate}		lval.item = string(l.val)
   744  			return curDate
   745  {current_date}		lval.item = string(l.val)
   746  			return currentDate
   747  {curtime}		lval.item = string(l.val)
   748  			return curTime
   749  {current_time}		lval.item = string(l.val)
   750  			return currentTime
   751  {current_user}		lval.item = string(l.val)
   752  			return currentUser
   753  {database}		lval.item = string(l.val)
   754  			return database
   755  {databases}		return databases
   756  {date_add}		lval.item = string(l.val)
   757  			return dateAdd
   758  {date_sub}		lval.item = string(l.val)
   759  			return dateSub
   760  {day}			lval.item = string(l.val)
   761  			return day
   762  {dayname}		lval.item = string(l.val)
   763  			return dayname
   764  {dayofweek}		lval.item = string(l.val)
   765  			return dayofweek
   766  {dayofmonth}		lval.item = string(l.val)
   767  			return dayofmonth
   768  {dayofyear}		lval.item = string(l.val)
   769  			return dayofyear
   770  {day_hour}		lval.item = string(l.val)
   771  			return dayHour
   772  {day_microsecond}	lval.item = string(l.val)
   773  			return dayMicrosecond
   774  {day_minute}		lval.item = string(l.val)
   775  			return dayMinute
   776  {day_second}		lval.item = string(l.val)
   777  			return daySecond
   778  {ddl}			return ddl
   779  {deallocate}		lval.item = string(l.val)
   780  			return deallocate
   781  {default}		return defaultKwd
   782  {delayed}		return delayed
   783  {delay_key_write}	lval.item = string(l.val)
   784  			return delayKeyWrite
   785  {delete}		return deleteKwd
   786  {desc}			return desc
   787  {describe}		return describe
   788  {drop}			return drop
   789  {disable}		lval.item = string(l.val)
   790  			return disable
   791  {distinct}		return distinct
   792  {div}			return div
   793  {do}			lval.item = string(l.val)
   794  			return do
   795  {dual}			return dual
   796  {duplicate}		lval.item = string(l.val)
   797  			return duplicate
   798  {dynamic}		lval.item = string(l.val)
   799  			return dynamic
   800  {else}			return elseKwd
   801  {enable}		lval.item = string(l.val)
   802  			return enable
   803  {end}			lval.item = string(l.val)
   804  			return end
   805  {engine}		lval.item = string(l.val)
   806  			return engine
   807  {engines}		lval.item = string(l.val)
   808  			return engines
   809  {execute}		lval.item = string(l.val)
   810  			return execute
   811  {enum}			return enum
   812  {escape}		lval.item = string(l.val)
   813  			return escape
   814  {exists}		return exists
   815  {explain}		return explain
   816  {extract}		lval.item = string(l.val)
   817  			return extract
   818  {fields}		lval.item = string(l.val)
   819  			return fields
   820  {first}			lval.item = string(l.val)
   821  			return first
   822  {fixed}			lval.item = string(l.val)
   823  			return fixed
   824  {for}			return forKwd
   825  {force}			return force
   826  {foreign}		return foreign
   827  {found_rows}		lval.item = string(l.val)
   828  			return foundRows
   829  {from}			return from
   830  {full}			lval.item = string(l.val)
   831  			return full
   832  {fulltext}		return fulltext
   833  {grant}			return grant
   834  {grants}		lval.item = string(l.val)
   835  			return grants
   836  {group}			return group
   837  {group_concat}		lval.item = string(l.val)
   838  			return groupConcat
   839  {hash}			lval.item = string(l.val)
   840  			return hash
   841  {having}		return having
   842  {high_priority}		return highPriority
   843  {hour}			lval.item = string(l.val)
   844  			return hour
   845  {hour_microsecond}	lval.item = string(l.val)
   846  			return hourMicrosecond
   847  {hour_minute}		lval.item = string(l.val)
   848  			return hourMinute
   849  {hour_second}		lval.item = string(l.val)
   850  			return hourSecond
   851  {identified}		lval.item = string(l.val)
   852  			return identified
   853  {if}			lval.item = string(l.val)
   854  			return ifKwd
   855  {ifnull}		lval.item = string(l.val)
   856  			return ifNull
   857  {isnull}		lval.item = string(l.val)
   858  			return isNull
   859  {ignore}		return ignore
   860  {index}			return index
   861  {inner} 		return inner
   862  {insert}		return insert
   863  {interval}		return interval
   864  {into}			return into
   865  {in}			return in
   866  {is}			return is
   867  {isolation}		lval.item = string(l.val)
   868  			return isolation
   869  {join}			return join
   870  {key}			return key
   871  {key_block_size}	lval.item = string(l.val)
   872  			return keyBlockSize
   873  {keys}			return keys
   874  {leading}		return leading
   875  {left}			lval.item = string(l.val)
   876  			return left
   877  {length}		lval.item = string(l.val)
   878  			return length
   879  {level}			lval.item = string(l.val)
   880  			return level
   881  {like}			return like
   882  {limit}			return limit
   883  {local}			lval.item = string(l.val)
   884  			return local
   885  {locate}		lval.item = string(l.val)
   886  			return locate
   887  {lock}			return lock
   888  {lower}			lval.item = string(l.val)
   889  			return lower
   890  {lcase}			lval.item = string(l.val)
   891  			return lcase
   892  {low_priority}		return lowPriority
   893  {ltrim}			lval.item = string(l.val)
   894  			return ltrim
   895  {max}			lval.item = string(l.val)
   896  			return max
   897  {max_rows}		lval.item = string(l.val)
   898  			return maxRows
   899  {microsecond}		lval.item = string(l.val)
   900  			return microsecond
   901  {min}			lval.item = string(l.val)
   902  			return min
   903  {minute}		lval.item = string(l.val)
   904  			return minute
   905  {minute_microsecond}	lval.item = string(l.val)
   906  			return minuteMicrosecond
   907  {minute_second}		lval.item = string(l.val)
   908  			return minuteSecond
   909  {min_rows}		lval.item = string(l.val)
   910  			return minRows
   911  {mod}			return mod
   912  {mode}			lval.item = string(l.val)
   913  			return mode
   914  {month}			lval.item = string(l.val)
   915  			return month
   916  {names}			lval.item = string(l.val)
   917  			return names
   918  {national}		lval.item = string(l.val)
   919  			return national
   920  {not}			return not
   921  {offset}		lval.item = string(l.val)
   922  			return offset
   923  {on}			return on
   924  {only}			lval.item = string(l.val)
   925  			return only
   926  {option}		return option
   927  {order}			return order
   928  {or}			return or
   929  {outer}			return outer
   930  {password}		lval.item = string(l.val)
   931  			return password
   932  {pow}			lval.item = string(l.val)
   933  			return pow
   934  {power}		lval.item = string(l.val)
   935  			return power
   936  {prepare}		lval.item = string(l.val)
   937  			return prepare
   938  {primary}		return primary
   939  {procedure}		return procedure
   940  {quarter}		lval.item = string(l.val)
   941  			return quarter
   942  {quick}			lval.item = string(l.val)
   943  			return quick
   944  redundant		lval.item = string(l.val)
   945  			return redundant
   946  {right}			return right
   947  {rollback}		lval.item = string(l.val)
   948  			return rollback
   949  {round}			lval.item = string(l.val)
   950  			return round
   951  {row}			lval.item = string(l.val)
   952  			return row
   953  {row_format}		lval.item = string(l.val)
   954  			return rowFormat
   955  {schema}		lval.item = string(l.val)
   956  			return schema
   957  {schemas}		return schemas
   958  {serializable}		lval.item = string(l.val)
   959  			return serializable
   960  {session}		lval.item = string(l.val)
   961  			return session
   962  {some}			lval.item = string(l.val)
   963  			return some
   964  {start}			lval.item = string(l.val)
   965  			return start
   966  {status}		lval.item = string(l.val)
   967  			return status
   968  {global}		lval.item = string(l.val)
   969  			return global
   970  {rand}			lval.item = string(l.val)
   971  			return rand
   972  {read}			return read
   973  {repeat}		lval.item = string(l.val)
   974  			return repeat
   975  {repeatable}		lval.item = string(l.val)
   976  			return repeatable
   977  {regexp}		return regexpKwd
   978  {replace}		lval.item = string(l.val)
   979  			return replace
   980  {references}		return references
   981  {rlike}			return rlike
   982  {rtrim}			lval.item = string(l.val)
   983  			return rtrim
   984  {reverse}		lval.item = string(l.val)
   985  			return reverse
   986  
   987  {sys_var}		lval.item = string(l.val)
   988  			return sysVar
   989  
   990  {user_var}		lval.item = string(l.val)
   991  			return userVar
   992  {utc_date}		lval.item = string(l.val)
   993  			return utcDate
   994  {second}		lval.item = string(l.val)
   995  			return second
   996  {second_microsecond}	lval.item= string(l.val)
   997  			return secondMicrosecond
   998  {select}		return selectKwd
   999  
  1000  {set}			return set
  1001  {share}			return share
  1002  {show}			return show
  1003  {subdate}		lval.item = string(l.val)
  1004  			return subDate
  1005  {strcmp}		lval.item = string(l.val)
  1006  			return strcmp
  1007  {substr}		lval.item = string(l.val)
  1008  			return substring
  1009  {substring}		lval.item = string(l.val)
  1010  			return substring
  1011  {substring_index}	lval.item = string(l.val)
  1012  			return substringIndex
  1013  {sum}			lval.item = string(l.val)
  1014  			return sum
  1015  {sysdate}		lval.item = string(l.val)
  1016  			return sysDate
  1017  {table}			return tableKwd
  1018  {tables}		lval.item = string(l.val)
  1019  			return tables
  1020  {then}			return then
  1021  {to}			return to
  1022  {trailing}		return trailing
  1023  {transaction}		lval.item = string(l.val)
  1024  			return transaction
  1025  {triggers}		lval.item = string(l.val)
  1026  			return triggers
  1027  {trim}			lval.item = string(l.val)
  1028  			return trim
  1029  {truncate}		lval.item = string(l.val)
  1030  			return truncate
  1031  {uncommitted}		lval.item = string(l.val)
  1032  			return uncommitted
  1033  {union}			return union
  1034  {unique}		return unique
  1035  {unknown}		lval.item = string(l.val)
  1036  			return unknown
  1037  {nullif}		lval.item = string(l.val)
  1038  			return nullIf
  1039  {unlock}		return unlock
  1040  {update}		return update
  1041  {upper}			lval.item = string(l.val)
  1042  			return upper
  1043  {ucase}			lval.item = string(l.val)
  1044  			return ucase
  1045  {use}			return use
  1046  {user}			lval.item = string(l.val)
  1047  			return user
  1048  {using}			return using
  1049  {value}			lval.item = string(l.val)
  1050  			return value
  1051  {values}		return values
  1052  {variables}		lval.item = string(l.val)
  1053  			return variables
  1054  {version}		lval.item = string(l.val)
  1055  			return version
  1056  {warnings}		lval.item = string(l.val)
  1057  			return warnings
  1058  {week}			lval.item = string(l.val)
  1059  			return week
  1060  {weekday}		lval.item = string(l.val)
  1061  			return weekday
  1062  {weekofyear}		lval.item = string(l.val)
  1063  			return weekofyear
  1064  {when}			return when
  1065  {where}			return where
  1066  {write}			return write
  1067  {xor}			return xor
  1068  {yearweek}		lval.item = string(l.val)
  1069  			return yearweek
  1070  {year_month}		lval.item = string(l.val)
  1071  			return yearMonth
  1072  
  1073  {restrict}		lval.item = string(l.val)
  1074  			return restrict
  1075  {cascade}		lval.item = string(l.val)
  1076  			return cascade
  1077  {no}			lval.item = string(l.val)
  1078  			return no
  1079  {action}		lval.item = string(l.val)
  1080  			return action
  1081  
  1082  {signed}		lval.item = string(l.val)
  1083  			return signed
  1084  {unsigned}		return unsigned
  1085  {zerofill}		return zerofill
  1086  
  1087  {null}			lval.item = nil
  1088  			return null
  1089  
  1090  {false}			return falseKwd
  1091  
  1092  {true}			return trueKwd
  1093  
  1094  {calc_found_rows}	lval.item = string(l.val)
  1095  			return calcFoundRows
  1096  {sql_cache}		lval.item = string(l.val)
  1097  			return sqlCache
  1098  {sql_no_cache}		lval.item = string(l.val)
  1099  			return sqlNoCache
  1100  
  1101  {current_ts}		lval.item = string(l.val)
  1102  			return currentTs
  1103  {localtime}		return localTime
  1104  {localts}		return localTs
  1105  {now}			lval.item = string(l.val)
  1106  			return now
  1107  
  1108  {bit}			lval.item = string(l.val) 
  1109  			return bitType
  1110  
  1111  {tiny}			lval.item = string(l.val) 
  1112  			return tinyIntType
  1113  
  1114  {tinyint}		lval.item = string(l.val) 
  1115  			return tinyIntType
  1116  
  1117  {smallint}		lval.item = string(l.val) 
  1118  			return smallIntType
  1119  
  1120  {mediumint}		lval.item = string(l.val)
  1121  			return mediumIntType
  1122  
  1123  {bigint}		lval.item = string(l.val)
  1124  			return bigIntType
  1125  
  1126  {decimal}		lval.item = string(l.val)
  1127  			return decimalType
  1128  
  1129  {numeric}		lval.item = string(l.val)
  1130  			return numericType
  1131  
  1132  {float}			lval.item = string(l.val)
  1133  			return floatType
  1134  
  1135  {double}		lval.item = string(l.val)
  1136  			return doubleType
  1137  
  1138  {precision}		lval.item = string(l.val)
  1139  			return precisionType
  1140  
  1141  {real}			lval.item = string(l.val)
  1142  			return realType
  1143  
  1144  {date}			lval.item = string(l.val)
  1145  			return dateType
  1146  
  1147  {time}			lval.item = string(l.val) 
  1148  			return timeType
  1149  
  1150  {timestamp}		lval.item = string(l.val)
  1151  			return timestampType
  1152  
  1153  {datetime}		lval.item = string(l.val)
  1154  			return datetimeType
  1155  
  1156  {year}			lval.item = string(l.val)
  1157  			return yearType
  1158  
  1159  {char}			lval.item = string(l.val)
  1160  			return charType
  1161  
  1162  {varchar}		lval.item = string(l.val)
  1163  			return varcharType
  1164  
  1165  {binary}		lval.item = string(l.val)
  1166  			return binaryType
  1167  
  1168  {varbinary}		lval.item = string(l.val)
  1169  			return varbinaryType
  1170  
  1171  {tinyblob}		lval.item = string(l.val)
  1172  			return tinyblobType
  1173  
  1174  {blob}			lval.item = string(l.val)
  1175  			return blobType
  1176  
  1177  {mediumblob}		lval.item = string(l.val)
  1178  			return mediumblobType
  1179  
  1180  {longblob}		lval.item = string(l.val)
  1181  			return longblobType
  1182  
  1183  {tinytext}		lval.item = string(l.val)
  1184  			return tinytextType
  1185  
  1186  {mediumtext}		lval.item = string(l.val)
  1187  			return mediumtextType
  1188  
  1189  {text}			lval.item = string(l.val)
  1190  			return textType
  1191  
  1192  {longtext}		lval.item = string(l.val)
  1193  			return longtextType
  1194  
  1195  {bool}			lval.item = string(l.val) 
  1196  			return boolType
  1197  
  1198  {boolean}		lval.item = string(l.val)
  1199  			return booleanType
  1200  
  1201  {byte}			lval.item = string(l.val) 
  1202  			return byteType
  1203  
  1204  {int}			lval.item = string(l.val)
  1205  			return intType
  1206  
  1207  {integer}		lval.item = string(l.val)
  1208  			return integerType
  1209  
  1210  {ident}			lval.item = string(l.val)
  1211  			return l.handleIdent(lval)
  1212  
  1213  .			return c0
  1214  
  1215  %%
  1216  			return int(unicode.ReplacementChar)
  1217  }
  1218  
  1219  func (l *lexer) npos() (line, col int) {
  1220  	if line, col = l.nline, l.ncol; col == 0 {
  1221  		line--
  1222  		col = l.lcol+1
  1223  	}
  1224  	return
  1225  } 
  1226  
  1227  func (l *lexer) str(lval *yySymType, pref string) int {
  1228  	l.sc = 0
  1229  	// TODO: performance issue.
  1230  	s := string(l.stringLit)
  1231  	l.stringLit = l.stringLit[0:0]
  1232  	if pref == "'" {
  1233  		s = strings.Replace(s, "\\'", "'", -1)    
  1234  		s = strings.TrimSuffix(s, "'") + "\""
  1235  		pref = "\""
  1236  	} 
  1237  	v := stringutil.RemoveUselessBackslash(pref+s)
  1238  	v, err := strconv.Unquote(v)
  1239  	if err != nil {
  1240  		v = strings.TrimSuffix(s, pref)
  1241  	}
  1242  	lval.item = v
  1243  	return stringLit
  1244  }
  1245  
  1246  func (l *lexer) trimIdent(idt string) string {
  1247  	idt = strings.TrimPrefix(idt, "`")    
  1248  	idt = strings.TrimSuffix(idt, "`")    
  1249  	return idt
  1250  }
  1251  
  1252  func (l *lexer) int(lval *yySymType) int {
  1253  	n, err := strconv.ParseUint(string(l.val), 0, 64)
  1254  	if err != nil {
  1255  		l.errf("integer literal: %v", err)
  1256  		return int(unicode.ReplacementChar)
  1257  	}
  1258  
  1259  	switch {
  1260  	case n < math.MaxInt64:
  1261  		lval.item = int64(n)
  1262  	default:
  1263  		lval.item = uint64(n)
  1264  	}
  1265  	return intLit
  1266  }
  1267  
  1268  func (l *lexer) float(lval *yySymType) int {
  1269  	n, err := strconv.ParseFloat(string(l.val), 64)
  1270  	if err != nil {
  1271  		l.errf("float literal: %v", err)
  1272  		return int(unicode.ReplacementChar)
  1273  	}
  1274  
  1275  	lval.item = float64(n)
  1276  	return floatLit
  1277  }
  1278  
  1279  // https://dev.mysql.com/doc/refman/5.7/en/hexadecimal-literals.html
  1280  func (l *lexer) hex(lval *yySymType) int {
  1281  	s := string(l.val)
  1282  	h, err := mysql.ParseHex(s)
  1283  	if err != nil {
  1284  		// If parse hexadecimal literal to numerical value error, we should treat it as a string.
  1285  		hexStr, err1 := mysql.ParseHexStr(s)
  1286  		if err1 != nil {
  1287  			l.errf("hex literal: %v", err)
  1288  			return int(unicode.ReplacementChar)
  1289  		}
  1290  		lval.item = hexStr
  1291  		return stringLit 
  1292  	}
  1293  	lval.item = h
  1294  	return hexLit
  1295  }
  1296  
  1297  // https://dev.mysql.com/doc/refman/5.7/en/bit-type.html
  1298  func (l *lexer) bit(lval *yySymType) int {
  1299  	s := string(l.val)
  1300  	b, err := mysql.ParseBit(s, -1)
  1301  	if err != nil {
  1302  		l.errf("bit literal: %v", err)
  1303  		return int(unicode.ReplacementChar)
  1304  	}
  1305  	lval.item = b
  1306  	return bitLit
  1307  }
  1308  
  1309  func (l *lexer) handleIdent(lval *yySymType) int {
  1310  	s := lval.item.(string)
  1311  	// A character string literal may have an optional character set introducer and COLLATE clause:
  1312  	// [_charset_name]'string' [COLLATE collation_name]
  1313  	// See: https://dev.mysql.com/doc/refman/5.7/en/charset-literal.html
  1314  	if !strings.HasPrefix(s, "_") {
  1315  		return identifier	
  1316  	}
  1317  	cs, _, err := charset.GetCharsetInfo(s[1:])
  1318  	if err != nil {
  1319  		return identifier	
  1320  	}
  1321  	lval.item = cs
  1322  	return underscoreCS
  1323  }