github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/token/token.go (about) 1 package token 2 3 import ( 4 "fmt" 5 ) 6 7 type Token struct { 8 Type 9 Lit []byte 10 Pos 11 } 12 13 func (t *Token) String() string { 14 if t == nil { 15 return "nil" 16 } 17 return fmt.Sprintf("Token(type=%d, lit=%s, pos=%s", t.Type, t.Lit, t.Pos) 18 } 19 20 type Type int 21 22 const ( 23 INVALID Type = iota 24 UNFINISHED 25 EOF 26 LONGSTRING 27 NUMDEC 28 STRING 29 NUMHEX 30 IDENT 31 32 KwBreak 33 KwGoto 34 KwDo 35 KwWhile 36 KwEnd 37 KwRepeat 38 KwUntil 39 KwThen 40 KwElse 41 KwElseIf 42 KwIf 43 KwFor 44 KwIn 45 KwFunction 46 KwLocal 47 KwNot 48 KwNil 49 KwTrue 50 KwFalse 51 KwReturn 52 53 SgEtc 54 55 SgOpenSquareBkt 56 SgCloseSquareBkt 57 SgOpenBkt 58 SgCloseBkt 59 SgOpenBrace 60 SgCloseBrace 61 SgSemicolon 62 SgComma 63 SgDot 64 SgColon 65 SgDoubleColon 66 SgAssign 67 SgHash 68 69 beforeBinOp 70 71 SgMinus 72 SgPlus 73 SgStar 74 SgSlash 75 SgSlashSlash 76 SgPct 77 SgPipe 78 SgTilde 79 SgAmpersand 80 SgHat 81 SgShiftRight 82 SgShiftLeft 83 SgEqual 84 SgNotEqual 85 SgLess 86 SgLessEqual 87 SgGreater 88 SgGreaterEqual 89 SgConcat 90 KwAnd 91 KwOr 92 93 afterBinOp 94 ) 95 96 func (tp Type) IsBinOp() bool { 97 return tp > beforeBinOp && tp < afterBinOp 98 } 99 100 type Pos struct { 101 Offset int 102 Line int 103 Column int 104 } 105 106 func (p Pos) String() string { 107 return fmt.Sprintf("Pos(offset=%d, line=%d, column=%d)", p.Offset, p.Line, p.Column) 108 }