001// lexical analyzer  for GSQLParser component java version
002
003/****************************************************}
004{   Lexical analizer for GSQLParser component java version    }
005{   Copyright (c) 2004-2018 by Gudu software              }
006{****************************************************/
007
008package gudusoft.gsqlparser;
009
010import java.util.HashMap;
011import java.io.InputStreamReader;
012
013import java.util.Locale;
014import java.io.BufferedReader;
015import java.io.IOException;
016
017public class TLexerClickhouse extends TCustomLexer{
018
019    static int yynmarks = 0  ;
020    static int yynmatches ;
021    static int yyntrans   ;
022    static int yynstates  ;
023    static int[]  yyk,yym ; // 1 based
024    static int[]  yytint;  // 1 based
025    static TYytRec[] yyt ;  // 1 based
026    static int[]  yykl,yykh,yyml,yymh,yytl,yyth ; // 0 based
027    private  static  String[] keywordlist;
028    static String   table_file;
029    static HashMap<String, Integer> keywordValueList;
030    static HashMap<Integer, Integer> keywordTypeList;    
031    HashMap clickhouseCharsets;
032        static int[][] yystateTable;
033
034    static {
035              keywordValueList = new HashMap<String, Integer>();
036              keywordTypeList = new HashMap<Integer, Integer>();              
037          table_file = "/gudusoft/gsqlparser/parser/clickhouse/clickhouse_lex_table.txt";
038                  if (TBaseType.enterprise_edition||TBaseType.clickhouse_edition){
039                inittable();
040          }
041    }
042
043
044    public TLexerClickhouse(){
045          super();
046          dbvendor = EDbVendor.dbvclickhouse;
047          sourcetokens = new TSourceTokenList();
048          clickhouseCharsets  = new HashMap();
049    }
050
051
052    public TSourceTokenList sourcetokens;
053
054    boolean isClickhouseCharset(String astr){
055        boolean ret = false;
056        if (clickhouseCharsets.size() == 0){
057            clickhouseCharsets.put("big5","1");
058            clickhouseCharsets.put("dec8","1");
059            clickhouseCharsets.put("cp850","1");
060            clickhouseCharsets.put("hp8","1");
061            clickhouseCharsets.put("koi8r","1");
062            clickhouseCharsets.put("latin1","1");
063            clickhouseCharsets.put("latin2","1");
064            clickhouseCharsets.put("swe7","1");
065            clickhouseCharsets.put("ascii","1");
066            clickhouseCharsets.put("ujis","1");
067            clickhouseCharsets.put("sjis","1");
068            clickhouseCharsets.put("hebrew","1");
069            clickhouseCharsets.put("tis620","1");
070            clickhouseCharsets.put("euckr","1");
071            clickhouseCharsets.put("koi8u","1");
072            clickhouseCharsets.put("gb2312","1");
073            clickhouseCharsets.put("greek","1");
074            clickhouseCharsets.put("cp1250","1");
075            clickhouseCharsets.put("gbk","1");
076            clickhouseCharsets.put("latin5","1");
077            clickhouseCharsets.put("armscii","1");
078            clickhouseCharsets.put("utf8","1");
079                        clickhouseCharsets.put("utf8mb3","1");
080            clickhouseCharsets.put("ucs2","1");
081            clickhouseCharsets.put("cp866","1");
082            clickhouseCharsets.put("keybcs2","1");
083            clickhouseCharsets.put("macce","1");
084            clickhouseCharsets.put("macroma","1");
085            clickhouseCharsets.put("cp852","1");
086            clickhouseCharsets.put("latin7","1");
087            clickhouseCharsets.put("utf8mb4","1");
088            clickhouseCharsets.put("cp1251","1");
089            clickhouseCharsets.put("utf16","1");
090            clickhouseCharsets.put("cp1256","1");
091            clickhouseCharsets.put("cp1257","1");
092            clickhouseCharsets.put("utf32","1");
093            clickhouseCharsets.put("binary","1");
094            clickhouseCharsets.put("geostd8","1");
095            clickhouseCharsets.put("cp932","1");
096            clickhouseCharsets.put("eucjpms","1");
097        }
098
099        try{
100            ret =   (Integer.parseInt( (String) clickhouseCharsets.get(astr.toLowerCase()) ) ) == 1 ;
101        }catch(NumberFormatException e){
102            ret = false;
103        }
104
105        return ret;
106    }
107    
108public boolean canBeColumnName(int tokencode){
109    //http://blog.csdn.net/superbeck/article/details/5387476
110    boolean ret = false;
111    int modifiers = keyword_type_identifier | keyword_type_column ;
112    
113    Integer s = keywordTypeList.get(tokencode);
114    if (s != null){
115        int modifier = s;
116        ret = (modifiers & modifier) == modifier;
117    }
118
119    return ret;
120}
121
122public  int iskeyword(String str){
123       int ret = -1;
124       
125       Integer s = keywordValueList.get(str.toUpperCase(Locale.ENGLISH));
126       if( s != null){
127                                        ret = s;                 
128       }
129       return ret;// -1 means not a keyword
130    }
131
132    public static EKeywordType getKeywordType(String keyword){
133        return TCustomLexer.getKeywordType(keyword,keywordValueList,keywordTypeList);
134    }    
135        
136    public int getkeywordvalue(String keyword){
137        int ret = 0;
138        Integer s = keywordValueList.get(keyword.toUpperCase(Locale.ENGLISH));
139        if( s != null){
140            ret = s;
141        }
142        return ret;// 0 means not a keyword
143    }
144
145
146    int issystemvariable(String str){
147        return -1;// -1 means not a system variable
148    }
149        
150    static void yystateLookupConfigure() {
151        int yystates = yytl.length;
152        yystateTable = new int[257][yystates];
153
154        // initialize to empty
155        for(int i = 0; i < yystates; i++) {
156            for (int j = 0; j < 257; j++)
157                yystateTable[j][i] = -1;
158        }
159
160        for(int i = 0; i < yystates; i++) {
161            int low = yytl[i];
162            int high = yyth[i];
163            for (int j = low; j <= high; j++) {
164                for (char c: yyt[j].cc) {
165                    yystateTable[c][i] = j;
166                }
167            }
168        }
169    }   
170
171    int yylex(){
172          int yyn;
173           while (true) { // top level while
174              yynew();
175              while (true){  //scan
176                 for(yyn = yykl[yystate]; yyn <= yykh[yystate]; yyn++){
177                     yymark(yyk[yyn]);
178                 }
179
180                 for(yyn=yymh[yystate]; yyn>= yyml[yystate]; yyn--){
181                    yymatch(yym[yyn]);
182                 }
183
184                 if(yytl[yystate] > yyth[yystate]){
185                     break;
186                 }
187
188                 yyscan();
189                 //yyn = yytl[yystate];
190                 totablechar();
191                                 
192                 //while( (yyn <= yyth[yystate]) && (!(charinarray(yytablechar,yyt[yyn].cc))) ){
193                 //  yyn++;
194                 // }
195                 //if (yyn > yyth[yystate]){
196                 //    break;
197                 //}
198
199                 yyn = yystateTable[yytablechar][yystate];
200                 if (yyn == -1)
201                     break;
202                                         
203                 yystate = yyt[yyn].s;
204              } //scan
205
206              while (true){ //action
207                int yyrule;
208                if ( (yyrule = yyfind()) != -1 ){
209                   yyaction(yyrule);
210                   if (yyreject){
211                       continue;
212                   }
213                }else if( (!yydefault() ) && (yywrap()) ){
214                   yyclear();
215                   returni(0);
216                }
217                break;
218              }
219
220              if (!yydone) {
221                  continue;
222              }
223              break;
224            } // top level while
225
226           return yyretval;
227        }
228
229    static void inittable(){
230                
231                //if (yynmarks > 0) return; //init table already
232
233        String line;
234        boolean inyyk=false,inyym=false,inyykl=false,inyykh=false,inyyml=false,inyymh=false,inyytl=false,inyyth=false,inyytint=false,inyyt=false,inkeyword=false;
235        int yyk_count=0,yym_count=0,yykl_count=0,yykh_count=0,yyml_count=0,yymh_count=0,yytl_count=0,yyth_count=0,yytint_count=0,yyt_count=0;
236        int c=0;
237        keywordValueList.clear();
238        keywordTypeList.clear();
239        
240        BufferedReader br = new BufferedReader(new InputStreamReader(TLexerClickhouse.class.getResourceAsStream(table_file)));
241
242            try{
243                while( (line = br.readLine()) != null){
244                          if (line.trim().startsWith("yynmarks=")){
245                             String[] ss = line.split("[=;]");
246                              yynmarks=Integer.parseInt(ss[1].trim());
247                              yyk = new int[yynmarks+1];
248                          }else if (line.trim().startsWith("yynmatches=")){
249                              String[] ss = line.split("[=;]");
250                               yynmatches=Integer.parseInt(ss[1].trim());
251                               yym = new int[yynmatches+1];
252                          }else if (line.trim().startsWith("yyntrans=")){
253                              String[] ss = line.split("[=;]");
254                               yyntrans=Integer.parseInt(ss[1].trim());
255                               yytint = new int[yyntrans+1];
256                               yyt = new TYytRec[yyntrans+1];
257                          }else if (line.trim().startsWith("yynstates=")){
258                              String[] ss = line.split("[=;]");
259                               yynstates=Integer.parseInt(ss[1].trim());
260                               yykl = new int[yynstates];
261                               yykh = new int[yynstates];
262                              yyml = new int[yynstates];
263                              yymh = new int[yynstates];
264                              yytl = new int[yynstates];
265                              yyth = new int[yynstates];
266                          }else if (line.trim().startsWith("<end>")){
267                              if (inyyk){
268                                  inyyk = false;
269                                 if (yynmarks+1 != yyk_count ){
270                                    System.out.println("required1:"+(yynmarks)+" actually:"+(yyk_count-1));
271                                 }
272                              }
273                              else if(inyym){
274                                     inyym = false;
275                                    if (yynmatches+1 != yym_count ){
276                                       System.out.println("required2:"+(yynmatches)+" actually:"+(yym_count-1));
277                                    }
278                              }
279                              else if(inyykl){
280                                     inyykl = false;
281                                    if (yynstates != yykl_count ){
282                                       System.out.println("required3:"+(yynstates)+" actually:"+(yykl_count));
283                                    }
284                              }
285                              else if(inyykh){
286                                     inyykh = false;
287                                    if (yynstates != yykh_count ){
288                                       System.out.println("required4:"+(yynstates)+" actually:"+(yykh_count));
289                                    }
290                              }
291                              else if(inyyml){
292                                     inyyml = false;
293                                    if (yynstates != yyml_count ){
294                                       System.out.println("required5:"+(yynstates)+" actually:"+(yyml_count));
295                                    }
296                              }
297                              else if(inyymh){
298                                     inyymh = false;
299                                    if (yynstates != yymh_count ){
300                                       System.out.println("required:"+(yynstates)+" actually:"+(yymh_count));
301                                    }
302                              }
303                              else if(inyytl){
304                                     inyytl = false;
305                                    if (yynstates != yytl_count ){
306                                       System.out.println("required6:"+(yynstates)+" actually:"+(yytl_count));
307                                    }
308                              }
309                              else if(inyyth){
310                                     inyyth = false;
311                                    if (yynstates != yyth_count ){
312                                       System.out.println("required7:"+(yynstates)+" actually:"+(yyth_count));
313                                    }
314                              }
315                              else if(inyytint){
316                                     inyytint = false;
317                                    if (yyntrans + 1 != yytint_count ){
318                                       System.out.println("required8:"+(yyntrans)+" actually:"+(yytint_count-1));
319                                    }
320                              }
321                              else if(inyyt){
322                                     inyyt = false;
323                                    if (yyntrans+1 != yyt_count ){
324                                       System.out.println("required9:"+(yyntrans)+" actually:"+(yyt_count-1));
325                                    }
326                              }
327                              else if(inkeyword){
328                                     inkeyword = false;
329                              }
330                          }else if(line.trim().startsWith("yyk =")){
331                             inyyk = true; 
332                          }else if(line.trim().startsWith("yym =")){
333                             inyym = true;
334                          }else if(line.trim().startsWith("yykl =")){
335                             inyykl = true;
336                          }else if(line.trim().startsWith("yykh =")){
337                             inyykh = true;
338                          }else if(line.trim().startsWith("yyml =")){
339                             inyyml = true;
340                          }else if(line.trim().startsWith("yymh =")){
341                             inyymh = true;
342                          }else if(line.trim().startsWith("yytl =")){
343                             inyytl = true;
344                          }else if(line.trim().startsWith("yyth =")){
345                             inyyth = true;
346                          }else if(line.trim().startsWith("yytint =")){
347                             inyytint = true;
348                          }else if(line.trim().startsWith("yyt =")){
349                             inyyt = true;
350                        }else if(line.trim().startsWith("keywordsvalue =")){
351                           inkeyword = true;
352                        }else if(inyyk){
353                             String[] ss = line.split("[,]");
354                               for(int j=0;j<ss.length;j++){
355                                   // System.out.println(ss[j].trim());
356                                 yyk[yyk_count++] = Integer.parseInt(ss[j].trim());
357                               }
358                          }else if(inyym){
359                               String[] ss = line.split("[,]");
360                                 for(int j=0;j<ss.length;j++){
361                                     // System.out.println(ss[j].trim());
362                                   yym[yym_count++] = Integer.parseInt(ss[j].trim());
363                                 }
364                          }else if(inyykl){
365                               String[] ss = line.split("[,]");
366                                 for(int j=0;j<ss.length;j++){
367                                    //  System.out.println(ss[j].trim());
368                                   yykl[yykl_count++] = Integer.parseInt(ss[j].trim());
369                                 }
370                          }else if(inyykh){
371                               String[] ss = line.split("[,]");
372                                 for(int j=0;j<ss.length;j++){
373                                     // System.out.println(ss[j].trim());
374                                   yykh[yykh_count++] = Integer.parseInt(ss[j].trim());
375                                 }
376                          }else if(inyyml){
377                               String[] ss = line.split("[,]");
378                                 for(int j=0;j<ss.length;j++){
379                                     // System.out.println(ss[j].trim());
380                                   yyml[yyml_count++] = Integer.parseInt(ss[j].trim());
381                                 }
382                          }else if(inyymh){
383                               String[] ss = line.split("[,]");
384                                 for(int j=0;j<ss.length;j++){
385                                     // System.out.println(ss[j].trim());
386                                   yymh[yymh_count++] = Integer.parseInt(ss[j].trim());
387                                 }
388                          }else if(inyytl){
389                               String[] ss = line.split("[,]");
390                                 for(int j=0;j<ss.length;j++){
391                                     // System.out.println(ss[j].trim());
392                                   yytl[yytl_count++] = Integer.parseInt(ss[j].trim());
393                                 }
394                          }else if(inyyth){
395                               String[] ss = line.split("[,]");
396                                 for(int j=0;j<ss.length;j++){
397                                     // System.out.println(ss[j].trim());
398                                   yyth[yyth_count++] = Integer.parseInt(ss[j].trim());
399                                 }
400                          }else if(inyytint){
401                               String[] ss = line.split("[,]");
402                                 for(int j=0;j<ss.length;j++){
403                                     // System.out.println(ss[j].trim());
404                                   yytint[yytint_count++] = Integer.parseInt(ss[j].trim());
405                                 }
406                          }else if(inyyt){
407                                //System.out.println(line.trim());
408
409                              c = 0;
410                              String[] st = line.trim().split(",,");
411                              char[] tmp = new char[st.length];
412                              for(int i=0;i<st.length;i++){
413
414                                  if(st[i].startsWith("\'")) {
415                                      if(st[i].length() == 3){  // 'a'
416                                          tmp[c++] = st[i].charAt(1);
417                                      }else if(st[i].length() == 4) { // '\\'
418                                          tmp[c++] = st[i].charAt(2);
419                                      }else{
420                                         System.out.println(" read yytstr error, error string is "+st[i]+ "line: "+ yyt_count);
421                                      }
422                                  }else{
423                                      try{
424                                           tmp[c++] = (char)Integer.parseInt(st[i]);   // char in number like 32 that represent space
425                                          } catch (NumberFormatException nfe) {
426                                             System.out.println("NumberFormatException: " + nfe.getMessage());
427                                          }
428                                  }
429                              } //while hasmoreTokens
430
431                          //yyt[lineno] = new YYTrec(tmp,yytint[lineno]);
432                              yyt[yyt_count] = new TYytRec(tmp,yytint[yyt_count]);
433                              yyt_count++;
434
435                          }else if(inkeyword){
436                              String[] ss =line.split("[=]");
437
438                              int val1 = -1;
439                              int val2 = -1;
440                              try {
441                                  val1 = Integer.parseInt(ss[1]);
442                                  val2 = Integer.parseInt(ss[2]);
443                              }
444                              catch (NumberFormatException nfe) {
445                                  System.out.println("NumberFormatException: " + nfe.getMessage());
446                              }
447                              keywordValueList.put(ss[0].toUpperCase(),val1);
448                              keywordTypeList.put(val1,val2);
449
450                             }
451                }
452                }catch(IOException e){
453                  System.out.println(e.toString());
454                }
455                                
456                                yystateLookupConfigure();
457
458    }
459
460
461
462    void yyaction(int yyruleno){
463
464
465      int ic;
466      char[] tmparray = {'=','+','-','*','/','>','<'};
467
468      yylvalstr = getyytext();
469  /* actions: */
470  switch(yyruleno){
471  case 1:
472                
473        {
474                    addlit(yylvalstr,yytextlen);
475                    if (xcdepth <= 0)
476                       {
477                        start(init);
478                        yylvalstr = litbufdup();
479                        returni(cmtslashstar);
480                       }
481                    else
482                       xcdepth--;
483
484                  break;
485        }
486
487
488  case 2:
489                
490                  {
491                                                // xcdepth++;
492                                                yyless(2);
493                                                addlit(yylvalstr,yytextlen);
494                                                break;
495                   }
496
497  case 3:
498                        
499                  {
500
501                      if (getyysstate() == xq)
502                      {
503                          nchars = yytextlen;
504                          addlit(yylvalstr, yytextlen-1);
505                          yyless(nchars-1);
506                          return;//exit;
507                      }
508
509                      xcdepth = 0;
510                      start(xc);
511                      startlit();
512                      yyless(2);
513                      addlit(yylvalstr,yytextlen);
514
515                  break;
516                  }
517
518  case 4:
519                
520                  {
521                    addlit(yylvalstr,yytextlen);
522                    break;
523                  }
524
525  case 5:
526                
527                  {
528                      addlitchar(yylvalstr.charAt(0));
529                      break;
530                  }
531
532
533  case 6:
534            
535        {
536                                        //token_start := yylvalStr;
537                                        if (getyysstate() == xq)
538            {
539                                                
540                                              nchars = yytextlen;
541                                              addlit(yylvalstr, yytextlen-1);
542                yyless(nchars-1);
543                                              return;//exit;    
544                                           }
545            start(xq);
546            startlit();
547                                          addlit(yylvalstr,yytextlen);
548                break;
549        }
550
551
552  case 7:
553                       
554        {
555                                        start(init);
556                                        addlit(yylvalstr, yytextlen);
557                                        yylvalstr = litbufdup();
558                                        returni(ident);
559                break;
560        }
561
562  case 8:
563                        
564        {
565          if ((getyysstate() == xd)||(getyysstate() == xq))
566          {
567              addlit(yylvalstr, 1);
568              yyless(1);
569              return;//exit;
570          }     
571                //token_start := yylvalStr;
572                start(xbacktick);
573                startlit();
574                addlit(yylvalstr, yytextlen);
575                break;
576        }
577
578
579  case 9:
580                       
581        {
582                addlit(yylvalstr, yytextlen);
583                break;
584  }
585
586  case 10:
587                       
588        {
589    addlit(yylvalstr, yytextlen);
590                break;
591   }
592
593
594  case 11:
595                
596                  {
597                      start(init);
598                      addlit(yylvalstr, yytextlen);
599                      yylvalstr = litbufdup();
600                      returni(sconst);
601                      break;
602                  }
603
604  case 12:
605                
606                    {
607                      addlit(yylvalstr,yytextlen);
608                      break;
609                    }
610        
611  case 13:
612                        
613                {
614
615          if (
616              (getyysstate() == xd)
617                                                )
618          {
619              addlit(yylvalstr, 1);
620              yyless(1);
621              return;//exit;
622          }
623          
624                        start(xq);
625                        startlit();
626                        addlit(yylvalstr, yytextlen);
627                        
628                        break;
629                }
630
631
632  case 14:
633                
634                  {
635                      addlit(yylvalstr, yytextlen);
636                      break;
637                  }
638
639  case 15:
640                
641                  {
642                    dummych1 = get_char();
643                    unget_char(dummych1);
644                      while (dummych1 == '\\'){
645                          dummych1 = get_char();
646                          dummych2 = get_char();
647                          addlit(yylvalstr+dummych1+dummych2, yytextlen+2);
648                          yylvalstr = "";
649                          yytextlen = 0;
650    
651                          dummych1 = get_char();
652                          unget_char(dummych1);
653                      }
654                                          
655                    if (dummych1 == (char)10)
656                      {
657                        if (insqlpluscmd){
658                          nchars = yytextlen;
659                          if(yylvalstr.charAt(nchars-1) == (char)13){
660                              yyless(nchars - 1);
661                              yylvalstr = yylvalstr.substring(0,nchars);
662                          }
663                            start(init);
664                            addlit(yylvalstr, nchars-1);
665                            yylvalstr = litbufdup();
666                            returni(sconst); //in sqlplus command, characters between ' and return is treated as a string
667
668                        }else{
669                        dummych1 = get_char();
670                        addlit(yylvalstr+dummych1, yytextlen+1);
671                        }
672                      } 
673                        else
674                            { addlit(yylvalstr, yytextlen);}
675
676                  break;
677                 }
678                                 
679  case 16:
680                 
681        {
682                addlit(yylvalstr, yytextlen);
683                break;
684        }
685
686
687  case 17:
688                
689                  {
690                      start(init);
691                      addlit(yylvalstr, yytextlen);
692                      if ((literallen == 0) && (!insqlpluscmd))
693                        {returni (error);}
694                     // if (literallen >= namedatalen)
695                     // {
696                     //    setlengthofliteralbuf(namedatalen);
697                     //    literallen = namedatalen;
698                     // }
699                      yylvalstr = litbufdup();
700                      returni (ident);
701
702                      break;
703                  }
704
705  case 18:
706               
707                  {
708                      addlit(yylvalstr, yytextlen);
709                      break;
710                  }
711
712  case 19:
713                        
714                  {
715                      start(xd);
716                      startlit();
717                      addlit(yylvalstr, yytextlen);
718                      break;
719                  }
720  case 20:
721                
722                  {
723                    dummych1 = get_char();
724                    unget_char(dummych1);
725                    if (dummych1 == (char)10)
726                      {
727                          if (insqlpluscmd){
728                            nchars = yytextlen;
729                            if(yylvalstr.charAt(nchars-1) == (char)13){
730                                yyless(nchars - 1);
731                                yylvalstr = yylvalstr.substring(0,nchars);
732                            }
733                              start(init);
734                              addlit(yylvalstr, nchars-1);
735                              yylvalstr = litbufdup();
736                              returni(sconst); //in sqlplus command, characters between ' and return is treated as a string
737
738                          }else{
739                          dummych1 = get_char();
740                          addlit(yylvalstr+dummych1, yytextlen+1);
741                          }
742
743                      } else
744                        addlit(yylvalstr, yytextlen);
745
746                  break;
747                  }
748
749
750  case 21:
751                              
752          {
753              dummych1 = get_char();
754              unget_char(dummych1);
755              if (dummych1 == ']')
756                  {
757                      dummych1 = get_char();
758                      addlit(yylvalstr+dummych1, yytextlen+1);
759                  }
760              else
761                  {
762                      start(init);
763                      addlit(yylvalstr, yytextlen);
764                      if (literallen == 0) returni (error);
765                      if (literallen >= namedatalen)
766                          {
767                              setlengthofliteralbuf(namedatalen);
768                              literallen = namedatalen;
769                          }
770                      yylvalstr = litbufdup();
771                      returni (ident);
772                  }
773
774          break;
775          }
776
777
778
779  case 22:
780                
781          {
782              /* ClickHouse does not use bracket-quoted identifiers;
783                 return [ as a character token for array literals and subscripts */
784              returnc(lexer_charAt(yylvalstr,0));
785              break;
786          }
787          
788  case 23:
789                              
790          {
791              dummych1 = get_char();
792              unget_char(dummych1);
793              if (dummych1 == (char)10)
794              {
795                  dummych1 = get_char();
796                  addlit(yylvalstr+dummych1, yytextlen+1);
797              }
798              else
799                  addlit(yylvalstr, yytextlen);
800
801          break;
802          }
803
804  case 24:
805          
806          {
807            returni(lexnewline);
808            break;
809          }
810
811  case 25:
812        
813          {
814              returni(lexspace);
815              break;
816          }
817
818  case 26:
819                
820          {
821          if ((getyysstate() == xq)
822              || (getyysstate() == xd)
823              || (getyysstate() == xc)
824              || (getyysstate() == xdbracket)
825              || (getyysstate() == xbacktick)
826              )
827          {
828              addlit(yylvalstr, 1);
829              yyless(1);
830              return;//exit;
831          }
832           
833           if ((yytextlen > 2)&&(yylvalstr.charAt(0) != '#')){
834             if (yylvalstr.charAt(2) != ' '){
835               // there must be a space after --, otherwise, it's not a line comment
836                yyless(1);
837                returnc(lexer_charAt(yylvalstr,0));  
838                break;           
839             }
840           }
841
842          returni(cmtdoublehyphen);
843          break;
844          }
845
846  case 27:
847                  
848          {
849              if (yylvalstr.equalsIgnoreCase(dolqstart))
850              {
851                  start(init);
852                  addlit(yylvalstr,yytextlen);
853                  yylvalstr = litbufdup();
854                  returni(sconst);
855              }
856              else
857              {
858                  addlit(yylvalstr, yytextlen-1);
859                  yyless(yytextlen-1);
860              }
861          break;
862          }
863
864  case 28:
865           
866          {
867              if ((getyysstate() == xq) || (getyysstate() == xd)
868                  || (getyysstate() == xdbracket) || (getyysstate() == xbacktick)
869                  || (getyysstate() == xc)) {
870                  addlit(yylvalstr, yytextlen);
871              } else {
872                  start(xdolq_clickhouse);
873                  startlit();
874                  dolqstart = yylvalstr;
875                  addlit(yylvalstr,yytextlen);
876              }
877          break;
878          }
879
880  case 29:
881                   
882          {
883              addlit(yylvalstr,yytextlen);
884          break;
885          }
886
887  case 30:
888                   
889          {
890              addlit(yylvalstr,yytextlen);
891          break;
892          }
893
894  case 31:
895        
896          {
897              addlitchar(yylvalstr.charAt(0));
898          break;
899          }
900
901  case 32:
902        
903          {
904               returnc(lexer_charAt(yylvalstr,0));
905               break;
906          }
907
908
909  case 33:
910          
911          {
912            returni(typecast);
913            break;
914          }
915
916  case 34:
917                      
918          {
919            returni(cmpop);
920            break;
921          }
922
923  case 35:
924          
925                  {
926
927                  if (getyysstate() == xc)
928                     {
929                      slashstar = yylvalstr.indexOf("*/");
930                        if (slashstar >= 0)
931                          {
932                              start(init);
933                              addlit(yylvalstr,slashstar+2);
934                              yylvalstr = litbufdup();
935                              yyless(slashstar+2);
936                              returni(cmtslashstar);
937                          }
938                        else
939                          {
940                              addlit(yylvalstr,1);
941                              yyless(1);
942                          }
943                     }
944                  else
945                    {
946                      nchars = yytextlen;
947                      slashstar = yylvalstr.indexOf("/*");
948                      dashdash = yylvalstr.indexOf("--");
949                      if ((slashstar >= 0) && (dashdash >= 0))
950                        {
951                          //if both appear, take the first one
952                           if (slashstar > dashdash)
953                            {slashstar = dashdash;}
954                        }
955                      else
956                        {
957                          //   if slashstar=0 then slashstar := dashdash;
958                          // add (getyysstate <> xc) to avoid something like this */--,here */ should be handled instead of --
959                          if ((slashstar >= 0) && (getyysstate() != xc)) {
960                            nchars = slashstar;
961                            }
962                        }
963
964                      while ((nchars > 1)
965                              && ( (yylvalstr.charAt(nchars-1) == '+' )
966                                  || (yylvalstr.charAt(nchars-1) =='-'))
967                              && (getyysstate() != xc))
968                        {
969                          for (ic = nchars - 1; ic>=1; ic--)
970                          {
971                            if (isopchar(yylvalstr.charAt(ic-1)))  break;
972                          }
973                          if (ic >= 1) break;
974                          nchars--;
975                        }
976
977                      if (nchars < yytextlen)
978                        {
979                          //Strip the unwanted chars from the token
980                          yyless(nchars);
981                          yylvalstr = yylvalstr.substring(0,nchars);
982                        }
983
984                          ///*
985                          // * If what we have left is only one char, and it's
986                          // * one of the characters matching "self", then
987                          // * return it as a character token the same way
988                          // * that the "self" rule would have.
989                          // * make sure @ return as self char, by james wang
990                          // */
991                          if ((nchars == 1) && (isselfchar(yylvalstr.charAt(0)) || (yylvalstr.charAt(0) == '@')))
992                            {
993                              returnc(lexer_charAt(yylvalstr,0));
994                            }
995                          else if (
996                                      (nchars >= 2)
997                                          &&(
998                                               charinarray(yylvalstr.charAt(nchars-1-1), tmparray)
999                                               && ((yylvalstr.charAt(nchars-1) == ':'))
1000                                               )
1001                                   )
1002                              {
1003                                yyless(nchars-1);
1004                                 yylvalstr = yylvalstr.substring(0,nchars-1);
1005                                if (nchars == 2)
1006                                  returnc(lexer_charAt(yylvalstr,0));
1007                                else
1008                                  returni(op);
1009                              }
1010                            else if (
1011                                        (nchars >= 2)
1012                                            && (
1013                                                  charinarray(yylvalstr.charAt(nchars-1-1),tmparray)
1014                                                  && (yylvalstr.charAt(nchars-1) == '@')
1015                                                 )
1016                                       )
1017                                {
1018                                  yyless(nchars-1);
1019                                   yylvalstr = yylvalstr.substring(0,nchars-1);
1020                                  if (nchars == 2)
1021                                    returnc(lexer_charAt(yylvalstr,0));
1022                                  else
1023                                    returni(op);
1024                                }
1025                            else if ( (nchars >= 2) && (yylvalstr.charAt(0) == '~') )
1026                              {
1027                                      yyless(1);
1028                                     returnc(lexer_charAt(yylvalstr,0));
1029                              }
1030                            else if ( (nchars >= 2) && (yylvalstr.charAt(0) == '+') )
1031                              {
1032                                      yyless(1);
1033                                     returnc(lexer_charAt(yylvalstr,0));
1034                              }
1035                            else if ( (nchars >= 2) && (yylvalstr.charAt(0) == '?') )
1036                              {
1037                                      yyless(1);
1038                                     returnc(lexer_charAt(yylvalstr,0));
1039                              }
1040                            else if ( (nchars >= 2) && (yylvalstr.charAt(0) == '=')&& ((yylvalstr.charAt(1) == '@')||(yylvalstr.charAt(1) == '.')) )
1041                              {
1042                                      yyless(1);
1043                                     returnc(lexer_charAt(yylvalstr,0));
1044                              }
1045                            else if ( (nchars == 2) && (yylvalstr.charAt(0) == '.') && (yylvalstr.charAt(1) == '*'))
1046                              {
1047                                      yyless(1);
1048                                     returnc(lexer_charAt(yylvalstr,0));
1049                              }
1050                            else if ( (nchars == 2) && (yylvalstr.charAt(0) == '+') && (yylvalstr.charAt(1) == '.'))
1051                              {
1052                                      yyless(1);
1053                                     returnc(lexer_charAt(yylvalstr,0));
1054                              }
1055                            else if ( (nchars == 2) && (yylvalstr.charAt(0) == '-') && (yylvalstr.charAt(1) == '.'))
1056                              {
1057                                      yyless(1);
1058                                     returnc(lexer_charAt(yylvalstr,0));
1059                              }
1060                            else if ( (nchars == 2) && (yylvalstr.charAt(1) == '~'))
1061                              {
1062                                      yyless(1);
1063                                     returnc(lexer_charAt(yylvalstr,0));
1064                              }
1065                            else if ( (nchars >= 2) && (yylvalstr.charAt(0) == '@') && (yylvalstr.charAt(1) == '@'))
1066                              {
1067                                      yyless(1);
1068                                     returnc(lexer_charAt(yylvalstr,0));
1069                              }
1070                           else if ( (nchars >= 2) && (yylvalstr.charAt(0)== '|') && (yylvalstr.charAt(1) == '|'))
1071                                { //||--sss ,just get || only
1072                                      yyless(2);
1073                                      yylvalstr = yylvalstr.substring(0,2);
1074                                      returni(op);
1075                                }
1076                                      else if ( (nchars == 2) && (yylvalstr.charAt(1) == '?') )
1077                                          {
1078                                            yyless(1);
1079                                            returnc(lexer_charAt(yylvalstr,0));
1080                                          }
1081                                      else if ( (nchars == 3) && (yylvalstr.charAt(2) == '?') )
1082                                          {
1083                                            //yyless(2);
1084                                            //returnc(lexer_charAt(yylvalstr,0));
1085                                            
1086                                 yyless(nchars-1);
1087                                 yylvalstr = yylvalstr.substring(0,nchars-1);
1088                                if (nchars == 2)
1089                                  returnc(lexer_charAt(yylvalstr,0));
1090                                else
1091                                  returni(op);
1092                                                                            
1093                                          }
1094                                                                else if ( (nchars >= 3) && (yylvalstr.charAt(nchars-1) == '$' ) && (yylvalstr.charAt(nchars-2) == '$' ))
1095                                                                { // =$$abc
1096                                                                        if (nchars == 3){
1097                                                                                yyless(1);
1098                                                                                returnc(lexer_charAt(yylvalstr,0));
1099                                                                        }else{
1100                                                                                yyless(nchars-2);
1101                                                                                yylvalstr = yylvalstr.substring(0,nchars-2);
1102                                                                                returni(cmpop);
1103                                                                        }
1104                                                                }
1105                                                                  else if (((nchars > 2) && (yylvalstr.charAt(0) == '*'))
1106                                      && (yylvalstr.charAt(1) == '/')
1107                                      && (getyysstate() == xc)
1108                                      )
1109                                   { //in comment, and find */ , then it must the end of comment
1110                                     yyless(2);
1111                                        addlit(yylvalstr,yytextlen);
1112                                     if (xcdepth <= 0)
1113                                       {
1114                                         start(init);
1115                                         yylvalstr = litbufdup();
1116                                         returni(cmtslashstar);
1117                                       }
1118                                     else
1119                                       xcdepth--;
1120                                   }
1121                              else
1122                                returni(op);
1123                       }
1124
1125                  break;
1126                  }
1127
1128  case 36:
1129                        
1130          {
1131               returni(iconst);
1132               break;
1133          }
1134
1135  case 37:
1136                        
1137          {
1138            ///*  for i in 1..5 loop, we can't recognize 1. as a decimal,but 1 as decimal
1139            nchars = yytextlen;
1140            if (yylvalstr.charAt(nchars-1) == '.')
1141              {
1142                dummych1 = get_char();
1143                unget_char(dummych1);
1144                if (dummych1 == '.')
1145                  {
1146                      yyless(nchars-1);
1147                    yylvalstr = yylvalstr.substring(0,nchars - 1);
1148                    returni (iconst);
1149                    return;//exit;
1150                  }
1151              }
1152                          
1153            if (yylvalstr.startsWith(".")&&(prevToken != null)){
1154                if (prevToken.tokencode == TBaseType.ident){
1155                    yyless(1);
1156                    yylvalstr = yylvalstr.substring(0,1);
1157                    returnc(lexer_charAt(yylvalstr,0));
1158                    return;//exit;
1159                }
1160            }
1161                        
1162            returni (fconst);
1163           break;
1164          }
1165
1166  case 38:
1167                        
1168          {
1169           returni (fconst);
1170           break;
1171          }
1172
1173
1174  case 39:
1175              
1176          {
1177            int rw;
1178             
1179             nchars = yytextlen;
1180             
1181             if ((tmpDelimiter.length()>0) && (yylvalstr.endsWith(tmpDelimiter))){
1182                 yyless(nchars-tmpDelimiter.length());
1183                 yylvalstr = yylvalstr.substring(0,nchars-tmpDelimiter.length());
1184             }
1185             
1186            if ( (rw = iskeyword(yylvalstr)) != -1)   { returni(rw);}
1187            else if ( (yylvalstr.charAt(0) == '_') && (isClickhouseCharset(yylvalstr.substring(1,nchars))) ){
1188              returni(MySQL_CHARSET_NAME);
1189            }
1190            else returni(ident);
1191            break;
1192          }
1193
1194  case 40:
1195           
1196          {
1197            returni(variable);
1198
1199            break;
1200          }
1201
1202  case 41:
1203             
1204          {
1205            returni(mysqllabel);
1206            break;
1207          }
1208
1209
1210  case 42:
1211         
1212          {
1213            returni(bind_v);
1214            break;
1215          }
1216                  
1217  case 43:
1218                          
1219          {
1220            returni(slash_dot);
1221            break;
1222          }
1223
1224  case 44:
1225                          
1226          {
1227            returni(mysql_null);
1228            break;
1229          }
1230                  
1231  case 45:
1232                        
1233          {
1234            returni( error);
1235            break;
1236          }
1237
1238    default:{
1239     System.out.println("fatal error in yyaction");
1240    }
1241   }//switch
1242}/*yyaction*/;
1243
1244
1245
1246        }