How to use scanChar method of ast Package

Best Syzkaller code snippet using ast.scanChar

lexer.go

Source:lexer.go Github

copy

Full Screen

1package parser2import (3 "github.com/Gumihoy/gumiho-sql-go/sql/basic/ast"4 "strings"5 "unicode"6)7type ISQLLexer interface {8 Position() int9 Ch() rune10 Limit() int11 Line() int12 Col() int13 Token() *SQLToken14 SetToken(token *SQLToken)15 PreToken() *SQLToken16 // SetPreToken(token *SQLToken)17 Value() string18 PutChar()19 PutAndScanChar()20 ClearValue()21 Mark() *Mark22 Reset() bool23 ResetWithMark(mark *Mark) bool24 IsSQLIdentifierStart() bool25 IsSQLIdentifierPart() bool26 SkipWhitespace()27 ScanChar()28 ScanMinusCommentRest()29 ScanMultiLineCommentRest()30 ScanSharpCommentRest()31 ScanDoubleQuota() *Kind32 ScanReverseQuota() *Kind33 ScanSingleQuota() *Kind34 ScanStartZero() *Kind35 ScanNumeric() *Kind36 ScanStartX(child ISQLLexer) *Kind37 ScanAnd() *Kind38 ScanOr() *Kind39 ScanNot() *Kind40 ScanXor() *Kind41 ScanExclamation() *Kind42 ScanPlus() *Kind43 ScanMinus() *Kind44 ScanStar() *Kind45 ScanSlash() *Kind46 ScanPercent() *Kind47 ScanGT() *Kind48 ScanEQ() *Kind49 ScanLT() *Kind50 ScanDot() *Kind51 ScanAt() *Kind52 ScanQuestion() *Kind53 ScanLeftParen() *Kind54 ScanRightParen() *Kind55 ScanLeftBracket() *Kind56 ScanRightBracket() *Kind57 ScanLeftBrace() *Kind58 ScanRightBrace() *Kind59 ScanComma() *Kind60 ScanSemi() *Kind61 ScanColon(child ISQLLexer) *Kind62 ScanSharp(child ISQLLexer) *Kind63 // ScanIdent() *Kind64 GetKindMap() map[string]*Kind65 StringValue() string66 Comments() []ast.ISQLComment67 AddComment(comment ast.ISQLComment)68 ClearComments()69 IsEOF() bool70 UseNearErrorMsg() string71 UnSupport() string72}73type SQLLexer struct {74 content []rune75 position, limit int76 ch rune77 line, col int78 valueBuff []rune79 preToken, token *SQLToken80 mark *Mark81 comments []ast.ISQLComment82}83type Mark struct {84 position int85 ch rune86 line, col int87 valueBuff []rune88 preToken, token *SQLToken89}90func NewLexer(sql string) *SQLLexer {91 var lexer SQLLexer92 buff := []rune(sql)93 lexer.content = buff94 lexer.limit = len(buff)95 lexer.position, lexer.line, lexer.col = 0, 1, 096 lexer.ch = lexer.content[lexer.position]97 return &lexer98}99func (lexer *SQLLexer) Ch() rune {100 return lexer.ch101}102func (lexer *SQLLexer) Position() int {103 return lexer.position104}105func (lexer *SQLLexer) Limit() int {106 return lexer.limit107}108func (lexer *SQLLexer) Line() int {109 return lexer.line110}111func (lexer *SQLLexer) Col() int {112 return lexer.col113}114func (lexer *SQLLexer) Token() *SQLToken {115 return lexer.token116}117func (lexer *SQLLexer) SetToken(token *SQLToken) {118 lexer.preToken = lexer.token119 lexer.token = token120}121func (lexer *SQLLexer) PreToken() *SQLToken {122 return lexer.preToken123}124// func (lexer *SQLLexer) SetPreToken(token *SQLToken) {125// lexer.preToken = token126// }127func (lexer *SQLLexer) Value() string {128 return string(lexer.valueBuff)129}130func (lexer *SQLLexer) PutChar() {131 lexer.valueBuff = append(lexer.valueBuff, lexer.ch)132}133func (lexer *SQLLexer) PutCharWithCh(ch rune) {134 lexer.valueBuff = append(lexer.valueBuff, ch)135}136func (lexer *SQLLexer) PutAndScanChar() {137 lexer.valueBuff = append(lexer.valueBuff, lexer.ch)138 lexer.ScanChar()139}140func (lexer *SQLLexer) ClearValue() {141 if len(lexer.valueBuff) > 0 {142 lexer.valueBuff = lexer.valueBuff[0:0]143 }144}145func (lexer *SQLLexer) Mark() *Mark {146 mark := new(Mark)147 mark.position, mark.ch = lexer.position, lexer.ch148 mark.line, mark.col = lexer.line, lexer.col149 mark.preToken, mark.token = lexer.preToken, lexer.token150 mark.valueBuff = make([]rune, len(lexer.valueBuff))151 copy(mark.valueBuff, lexer.valueBuff)152 lexer.mark = mark153 return mark154}155func (lexer *SQLLexer) Reset() bool {156 return lexer.ResetWithMark(lexer.mark)157}158func (lexer *SQLLexer) ResetWithMark(mark *Mark) bool {159 if mark == nil {160 return false161 }162 lexer.position, lexer.ch = mark.position, mark.ch163 lexer.line, lexer.col = mark.line, mark.col164 lexer.preToken, lexer.token = mark.preToken, mark.token165 lexer.valueBuff = mark.valueBuff166 return true167}168func (lexer *SQLLexer) IsSQLIdentifierStart() bool {169 return lexer.IsSQLIdentifierStartWithCh(lexer.Ch())170}171func (lexer *SQLLexer) IsSQLIdentifierStartWithCh(ch rune) bool {172 return (ch >= 'a' && ch <= 'z') ||173 (ch >= 'A' && ch <= 'Z') ||174 (ch >= '0' && ch <= '9') ||175 (ch == '$') ||176 (ch == '_') ||177 (ch >= 0x0080 && ch <= 0xFFFF && ch != '(' && ch != ')' && ch != ',')178}179func (lexer *SQLLexer) IsSQLIdentifierPart() bool {180 return lexer.IsSQLIdentifierPartWithCh(lexer.Ch())181}182func (lexer *SQLLexer) IsSQLIdentifierPartWithCh(ch rune) bool {183 return (ch >= 'a' && ch <= 'z') ||184 (ch >= 'A' && ch <= 'Z') ||185 (ch >= '0' && ch <= '9') ||186 (ch == '$') ||187 (ch == '_') ||188 (ch >= 0x0080 && ch <= 0xFFFF && ch != '(' && ch != ')' && ch != ',')189}190func (lexer *SQLLexer) SkipWhitespace() {191 for {192 if !IsWhitespace(lexer.ch) {193 return194 }195 lexer.ScanChar()196 }197}198func (lexer *SQLLexer) ScanChar() {199 if lexer.ch == '\n' {200 lexer.line++201 lexer.col = 0202 } else {203 lexer.col++204 }205 lexer.position++206 lexer.ch = lexer.charAt(lexer.position)207}208func (lexer *SQLLexer) unScan() {209 lexer.position--210 lexer.ch = lexer.charAt(lexer.position)211}212func (lexer *SQLLexer) SkipChar(count int) {213 lexer.position += count214 lexer.ch = lexer.charAt(lexer.position)215}216const END = -1217func (lexer *SQLLexer) charAt(position int) rune {218 if position >= lexer.limit {219 return END220 }221 return lexer.content[position]222}223/**224 * -- comment225 */226func (lexer *SQLLexer) ScanMinusCommentRest() {227 lexer.ClearValue()228 lexer.SkipWhitespace()229 for {230 lexer.PutAndScanChar()231 if lexer.ch == '\n' || lexer.ch == END {232 break233 }234 }235 comment := ast.NewMinusCommentWithComment(lexer.StringValue())236 lexer.AddComment(comment)237}238// /* */239func (lexer *SQLLexer) ScanMultiLineCommentRest() {240 lexer.ClearValue()241 for {242 if lexer.Ch() == '*' && lexer.charAt(lexer.position+1) == '/' {243 lexer.ScanChar()244 lexer.ScanChar()245 break246 }247 if lexer.ch == END {248 break249 }250 lexer.PutAndScanChar()251 }252 comment := ast.NewMultiLineCommentWithComment(lexer.StringValue())253 lexer.AddComment(comment)254}255/**256 * # comment257 */258func (lexer *SQLLexer) ScanSharpCommentRest() {259 lexer.ClearValue()260 lexer.SkipWhitespace()261 for {262 lexer.PutAndScanChar()263 if lexer.ch == '\n' || lexer.ch == END {264 break265 }266 }267 comment := ast.NewSharpCommentWithComment(lexer.StringValue())268 lexer.AddComment(comment)269}270// ""271// "xxx"" xxx" => xxx" xxx272// "xxx" " xxx" => xxx xxx273func (lexer *SQLLexer) ScanDoubleQuota() *Kind {274 for {275 lexer.ScanString()276 if lexer.Ch() == '"' {277 lexer.PutCharWithCh('\\')278 lexer.PutCharWithCh('"')279 continue280 }281 if IsWhitespace(lexer.Ch()) {282 lexer.ScanChar()283 }284 if lexer.Ch() == '"' || lexer.Ch() == '\'' {285 continue286 }287 break288 }289 return IDENTIFIER_DOUBLE_QUOTE290}291func (lexer *SQLLexer) ScanReverseQuota() *Kind {292 panic("UnSupport '`' error:" + lexer.UseNearErrorMsg())293}294// ''295// 'xxx' xxx' => xxx" xxx296// 'xxx' ' xxx' => xxx xxx297func (lexer *SQLLexer) ScanSingleQuota() *Kind {298 for {299 lexer.ScanString()300 if lexer.Ch() == '\'' {301 lexer.PutCharWithCh('\\')302 lexer.PutCharWithCh('\'')303 continue304 }305 if IsWhitespace(lexer.Ch()) {306 lexer.ScanChar()307 }308 if lexer.Ch() == '"' || lexer.Ch() == '\'' {309 continue310 }311 break312 }313 return LITERAL_STRING314}315// "string"316// 'string'317// `string`318func (lexer *SQLLexer) ScanString() {319 firstCh := lexer.ch320 lexer.ScanChar()321 for {322 if lexer.ch == '\\' {323 lexer.PutAndScanChar()324 lexer.PutAndScanChar()325 }326 if lexer.ch == firstCh {327 lexer.ScanChar()328 break329 }330 if lexer.ch == END {331 panic("")332 }333 lexer.PutAndScanChar()334 }335}336/**337 * 0、0.1338 * 0x01AF339 */340func (lexer *SQLLexer) ScanStartZero() *Kind {341 if lexer.charAt(lexer.position+1) == '.' {342 lexer.PutAndScanChar()343 lexer.ScanChar()344 // 0.345 if !IsDigit(lexer.ch) {346 return LITERAL_INTEGER347 }348 lexer.PutCharWithCh('.')349 // 0.1xxx350 lexer.ScanDigit()351 return LITERAL_FLOATING_POINT352 } else if lexer.ch == 'x' {353 lexer.ScanChar()354 lexer.ScanHexadecimal()355 return LITERAL_HEXADECIMAL_0X356 } else if lexer.ch == 'X' {357 panic("")358 }359 lexer.PutAndScanChar()360 return LITERAL_INTEGER361}362/**363 * 1, .2, 3.4, -5, -6.78, +9.10364 * 1.2E3, 1.2E-3, -1.2E3, -1.2E-3365 */366func (lexer *SQLLexer) ScanNumeric() *Kind {367 kind := LITERAL_INTEGER368 if lexer.ch == '-' || lexer.ch == '+' {369 lexer.PutAndScanChar()370 // 处理空格371 lexer.SkipWhitespace()372 }373 lexer.ScanDigit()374 if lexer.ch == '.' {375 if lexer.charAt(lexer.position+1) == '.' {376 return kind377 }378 lexer.PutAndScanChar()379 lexer.ScanDigit()380 if lexer.ch == 'e' || lexer.ch == 'E' {381 lexer.PutAndScanChar()382 if lexer.ch == '-' || lexer.ch == '+' {383 lexer.PutAndScanChar()384 }385 lexer.ScanDigit()386 }387 kind = LITERAL_FLOATING_POINT388 } else if lexer.ch == 'E' || lexer.ch == 'e' {389 lexer.PutAndScanChar()390 if lexer.ch == '-' || lexer.ch == '+' {391 lexer.PutAndScanChar()392 }393 lexer.ScanDigit()394 kind = LITERAL_FLOATING_POINT395 }396 return kind397}398func IsDigit(ch rune) bool {399 return ch >= '0' && ch <= '9'400}401func (lexer *SQLLexer) ScanDigit() {402 for {403 if IsDigit(lexer.ch) {404 lexer.PutAndScanChar()405 continue406 }407 break408 }409}410/**411 * X'01AF'、X'01af'、x'01AF'、x'01af'412 * https://dev.mysql.com/doc/refman/8.0/en/hexadecimal-literals.html413 */414func (lexer *SQLLexer) ScanStartX(child ISQLLexer) *Kind {415 if lexer.charAt(lexer.position+1) == '\'' {416 lexer.ScanChar()417 lexer.ScanHexadecimal()418 return LITERAL_HEXADECIMAL_X419 }420 return ScanIdent(child)421}422func IsHexadecimal(ch rune) bool {423 return (ch >= '0' && ch <= '9') ||424 (ch >= 'a' && ch <= 'f') ||425 (ch >= 'A' && ch <= 'F')426}427/**428 * '01AF'429 * 01AF430 */431func (lexer *SQLLexer) ScanHexadecimal() {432 isQuote := lexer.ch == '\''433 if isQuote {434 lexer.ScanChar()435 }436 for {437 if !IsHexadecimal(lexer.ch) {438 break439 }440 lexer.PutAndScanChar()441 }442 if isQuote {443 if lexer.ch == '\'' {444 lexer.ScanChar()445 } else {446 panic("")447 }448 }449}450func (lexer *SQLLexer) ScanAnd() *Kind {451 lexer.ScanChar()452 return SYMB_BIT_AND453}454func (lexer *SQLLexer) ScanOr() *Kind {455 lexer.ScanChar()456 return SYMB_BIT_OR457}458func (lexer *SQLLexer) ScanNot() *Kind {459 lexer.ScanChar()460 return SYMB_BIT_NOT461}462// ^463func (lexer *SQLLexer) ScanXor() *Kind {464 lexer.ScanChar()465 return SYMB_BIT_XOR466}467// !468// !=469func (lexer *SQLLexer) ScanExclamation() *Kind {470 lexer.ScanChar()471 if lexer.ch == '=' {472 lexer.ScanChar()473 return SYMB_EXCLAMATION_EQUAL474 }475 return SYMB_EXCLAMATION476}477// +478// +1479func (lexer *SQLLexer) ScanPlus() *Kind {480 // 默认值481 kind := SYMB_PLUS482 nextPosition := lexer.position + 1483 next := lexer.charAt(nextPosition)484 // 处理空格485 for {486 if IsWhitespace(next) {487 if next == '\n' {488 lexer.line++489 }490 nextPosition := nextPosition + 1491 next = lexer.charAt(nextPosition)492 continue493 }494 break495 }496 if CanScanNumeric(lexer, next) {497 lexer.ScanNumeric()498 } else {499 lexer.ScanChar()500 }501 return kind502}503func (lexer *SQLLexer) ScanMinus() *Kind {504 // 默认值505 kind := SYMB_MINUS506 nextPosition := lexer.position + 1507 next := lexer.charAt(nextPosition)508 if next == '-' {509 lexer.ScanChar()510 lexer.ScanChar()511 kind = COMMENT_MINUS512 } else {513 // 处理空格514 for {515 if IsWhitespace(next) {516 if next == '\n' {517 lexer.line++518 }519 nextPosition := nextPosition + 1520 next = lexer.charAt(nextPosition)521 continue522 }523 break524 }525 if CanScanNumeric(lexer, next) {526 kind = lexer.ScanNumeric()527 } else {528 lexer.ScanChar()529 }530 }531 return kind532}533func CanScanNumeric(lexer *SQLLexer, ch rune) bool {534 return IsDigit(ch) && (lexer.preToken == nil || (lexer.token != nil && (lexer.token.Kind == SYMB_LEFT_PAREN || lexer.token.Kind == SYMB_COMMA)))535}536// *537func (lexer *SQLLexer) ScanStar() *Kind {538 lexer.ScanChar()539 if lexer.ch == '=' {540 lexer.ScanChar()541 return SYMB_MULT_EQUAL542 }543 return SYMB_STAR544}545/*546 * /547 * /*548 */549func (lexer *SQLLexer) ScanSlash() *Kind {550 kind := SYMB_SLASH551 lexer.ScanChar()552 if lexer.Ch() == '*' {553 lexer.ScanChar()554 kind = COMMENT_MULTI_LINE555 lexer.ScanMultiLineCommentRest()556 }557 return kind558}559func (lexer *SQLLexer) ScanPercent() *Kind {560 lexer.ScanChar()561 return SYMB_PERCENT562}563// >564// >>、>=565func (lexer *SQLLexer) ScanGT() *Kind {566 lexer.ScanChar()567 if lexer.ch == '>' {568 lexer.ScanChar()569 return SYMB_GREATER_THAN_GREATER_THAN570 } else if lexer.ch == '=' {571 lexer.ScanChar()572 return SYMB_GREATER_THAN_EQUAL573 }574 return SYMB_GREATER_THAN575}576// =577func (lexer *SQLLexer) ScanEQ() *Kind {578 lexer.ScanChar()579 return SYMB_EQUAL580}581// <582// <<、<>、<=、<=>583func (lexer *SQLLexer) ScanLT() *Kind {584 lexer.ScanChar()585 if lexer.ch == '<' {586 lexer.ScanChar()587 return SYMB_LESS_THAN_LESS_THAN588 } else if lexer.ch == '>' {589 lexer.ScanChar()590 return SYMB_LESS_THAN_GREATER_THAN591 } else if lexer.ch == '=' {592 lexer.ScanChar()593 if lexer.ch == '>' {594 lexer.ScanChar()595 return SYMB_LESS_THAN_EQUAL_GREATER_THAN596 }597 return SYMB_LESS_THAN_EQUAL598 }599 return SYMB_LESS_THAN600}601func (lexer *SQLLexer) ScanDot() *Kind {602 lexer.ScanChar()603 if IsDigit(lexer.ch) {604 for {605 lexer.PutAndScanChar()606 if !IsDigit(lexer.ch) {607 break608 }609 }610 return LITERAL_FLOATING_POINT611 }612 return SYMB_DOT613}614func (lexer *SQLLexer) ScanAt() *Kind {615 lexer.ScanChar()616 return SYMB_AT617}618func (lexer *SQLLexer) ScanQuestion() *Kind {619 lexer.ScanChar()620 return SYMB_QUESTION621}622func (lexer *SQLLexer) ScanLeftParen() *Kind {623 lexer.ScanChar()624 return SYMB_LEFT_PAREN625}626func (lexer *SQLLexer) ScanRightParen() *Kind {627 lexer.ScanChar()628 return SYMB_RIGHT_PAREN629}630func (lexer *SQLLexer) ScanLeftBracket() *Kind {631 lexer.ScanChar()632 return SYMB_LERT_BRACKET633}634func (lexer *SQLLexer) ScanRightBracket() *Kind {635 lexer.ScanChar()636 return SYMB_RIGHT_BRACKET637}638func (lexer *SQLLexer) ScanLeftBrace() *Kind {639 panic(lexer.UnSupport())640}641func (lexer *SQLLexer) ScanRightBrace() *Kind {642 panic(lexer.UnSupport())643}644func (lexer *SQLLexer) ScanComma() *Kind {645 lexer.ScanChar()646 return SYMB_COMMA647}648func (lexer *SQLLexer) ScanSemi() *Kind {649 lexer.ScanChar()650 return SYMB_SEMI651}652func (lexer *SQLLexer) ScanColon(child ISQLLexer) *Kind {653 panic(lexer.UnSupport())654}655func (lexer *SQLLexer) ScanSharp(child ISQLLexer) *Kind {656 panic(lexer.UnSupport())657}658func ScanIdent(lexer ISQLLexer) *Kind {659 lexer.PutChar()660 for {661 lexer.ScanChar()662 if !lexer.IsSQLIdentifierPart() {663 break664 }665 lexer.PutChar()666 }667 kind, ok := LookUp(lexer)668 if !ok {669 kind = IDENTIFIER670 }671 return kind672}673func LookUp(lexer ISQLLexer) (*Kind, bool) {674 kindMap := lexer.GetKindMap()675 kind, ok := kindMap[strings.ToUpper(lexer.StringValue())]676 return kind, ok677}678func (lexer *SQLLexer) GetKindMap() map[string]*Kind {679 return KindMap680}681func (lexer *SQLLexer) StringValue() string {682 return string(lexer.valueBuff)683}684func (lexer *SQLLexer) Comments() []ast.ISQLComment {685 return lexer.comments686}687func (lexer *SQLLexer) AddComment(comment ast.ISQLComment) {688 lexer.comments = append(lexer.comments, comment)689}690func (lexer *SQLLexer) ClearComments() {691 lexer.comments = ClearComments(lexer.comments)692}693func ClearComments(comments []ast.ISQLComment) []ast.ISQLComment {694 return comments[:0]695}696func (lexer *SQLLexer) IsEOF() bool {697 return lexer.position >= lexer.limit698}699func (lexer *SQLLexer) UseNearErrorMsg() string {700 return string(lexer.content[0:lexer.position])701}702func (lexer *SQLLexer) UnSupport() string {703 if lexer.token.Kind == IDENTIFIER {704 return "TODO: " + lexer.token.UnSupport() + " " + lexer.StringValue() + ", error:\"" + lexer.UseNearErrorMsg() + "\""705 } else {706 return "TODO: " + lexer.token.UnSupport() + ", error:\"" + lexer.UseNearErrorMsg() + "\""707 }708}709func (lexer *SQLLexer) clearValueBuff() {710 lexer.valueBuff = lexer.valueBuff[:0]711}712func NextToken(lexer ISQLLexer) {713 if lexer == nil {714 panic("lexer is nil.")715 }716 var kind *Kind717 var start, end int718 var line, col int719loop:720 for {721 lexer.ClearValue()722 lexer.SkipWhitespace()723 start = lexer.Position()724 line = lexer.Line()725 col = lexer.Col()726 start = lexer.Position()727 switch lexer.Ch() {728 case '"':729 kind = lexer.ScanDoubleQuota()730 case '`':731 kind = lexer.ScanReverseQuota()732 case '\'':733 kind = lexer.ScanSingleQuota()734 case '0':735 kind = lexer.ScanStartZero()736 case '1', '2', '3', '4', '5', '6', '7', '8', '9':737 kind = lexer.ScanNumeric()738 // case 'b':739 // 740 // case 'B':741 // 742 case 'x', 'X':743 kind = lexer.ScanStartX(lexer)744 case '&':745 kind = lexer.ScanAnd()746 case '|':747 kind = lexer.ScanOr()748 case '~':749 kind = lexer.ScanNot()750 case '^':751 kind = lexer.ScanXor()752 case '!':753 kind = lexer.ScanExclamation()754 case '+':755 kind = lexer.ScanPlus()756 case '-':757 kind = lexer.ScanMinus()758 case '*':759 kind = lexer.ScanStar()760 case '/':761 kind = lexer.ScanSlash()762 case '%':763 kind = lexer.ScanPercent()764 case '>':765 kind = lexer.ScanGT()766 case '=':767 kind = lexer.ScanEQ()768 case '<':769 kind = lexer.ScanLT()770 case '.':771 kind = lexer.ScanDot()772 case '@':773 kind = lexer.ScanAt()774 case '?', '?':775 kind = lexer.ScanQuestion()776 case '(', '(':777 kind = lexer.ScanLeftParen()778 case ')', ')':779 kind = lexer.ScanRightParen()780 case '[':781 kind = lexer.ScanLeftBracket()782 case ']':783 kind = lexer.ScanRightBracket()784 case '{':785 kind = lexer.ScanLeftBrace()786 case '}':787 kind = lexer.ScanRightBrace()788 case ',', ',':789 kind = lexer.ScanComma()790 case ';', ';':791 kind = lexer.ScanSemi()792 case ':':793 kind = lexer.ScanColon(lexer)794 case '#':795 kind = lexer.ScanSharp(lexer)796 default:797 if lexer.IsSQLIdentifierStart() {798 kind = ScanIdent(lexer)799 } else if lexer.IsEOF() {800 kind = EOF801 } else {802 panic("TODO:" + string(lexer.Ch()))803 }804 }805 break loop806 }807 end = lexer.Position() - 1808 token := NewToken(kind, start, end, line, col)809 lexer.SetToken(token)810}811func IsWhitespace(ch rune) bool {812 return unicode.IsSpace(ch)813}814var KindMap = make(map[string]*Kind)815func init() {816 // KindMap["ACCESSIBLE"] = ACCESSIBLE817 // KindMap["ADD"] = ADD818 KindMap["ALL"] = ALL819 KindMap["ALTER"] = ALTER820 // KindMap["ANALYZE"] = ANALYZE821 KindMap["AND"] = AND822 KindMap["AS"] = AS823 KindMap["ASC"] = ASC824 // KindMap["ASENSITIVE"] = ASENSITIVE825 // KindMap["BEFORE"] = BEFORE826 // KindMap["BETWEEN"] = BETWEEN827 // KindMap["BIGINT"] = BIGINT828 // KindMap["BINARY"] = BINARY829 // KindMap["BLOB"] = BLOB830 // KindMap["BOTH"] = BOTH831 KindMap["BY"] = BY832 // KindMap["CALL"] = CALL833 // KindMap["CASCADE"] = CASCADE834 // KindMap["CASE"] = CASE835 // KindMap["CHANGE"] = CHANGE836 // KindMap["CHAR"] = CHAR837 // KindMap["CHARACTER"] = CHARACTER838 // KindMap["CHECK"] = CHECK839 // KindMap["COLLATE"] = COLLATE840 // KindMap["COLUMN"] = COLUMN841 // KindMap["CONDITION"] = CONDITION842 // KindMap["CONSTRAINT"] = CONSTRAINT843 // KindMap["CONTINUE"] = CONTINUE844 // KindMap["CONVERT"] = CONVERT845 // KindMap["CREATE"] = CREATE846 // KindMap["CROSS"] = CROSS847 // KindMap["CUBE"] = CUBE848 // KindMap["CUME_DIST"] = CUME_DIST849 // KindMap["CURRENT_DATE"] = CURRENT_DATE850 // KindMap["CURRENT_TIME"] = CURRENT_TIME851 // KindMap["CURRENT_TIMESTAMP"] = CURRENT_TIMESTAMP852 // KindMap["CURRENT_USER"] = CURRENT_USER853 // KindMap["CURSOR"] = CURSOR854 // KindMap["DATABASE"] = DATABASE855 // KindMap["DATABASES"] = DATABASES856 // KindMap["DAY_HOUR"] = DAY_HOUR857 // KindMap["DAY_MICROSECOND"] = DAY_MICROSECOND858 // KindMap["DAY_MINUTE"] = DAY_MINUTE859 // KindMap["DAY_SECOND"] = DAY_SECOND860 // KindMap["DEC"] = DEC861 // KindMap["DECIMAL"] = DECIMAL862 // KindMap["DECLARE"] = DECLARE863 // KindMap["DEFAULT"] = DEFAULT864 // KindMap["DELAYED"] = DELAYED865 // KindMap["DELETE"] = DELETE866 // KindMap["DENSE_RANK"] = DENSE_RANK867 // KindMap["DESC"] = DESC868 // KindMap["DESCRIBE"] = DESCRIBE869 // KindMap["DETERMINISTIC"] = DETERMINISTIC870 // KindMap["DISTINCT"] = DISTINCT871 // KindMap["DISTINCTROW"] = DISTINCTROW872 // KindMap["DIV"] = DIV873 // KindMap["DOUBLE"] = DOUBLE874 // KindMap["DROP"] = DROP875 // KindMap["DUAL"] = DUAL876 // KindMap["EACH"] = EACH877 // KindMap["ELSE"] = ELSE878 // KindMap["ELSEIF"] = ELSEIF879 // KindMap["EMPTY"] = EMPTY880 // KindMap["ENCLOSED"] = ENCLOSED881 // KindMap["ESCAPED"] = ESCAPED882 // KindMap["EXCEPT"] = EXCEPT883 // KindMap["EXISTS"] = EXISTS884 // KindMap["EXIT"] = EXIT885 // KindMap["EXPLAIN"] = EXPLAIN886 KindMap["FALSE"] = FALSE887 // KindMap["FETCH"] = FETCH888 // KindMap["FIRST_VALUE"] = FIRST_VALUE889 // KindMap["FLOAT"] = FLOAT890 // KindMap["FLOAT4"] = FLOAT4891 // KindMap["FLOAT8"] = FLOAT8892 // KindMap["FOR"] = FOR893 // KindMap["FORCE"] = FORCE894 // KindMap["FOREIGN"] = FOREIGN895 KindMap["FROM"] = FROM896 // KindMap["FULLTEXT"] = FULLTEXT897 // KindMap["FUNCTION"] = FUNCTION898 // KindMap["GENERATED"] = GENERATED899 // KindMap["GET"] = GET900 // KindMap["GRANT"] = GRANT901 KindMap["GROUP"] = GROUP902 // KindMap["GROUPING"] = GROUPING903 // KindMap["GROUPS"] = GROUPS904 // KindMap["HAVING"] = HAVING905 // KindMap["HIGH_PRIORITY"] = HIGH_PRIORITY906 // KindMap["HOUR_MICROSECOND"] = HOUR_MICROSECOND907 // KindMap["HOUR_MINUTE"] = HOUR_MINUTE908 // HOUR_SECOND909 // IF910 // IGNORE911 KindMap["IN"] = IN912 KindMap["INDEX"] = INDEX913 // INFILE914 // INNER915 // INOUT916 // INSENSITIVE917 // INSERT918 // INT919 // INT1920 // INT2921 // INT3922 // INT4923 // INT8924 // INTEGER925 KindMap["INTERVAL"] = INTERVAL926 // INTO927 // IO_AFTER_GTIDS928 // IO_BEFORE_GTIDS929 // IS930 // ITERATE931 KindMap["JOIN"] = JOIN932 // JSON_TABLE933 // KEY934 // KEYS935 // KILL936 // LAG937 // LAST_VALUE938 // LATERAL939 // LEAD940 // LEADING941 // LEAVE942 // LEFT943 // LIKE944 KindMap["LIMIT"] = LIMIT945 // LINEAR946 // LINES947 // LOAD948 // LOCALTIME949 // LOCALTIMESTAMP950 // LOCK951 // LONG952 // LONGBLOB953 // LONGTEXT954 // LOOP955 // LOW_PRIORITY956 // MASTER_BIND957 // MASTER_SSL_VERIFY_SERVER_CERT958 // MATCH959 // MAXVALUE960 // MEDIUMBLOB961 // MEDIUMINT962 // MEDIUMTEXT963 // MIDDLEINT964 // MINUTE_MICROSECOND965 // MINUTE_SECOND966 // MOD967 // MODIFIES968 // NATURAL969 // NOT970 // NO_WRITE_TO_BINLOG971 // NTH_VALUE972 // NTILE973 // NULL974 // NUMERIC975 // OF976 KindMap["ON"] = ON977 // OPTIMIZE978 // OPTIMIZER_COSTS979 // OPTION980 // OPTIONALLY981 KindMap["OR"] = OR982 KindMap["ORDER"] = ORDER983 // OUT984 // OUTER985 // OUTFILE986 // OVER987 KindMap["PARTITION"] = PARTITION988 // PERCENT_RANK989 // PRECISION990 // PRIMARY991 // PROCEDURE992 // PURGE993 // RANGE994 // RANK995 // READ996 // READS997 // READ_WRITE998 // REAL999 // RECURSIVE1000 // REFERENCES1001 // REGEXP1002 // RELEASE1003 // RENAME1004 // REPEAT1005 // REPLACE1006 // REQUIRE1007 // RESIGNAL1008 // RESTRICT1009 // RETURN1010 // REVOKE1011 // RIGHT1012 // RLIKE1013 // ROW1014 // ROWS1015 // ROW_NUMBER1016 // SCHEMA1017 // SCHEMAS1018 // SECOND_MICROSECOND1019 KindMap["SELECT"] = SELECT1020 // SENSITIVE1021 // SEPARATOR1022 KindMap["SET"] = SET1023 // SHOW1024 // SIGNAL1025 // SMALLINT1026 // SPATIAL1027 // SPECIFIC1028 // SQL1029 // SQLEXCEPTION1030 // SQLSTATE1031 // SQLWARNING1032 // SQL_BIG_RESULT1033 // SQL_CALC_FOUND_ROWS1034 // SQL_SMALL_RESULT1035 // SSL1036 // STARTING1037 // STORED1038 // STRAIGHT_JOIN1039 // SYSTEM1040 // TABLE1041 // TERMINATED1042 // THEN1043 // TINYBLOB1044 // TINYINT1045 // TINYTEXT1046 // TO1047 // TRAILING1048 // TRIGGER1049 KindMap["TRUE"] = TRUE1050 // UNDO1051 // UNION1052 KindMap["UNION"] = UNION1053 // UNIQUE1054 // UNLOCK1055 // UNSIGNED1056 // UPDATE1057 // USAGE1058 // USE1059 // USING1060 // UTC_DATE1061 // UTC_TIME1062 // UTC_TIMESTAMP1063 // VALUES1064 // VARBINARY1065 // VARCHAR1066 // VARCHARACTER1067 // VARYING1068 // VIRTUAL1069 // KindMap["WHEN"] = WHEN1070 KindMap["WHERE"] = WHERE1071 // KindMap["WHILE"] = WHILE1072 // KindMap["WINDOW"] = WINDOW1073 KindMap["WITH"] = WITH1074 // KindMap["WRITE"] = WRITE1075 // KindMap["XOR"] = XOR1076 // KindMap["YEAR_MONTH"] = YEAR_MONTH1077 // KindMap["ZEROFILL"] = ZEROFILL1078}...

Full Screen

Full Screen

scan.go

Source:scan.go Github

copy

Full Screen

...55 tok.id = ruledef56 tok.lit = s.scanRuleDef()57 case s.cur == '\'':58 tok.id = char59 tok.lit = s.scanChar()60 case s.cur == '"':61 tok.id = str62 tok.lit = s.scanString()63 case s.cur == '`':64 tok.id = rstr65 tok.lit = s.scanRawString()66 case s.cur == '[':67 tok.id = class68 tok.lit = s.scanClass()69 case s.cur == '{':70 tok.id = code71 tok.lit = s.scanCode()72 default:73 r := s.cur74 s.read()75 switch r {76 case '/':77 if s.cur == '*' || s.cur == '/' {78 tok.id, tok.lit = s.scanComment()79 break80 }81 fallthrough82 case ':', ';', '(', ')', '.', '&', '!', '?', '+', '*', '\n':83 tok.id = tid(r)84 tok.lit = string(r)85 default:86 s.errorf("invalid character %#U", r)87 tok.id = invalid88 tok.lit = string(r)89 }90 }91 return tok, tok.id != eof92}93func (s *Scanner) scanIdentifier() string {94 s.tok.Reset()95 for isLetter(s.cur) || isDigit(s.cur) {96 s.tok.WriteRune(s.cur)97 s.read()98 }99 return s.tok.String()100}101func (s *Scanner) scanComment() (tid, string) {102 s.tok.Reset()103 s.tok.WriteRune('/') // initial '/' already consumed104 var multiline bool105 switch s.cur {106 case '*':107 multiline = true108 case '\n', -1:109 s.errorf("comment not terminated")110 return lcomment, s.tok.String()111 }112 var closing bool113 for {114 s.tok.WriteRune(s.cur)115 s.read()116 switch s.cur {117 case '\n':118 if !multiline {119 return lcomment, s.tok.String()120 }121 case -1:122 if multiline {123 s.errorf("comment not terminated")124 return mlcomment, s.tok.String()125 }126 return lcomment, s.tok.String()127 case '*':128 if multiline {129 closing = true130 }131 case '/':132 if closing {133 s.tok.WriteRune(s.cur)134 s.read()135 return mlcomment, s.tok.String()136 }137 }138 }139}140func (s *Scanner) scanCode() string {141 s.tok.Reset()142 s.tok.WriteRune(s.cur)143 depth := 1144 for {145 s.read()146 s.tok.WriteRune(s.cur)147 switch s.cur {148 case -1:149 s.errorf("code block not terminated")150 return s.tok.String()151 case '{':152 depth++153 case '}':154 depth--155 if depth == 0 {156 s.read()157 return s.tok.String()158 }159 }160 }161}162func (s *Scanner) scanEscape(quote rune) bool {163 // scanEscape is always called as part of a greater token, so do not164 // reset s.tok, and write s.cur before calling s.read.165 s.tok.WriteRune(s.cur)166 var n int167 var base, max uint32168 var unicodeClass bool169 s.read()170 switch s.cur {171 case 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', quote:172 s.tok.WriteRune(s.cur)173 return true174 case '0', '1', '2', '3', '4', '5', '6', '7':175 n, base, max = 3, 8, 255176 case 'x':177 s.tok.WriteRune(s.cur)178 s.read()179 n, base, max = 2, 16, 255180 case 'u':181 s.tok.WriteRune(s.cur)182 s.read()183 n, base, max = 4, 16, unicode.MaxRune184 case 'U':185 s.tok.WriteRune(s.cur)186 s.read()187 n, base, max = 8, 16, unicode.MaxRune188 case 'p':189 // unicode character class, only valid if quote is ']'190 if quote == ']' {191 s.tok.WriteRune(s.cur)192 unicodeClass = true193 s.read()194 break195 }196 fallthrough197 default:198 s.tok.WriteRune(s.cur)199 msg := "unknown escape sequence"200 if s.cur == -1 || s.cur == '\n' {201 msg = "escape sequence not terminated"202 s.errorf(msg)203 } else {204 s.errorf(msg)205 s.read()206 }207 return false208 }209 if unicodeClass {210 switch s.cur {211 case '\n', -1:212 s.errorf("escape sequence not terminated")213 return false214 case '{':215 // unicode class name, read until '}'216 cnt := 0217 for {218 s.tok.WriteRune(s.cur)219 s.read()220 cnt++221 switch s.cur {222 case '\n', -1:223 s.errorf("escape sequence not terminated")224 return false225 case '}':226 if cnt < 2 {227 s.errorf("empty Unicode character class escape sequence")228 }229 s.tok.WriteRune(s.cur)230 return true231 }232 }233 default:234 // single letter class235 s.tok.WriteRune(s.cur)236 return true237 }238 }239 var x uint32240 for n > 0 {241 s.tok.WriteRune(s.cur)242 d := uint32(digitVal(s.cur))243 if d >= base {244 msg := fmt.Sprintf("illegal character %#U in escape sequence", s.cur)245 if s.cur == -1 || s.cur == '\n' {246 msg = "escape sequence not terminated"247 s.errorf(msg)248 return false249 }250 s.errorf(msg)251 s.read()252 return false253 }254 x = x*base + d255 n--256 if n > 0 {257 s.read()258 }259 }260 if x > max || 0xd800 <= x && x <= 0xe000 {261 s.errorf("escape sequence is invalid Unicode code point")262 s.read()263 return false264 }265 return true266}267func (s *Scanner) scanClass() string {268 s.tok.Reset()269 s.tok.WriteRune(s.cur) // opening '['270 var noread bool271 for {272 if !noread {273 s.read()274 }275 noread = false276 switch s.cur {277 case '\\':278 noread = !s.scanEscape(']')279 case '\n', -1:280 // \n not consumed281 s.errorf("character class not terminated")282 return s.tok.String()283 case ']':284 s.tok.WriteRune(s.cur)285 s.read()286 // can have an optional "i" ignore case suffix287 if s.cur == 'i' {288 s.tok.WriteRune(s.cur)289 s.read()290 }291 return s.tok.String()292 default:293 s.tok.WriteRune(s.cur)294 }295 }296}297func (s *Scanner) scanRawString() string {298 s.tok.Reset()299 s.tok.WriteRune(s.cur) // opening '`'300 var hasCR bool301loop:302 for {303 s.read()304 switch s.cur {305 case -1:306 s.errorf("raw string literal not terminated")307 break loop308 case '`':309 s.tok.WriteRune(s.cur)310 s.read()311 // can have an optional "i" ignore case suffix312 if s.cur == 'i' {313 s.tok.WriteRune(s.cur)314 s.read()315 }316 break loop317 case '\r':318 hasCR = true319 fallthrough320 default:321 s.tok.WriteRune(s.cur)322 }323 }324 b := s.tok.Bytes()325 if hasCR {326 b = stripCR(b)327 }328 return string(b)329}330func stripCR(b []byte) []byte {331 c := make([]byte, len(b))332 i := 0333 for _, ch := range b {334 if ch != '\r' {335 c[i] = ch336 i++337 }338 }339 return c[:i]340}341func (s *Scanner) scanString() string {342 s.tok.Reset()343 s.tok.WriteRune(s.cur) // opening '"'344 var noread bool345 for {346 if !noread {347 s.read()348 }349 noread = false350 switch s.cur {351 case '\\':352 noread = !s.scanEscape('"')353 case '\n', -1:354 // \n not consumed355 s.errorf("string literal not terminated")356 return s.tok.String()357 case '"':358 s.tok.WriteRune(s.cur)359 s.read()360 // can have an optional "i" ignore case suffix361 if s.cur == 'i' {362 s.tok.WriteRune(s.cur)363 s.read()364 }365 return s.tok.String()366 default:367 s.tok.WriteRune(s.cur)368 }369 }370}371func (s *Scanner) scanChar() string {372 s.tok.Reset()373 s.tok.WriteRune(s.cur) // opening "'"374 // must be followed by one char (which may be an escape) and a single375 // quote, but read until we find that closing quote.376 cnt := 0377 var noread bool378 for {379 if !noread {380 s.read()381 }382 noread = false383 switch s.cur {384 case '\\':385 cnt++...

Full Screen

Full Screen

scanChar

Using AI Code Generation

copy

Full Screen

1import java.io.*;2{3 public static void main(String args[])throws IOException4 {5 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));6 System.out.println("Enter the string");7 String s=br.readLine();8 System.out.println("Enter the character to be searched");9 String c=br.readLine();10 char ch=c.charAt(0);11 System.out.println("Enter the position to be searched");12 int pos=Integer.parseInt(br.readLine());13 int count=0;14 for(int i=0;i<s.length();i++)15 {16 if(s.charAt(i)==ch)17 {18 count++;19 if(count==pos)20 {21 System.out.println("The character is present at position "+(i+1));22 break;23 }24 }25 }26 if(count<pos)27 {28 System.out.println("The character is not present at the given position");29 }30 }31}32import java.io.*;33{34 public static void main(String args[])throws IOException35 {36 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));37 System.out.println("Enter the string");38 String s=br.readLine();39 System.out.println("Enter the character to be searched");40 String c=br.readLine();41 char ch=c.charAt(0);42 int count=0;43 for(int i=0;i<s.length();i++)44 {45 if(s.charAt(i)==ch)46 {47 count++;48 }49 }50 System.out.println("The number of occurences of the given character is "+count);51 }52}53import java.io.*;54{55 public static void main(String args[])throws IOException56 {57 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));58 System.out.println("Enter the string");59 String s=br.readLine();60 System.out.println("Enter the character to be searched");61 String c=br.readLine();62 char ch=c.charAt(0);63 int count=0;64 for(int i=0;i<s.length();i++)65 {66 if(s.charAt(i)==ch)67 {68 count++;69 }70 }71 System.out.println("The number of occurences of the given character is "+count);72 }73}

Full Screen

Full Screen

scanChar

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, 世界")4}52: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped62: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped72: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped82: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped92: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped102: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped112: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped122: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped

Full Screen

Full Screen

scanChar

Using AI Code Generation

copy

Full Screen

1void scanChar (char ch) {2 ast . scanChar (ch);3}4void scanChar (char ch) {5 ast . scanChar (ch);6}7void scanChar (char ch) {8 ast . scanChar (ch);9}10void scanChar (char ch) {11 ast . scanChar (ch);12}13void scanChar (char ch) {14 ast . scanChar (ch);15}16void scanChar (char ch) {17 ast . scanChar (ch);18}19void scanChar (char ch) {20 ast . scanChar (ch);21}22void scanChar (char ch) {23 ast . scanChar (ch);24}25void scanChar (char ch) {26 ast . scanChar (ch);27}28void scanChar (char ch) {29 ast . scanChar (ch);30}31void scanChar (char ch) {32 ast . scanChar (ch);33}34void scanChar (char ch) {35 ast . scanChar (ch);36}37void scanChar (char ch) {38 ast . scanChar (ch);39}40void scanChar (char ch) {41 ast . scanChar (ch

Full Screen

Full Screen

scanChar

Using AI Code Generation

copy

Full Screen

1import java.io.*;2import java.util.*;3import java.lang.*;4import java.util.regex.*;5public class 2 {6 public static void main(String[] args) {7 System.out.println("Enter the path of the file");8 Scanner scan = new Scanner(System.in);9 String path = scan.nextLine();10 File file = new File(path);11 ast a = new ast();12 a.scanChar(file);13 }14}15import java.io.*;16import java.util.*;17import java.lang.*;18import java.util.regex.*;19public class ast {20 public void scanChar(File file) {21 try {22 Scanner scan = new Scanner(file);23 while (scan.hasNext()) {24 String line = scan.nextLine();25 String[] words = line.split(" ");26 for (int i = 0; i < words.length; i++) {27 if (words[i].contains("for")) {28 System.out.println("Found a for loop");29 }30 }31 }32 } catch (FileNotFoundException e) {33 System.out.println("File not found");34 }35 }36}

Full Screen

Full Screen

scanChar

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "os"3import "io"4import "bufio"5import "strings"6import "strconv"7import "go/ast"8import "go/parser"9import "go/token"10func main() {11 f, err := parser.ParseFile(fset, os.Args[1], nil, parser.ParseComments)12 if err != nil {13 fmt.Println(err)14 }15 ast.Print(fset, f)16}17import "fmt"18import "os"19import "io"20import "bufio"21import "strings"22import "strconv"23import "go/ast"24import "go/parser"25import "go/token"26func main() {27 f, err := parser.ParseFile(fset, os.Args[1], nil, parser.ParseComments)28 if err != nil {29 fmt.Println(err)30 }31 ast.Print(fset, f)32}33import "fmt"34import "os"35import "io"36import "bufio"37import "strings"38import "strconv"39import "go/ast"40import "go/parser"41import "go/token"42func main() {43 f, err := parser.ParseFile(fset, os.Args[1], nil, parser.ParseComments)44 if err != nil {45 fmt.Println(err)46 }47 ast.Print(fset, f)48}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful