State functions ------------------------------------------------------------ Find first keyword in the current queryText, then find appropriate statement in dialect. ie [SELECT, ALTER, CREATE, INSERT] in sql
(l *Lexer)
| 776 | // Find first keyword in the current queryText, then find appropriate statement in dialect. |
| 777 | // ie [SELECT, ALTER, CREATE, INSERT] in sql |
| 778 | func LexDialectForStatement(l *Lexer) StateFn { |
| 779 | |
| 780 | l.SkipWhiteSpaces() |
| 781 | |
| 782 | r := l.Peek() |
| 783 | |
| 784 | switch r { |
| 785 | case '/', '-', '#': |
| 786 | // ensure we have consumed all initial pre-statement comments |
| 787 | l.Push("LexDialectForStatement", LexDialectForStatement) |
| 788 | return LexComment(l) |
| 789 | default: |
| 790 | peekWord := strings.ToLower(l.PeekWord()) |
| 791 | for _, stmt := range l.dialect.Statements { |
| 792 | if l.IsEnd() { |
| 793 | break |
| 794 | } |
| 795 | |
| 796 | //u.Warnf("LexDialectForStatement peek=%s keyword=%v ", peekWord, stmt.Token.String()) |
| 797 | if stmt.MatchesKeyword(peekWord, l) { |
| 798 | // We aren't actually going to consume anything here, just find |
| 799 | // the correct statement |
| 800 | l.statement = stmt |
| 801 | l.curClause = stmt |
| 802 | if len(stmt.Clauses) > 0 { |
| 803 | l.curClause = stmt.Clauses[0] |
| 804 | } |
| 805 | //u.Infof("statement: %s curClause %s", l.statement, l.curClause) |
| 806 | return LexStatement |
| 807 | } else if stmt.Token == TokenNil { |
| 808 | if len(stmt.Clauses) == 1 { |
| 809 | l.statement = stmt |
| 810 | l.curClause = stmt |
| 811 | if len(stmt.Clauses) > 0 { |
| 812 | l.curClause = stmt.Clauses[0] |
| 813 | } |
| 814 | return l.clauseState() |
| 815 | } |
| 816 | l.statement = stmt |
| 817 | l.curClause = stmt |
| 818 | if len(stmt.Clauses) > 0 { |
| 819 | l.curClause = stmt.Clauses[0] |
| 820 | } |
| 821 | return LexStatement |
| 822 | } |
| 823 | |
| 824 | } |
| 825 | return l.errorToken("un recognized keyword token:" + peekWord) |
| 826 | |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | // LexStatement is the main entrypoint to lex Grammars primarily associated with QL type |
| 831 | // languages, which is keywords separate clauses, and have order [select .. FROM name WHERE ..] |
nothing calls this directly
no test coverage detected