()
| 170 | } |
| 171 | |
| 172 | func (s *Scanner) scanIdent() (tok Token, pos Pos, lit string) { |
| 173 | // Save the starting position of the identifier. |
| 174 | _, pos = s.r.read() |
| 175 | s.r.unread() |
| 176 | |
| 177 | var buf bytes.Buffer |
| 178 | for { |
| 179 | if ch, _ := s.r.read(); ch == eof { |
| 180 | break |
| 181 | } else if ch == '`' { |
| 182 | tok0, pos0, lit0 := s.scanString() |
| 183 | if tok0 == BADSTRING || tok0 == BADESCAPE { |
| 184 | return tok0, pos0, lit0 |
| 185 | } |
| 186 | return IDENT, pos, lit0 |
| 187 | } else if isIdentChar(ch) { |
| 188 | s.r.unread() |
| 189 | buf.WriteString(ScanBareIdent(s.r)) |
| 190 | } else { |
| 191 | s.r.unread() |
| 192 | break |
| 193 | } |
| 194 | } |
| 195 | lit = buf.String() |
| 196 | |
| 197 | // If the literal matches a keyword then return that keyword. |
| 198 | if tok = Lookup(lit); tok != IDENT { |
| 199 | return tok, pos, "" |
| 200 | } |
| 201 | |
| 202 | return IDENT, pos, lit |
| 203 | } |
| 204 | |
| 205 | // scanString consumes a contiguous string of non-quote characters. |
| 206 | // Quote characters can be consumed if they're first escaped with a backslash. |
no test coverage detected