1// Code generated by golex. DO NOT EDIT. 2 3/* 4This file is used with golex to generate a lexer that has a signature compatible with goyacc. 5 6Many constants referred to below are defined by goyacc when creating template.y.go 7 8See https://godoc.org/modernc.org/golex for more about golex 9*/ 10 11package datemath 12 13import ( 14 "bytes" 15 "fmt" 16 "strconv" 17) 18 19const ( 20 // 0 is expected by the goyacc generated parser to indicate EOF 21 eofCode = 0 22) 23 24// lexer holds the state of the lexer 25type lexer struct { 26 src *bytes.Reader 27 28 buf []byte 29 current byte 30 31 pos int 32 33 errors []string 34} 35 36func newLexer(b []byte) *lexer { 37 l := &lexer{ 38 src: bytes.NewReader(b), 39 } 40 // queue up a byte 41 l.next() 42 return l 43} 44 45func (l *lexer) Error(s string) { 46 l.errors = append(l.errors, fmt.Sprintf("%s at character %d starting with %q", s, l.pos, string(l.buf))) 47} 48 49func (l *lexer) next() { 50 if l.current != 0 { 51 l.buf = append(l.buf, l.current) 52 } 53 l.current = 0 54 if b, err := l.src.ReadByte(); err == nil { 55 l.current = b 56 } 57 l.pos++ 58} 59func (l *lexer) Lex(lval *yySymType) int { 60 61 /* give some regular expressions more semantic names for use below */ 62 /* tell golex how to determine the current start condition */ 63 /* tell golex how to determine the current byte */ 64 /* tell golex how to advance to the next byte */ 65 66yystate0: 67 68 // runs before each token is parsed 69 l.buf = l.buf[:0] 70 71 goto yystart1 72 73yystate1: 74 l.next() 75yystart1: 76 switch { 77 default: 78 goto yyabort 79 case l.current == '+': 80 goto yystate4 81 case l.current == '-': 82 goto yystate5 83 case l.current == '.': 84 goto yystate6 85 case l.current == '/': 86 goto yystate7 87 case l.current == ':': 88 goto yystate9 89 case l.current == 'H' || l.current == 'M' || l.current == 'b' || l.current == 'd' || l.current == 'h' || l.current == 'm' || l.current == 's' || l.current == 'w' || l.current == 'y': 90 goto yystate10 91 case l.current == 'T': 92 goto yystate11 93 case l.current == 'Z': 94 goto yystate12 95 case l.current == '\x00': 96 goto yystate2 97 case l.current == 'n': 98 goto yystate13 99 case l.current == '|': 100 goto yystate16 101 case l.current >= '0' && l.current <= '9': 102 goto yystate8 103 case l.current >= '\x01' && l.current <= '\t' || l.current >= '\v' && l.current <= '*' || l.current == ',' || l.current >= ';' && l.current <= 'G' || l.current >= 'I' && l.current <= 'L' || l.current >= 'N' && l.current <= 'S' || l.current >= 'U' && l.current <= 'Y' || l.current >= '[' && l.current <= 'a' || l.current == 'c' || l.current >= 'e' && l.current <= 'g' || l.current >= 'i' && l.current <= 'l' || l.current >= 'o' && l.current <= 'r' || l.current >= 't' && l.current <= 'v' || l.current == 'x' || l.current == 'z' || l.current == '{' || l.current >= '}' && l.current <= 'ÿ': 104 goto yystate3 105 } 106 107yystate2: 108 l.next() 109 goto yyrule12 110 111yystate3: 112 l.next() 113 goto yyrule13 114 115yystate4: 116 l.next() 117 goto yyrule3 118 119yystate5: 120 l.next() 121 goto yyrule4 122 123yystate6: 124 l.next() 125 goto yyrule9 126 127yystate7: 128 l.next() 129 goto yyrule7 130 131yystate8: 132 l.next() 133 goto yyrule1 134 135yystate9: 136 l.next() 137 goto yyrule5 138 139yystate10: 140 l.next() 141 goto yyrule8 142 143yystate11: 144 l.next() 145 goto yyrule10 146 147yystate12: 148 l.next() 149 goto yyrule11 150 151yystate13: 152 l.next() 153 switch { 154 default: 155 goto yyrule13 156 case l.current == 'o': 157 goto yystate14 158 } 159 160yystate14: 161 l.next() 162 switch { 163 default: 164 goto yyabort 165 case l.current == 'w': 166 goto yystate15 167 } 168 169yystate15: 170 l.next() 171 goto yyrule2 172 173yystate16: 174 l.next() 175 switch { 176 default: 177 goto yyrule13 178 case l.current == '|': 179 goto yystate17 180 } 181 182yystate17: 183 l.next() 184 goto yyrule6 185 186yyrule1: // [0-9] 187 { 188 189 i, err := strconv.ParseInt(string(l.buf), 10, 0) 190 if err != nil { 191 panic(fmt.Sprintf("could not parse digit as number: %s", err)) 192 } 193 lval.i = int(i) 194 return tDIGIT 195 } 196yyrule2: // "now" 197 { 198 199 return tNOW 200 } 201yyrule3: // "+" 202 { 203 204 return tPLUS 205 } 206yyrule4: // "-" 207 { 208 209 return tMINUS 210 } 211yyrule5: // ":" 212 { 213 214 return tCOLON 215 } 216yyrule6: // "||" 217 { 218 219 return tPIPES 220 } 221yyrule7: // "/" 222 { 223 224 return tBACKSLASH 225 } 226yyrule8: // [yMwdbhHms] 227 { 228 229 switch l.buf[0] { 230 case 'y': 231 lval.unit = timeUnitYear 232 case 'M': 233 lval.unit = timeUnitMonth 234 case 'w': 235 lval.unit = timeUnitWeek 236 case 'b': 237 lval.unit = timeUnitBusinessDay 238 case 'd': 239 lval.unit = timeUnitDay 240 case 'h', 'H': 241 lval.unit = timeUnitHour 242 case 'm': 243 lval.unit = timeUnitMinute 244 case 's': 245 lval.unit = timeUnitSecond 246 default: 247 panic(fmt.Sprintf("unknown time unit: %q", l.buf[0])) 248 } 249 return tUNIT 250 } 251yyrule9: // \. 252 { 253 254 return tDOT 255 } 256yyrule10: // "T" 257 { 258 259 return tTIME_DELIMITER 260 } 261yyrule11: // "Z" 262 { 263 264 return tUTC 265 } 266yyrule12: // {eof} 267 { 268 269 return eofCode 270 } 271yyrule13: // . 272 if true { // avoid go vet determining the below panic will not be reached 273 274 return tINVALID_TOKEN 275 } 276 panic("unreachable") 277 278yyabort: // no lexem recognized 279 // 280 // silence unused label errors for build and satisfy go vet reachability analysis 281 // 282 { 283 if false { 284 goto yyabort 285 } 286 if false { 287 goto yystate0 288 } 289 if false { 290 goto yystate1 291 } 292 } 293 294 // should never get here 295 panic("scanner internal error") 296} 297