PostgreSQL Source Code: src/fe_utils/psqlscan.l File Reference (original) (raw)
387 {
388
391
392
393
394
395
396
397
398
400%}
401
402{whitespace} {
403
404
405
406
407
408
409
410 if (output_buf->len > 0)
412 }
413
414{xcstart} {
416 BEGIN(xc);
417
418 yyless(2);
420 }
421
422{
423{xcstart} {
424 cur_state->xcdepth++;
425
426 yyless(2);
428 }
429
430{xcstop} {
431 if (cur_state->xcdepth <= 0)
432 BEGIN(INITIAL);
433 else
434 cur_state->xcdepth--;
436 }
437
438{xcinside} {
440 }
441
442{op_chars} {
444 }
445
446\*+ {
448 }
449} /* */
450
451{xbstart} {
452 BEGIN(xb);
454 }
455{xhinside} |
456{xbinside} {
458 }
459
460{xhstart} {
461
462
463
464
465
466
467 BEGIN(xh);
469 }
470
471{xnstart} {
472 yyless(1);
474 }
475
476{xqstart} {
477 if (cur_state->std_strings)
478 BEGIN(xq);
479 else
480 BEGIN(xe);
482 }
483{xestart} {
484 BEGIN(xe);
486 }
487{xusstart} {
488 BEGIN(xus);
490 }
491
492<xb,xh,xq,xe,xus>{quote} {
493
494
495
496
497
498
499
500
501 cur_state->state_before_str_stop = YYSTATE;
502 BEGIN(xqs);
504 }
505{quotecontinue} {
506
507
508
509
510
511 BEGIN(cur_state->state_before_str_stop);
513 }
514{quotecontinuefail} |
515{other} {
516
517
518
519
520
521 yyless(0);
522 BEGIN(INITIAL);
523
524 }
525
526<xq,xe,xus>{xqdouble} {
528 }
529<xq,xus>{xqinside} {
531 }
532{xeinside} {
534 }
535{xeunicode} {
537 }
538{xeunicodefail} {
540 }
541{xeescape} {
543 }
544{xeoctesc} {
546 }
547{xehexesc} {
549 }
550. {
551
553 }
554
555{dolqdelim} {
556 cur_state->dolqstart = pg_strdup(yytext);
557 BEGIN(xdolq);
559 }
560{dolqfailed} {
561
562 yyless(1);
564 }
565{dolqdelim} {
566 if (strcmp(yytext, cur_state->dolqstart) == 0)
567 {
568 free(cur_state->dolqstart);
569 cur_state->dolqstart = NULL;
570 BEGIN(INITIAL);
571 }
572 else
573 {
574
575
576
577
578
580 }
582 }
583{dolqinside} {
585 }
586{dolqfailed} {
588 }
589. {
590
592 }
593
594{xdstart} {
595 BEGIN(xd);
597 }
598{xuistart} {
599 BEGIN(xui);
601 }
602{xdstop} {
603 BEGIN(INITIAL);
605 }
606{dquote} {
607 BEGIN(INITIAL);
609 }
610<xd,xui>{xddouble} {
612 }
613<xd,xui>{xdinside} {
615 }
616
617{xufailed} {
618
619 yyless(1);
621 }
622
623{typecast} {
625 }
626
627{dot_dot} {
629 }
630
631{colon_equals} {
633 }
634
635{equals_greater} {
637 }
638
639{less_equals} {
641 }
642
643{greater_equals} {
645 }
646
647{less_greater} {
649 }
650
651{not_equals} {
653 }
654
655
656
657
658
659
660
661"(" {
662 cur_state->paren_depth++;
664 }
665
666")" {
667 if (cur_state->paren_depth > 0)
668 cur_state->paren_depth--;
670 }
671
672";" {
674 if (cur_state->paren_depth == 0 && cur_state->begin_depth == 0)
675 {
676
677 cur_state->start_state = YY_START;
678 cur_state->identifier_count = 0;
680 }
681 }
682
683
684
685
686
687
688"\\"[;:] {
689
691 if (yytext[1] == ';')
692 cur_state->identifier_count = 0;
693 }
694
695"\\" {
696
697 cur_state->start_state = YY_START;
699 }
700
701:{variable_char}+ {
702
703 char *varname;
705
707 yytext + 1,
709 if (cur_state->callbacks->get_variable)
710 value = cur_state->callbacks->get_variable(varname,
712 cur_state->cb_passthrough);
713 else
715
717 {
718
720 {
721
722 pg_log_warning("skipping recursive expansion of variable \"%s\"",
723 varname);
724
726 }
727 else
728 {
729
731
732 }
734 }
735 else
736 {
737
738
739
740
742 }
#define pg_log_warning(...)
void psqlscan_push_new_buffer(PsqlScanState state, const char *newstr, const char *varname)
bool psqlscan_var_is_current_source(PsqlScanState state, const char *varname)
743
744 free(varname);
745 }
746
747:'{variable_char}+' {
750 }
void psqlscan_escape_variable(PsqlScanState state, const char *txt, int len, PsqlScanQuoteType quote)
751
752:\"{variable_char}+\" {
755 }
756
757:\{\?{variable_char}+\} {
759 }
void psqlscan_test_variable(PsqlScanState state, const char *txt, int len)
760
761
762
763
764
765
766:'{variable_char}* {
767
768 yyless(1);
770 }
771
772:\"{variable_char}* {
773
774 yyless(1);
776 }
777
778:\{\?{variable_char}* {
779
780 yyless(1);
782 }
783:\{ {
784
785 yyless(1);
787 }
788
789
790
791
792
793{self} {
795 }
796
797{operator} {
798
799
800
801
802
803
805 char *slashstar = strstr(yytext, "/*");
806 char *dashdash = strstr(yytext, "--");
807
808 if (slashstar && dashdash)
809 {
810
811 if (slashstar > dashdash)
812 slashstar = dashdash;
813 }
814 else if (!slashstar)
815 slashstar = dashdash;
816 if (slashstar)
817 nchars = slashstar - yytext;
818
819
820
821
822
823
824
825
826
827 if (nchars > 1 &&
828 (yytext[nchars - 1] == '+' ||
829 yytext[nchars - 1] == '-'))
830 {
831 int ic;
832
833 for (ic = nchars - 2; ic >= 0; ic--)
834 {
835 char c = yytext[ic];
836 if (c == '~' || c == '!' || c == '@' ||
837 c == '#' || c == '^' || c == '&' ||
838 c == '|' || c == '`' || c == '?' ||
839 c == '%')
840 break;
841 }
842 if (ic < 0)
843 {
844
845
846
847
848 do {
849 nchars--;
850 } while (nchars > 1 &&
851 (yytext[nchars - 1] == '+' ||
852 yytext[nchars - 1] == '-'));
853 }
854 }
855
857 {
858
859 yyless(nchars);
860 }
862 }
863
864{param} {
866 }
867{param_junk} {
869 }
870
871{decinteger} {
873 }
874{hexinteger} {
876 }
877{octinteger} {
879 }
880{bininteger} {
882 }
883{hexfail} {
885 }
886{octfail} {
888 }
889{binfail} {
891 }
892{numeric} {
894 }
895{numericfail} {
896
899 }
900{real} {
902 }
903{realfail} {
905 }
906{integer_junk} {
908 }
909{numeric_junk} {
911 }
912{real_junk} {
914 }
915
916
917{identifier} {
918
919
920
921
922
923
924
925
926
927
928 if (cur_state->identifier_count == 0)
929 memset(cur_state->identifiers, 0, sizeof(cur_state->identifiers));
930
936 {
937 if (cur_state->identifier_count < sizeof(cur_state->identifiers))
938 cur_state->identifiers[cur_state->identifier_count] = pg_tolower((unsigned char) yytext[0]);
939 }
int pg_strcasecmp(const char *s1, const char *s2)
unsigned char pg_tolower(unsigned char ch)
940
941 cur_state->identifier_count++;
942
943 if (cur_state->identifiers[0] == 'c' &&
944 (cur_state->identifiers[1] == 'f' || cur_state->identifiers[1] == 'p' ||
945 (cur_state->identifiers[1] == 'o' && cur_state->identifiers[2] == 'r' &&
946 (cur_state->identifiers[3] == 'f' || cur_state->identifiers[3] == 'p'))) &&
947 cur_state->paren_depth == 0)
948 {
950 cur_state->begin_depth++;
952 {
953
954
955
956
957 if (cur_state->begin_depth >= 1)
958 cur_state->begin_depth++;
959 }
961 {
962 if (cur_state->begin_depth > 0)
963 cur_state->begin_depth--;
964 }
965 }
966
968 }
969
970{other} {
972 }
973
974<> {
975 if (cur_state->buffer_stack == NULL)
976 {
977 cur_state->start_state = YY_START;
978 return LEXRES_EOL;
979 }
980
981
982
983
984
987 }
void psqlscan_select_top_buffer(PsqlScanState state)
988
989%%