MCPcopy Create free account
hub / github.com/araddon/qlbridge / LexDialectForStatement

Function LexDialectForStatement

lex/lexer.go:778–828  ·  view source on GitHub ↗

State functions ------------------------------------------------------------ Find first keyword in the current queryText, then find appropriate statement in dialect. ie [SELECT, ALTER, CREATE, INSERT] in sql

(l *Lexer)

Source from the content-addressed store, hash-verified

776// Find first keyword in the current queryText, then find appropriate statement in dialect.
777// ie [SELECT, ALTER, CREATE, INSERT] in sql
778func 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 ..]

Callers

nothing calls this directly

Calls 9

LexCommentFunction · 0.85
SkipWhiteSpacesMethod · 0.80
PushMethod · 0.80
PeekWordMethod · 0.80
MatchesKeywordMethod · 0.80
clauseStateMethod · 0.80
errorTokenMethod · 0.80
PeekMethod · 0.65
IsEndMethod · 0.65

Tested by

no test coverage detected