• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "gn/token.h"
6 
7 #include "base/logging.h"
8 #include "gn/tokenizer.h"
9 
Token()10 Token::Token() : type_(INVALID), value_() {}
11 
Token(const Location & location,Type t,std::string_view v)12 Token::Token(const Location& location, Type t, std::string_view v)
13     : type_(t), value_(v), location_(location) {}
14 
15 // static
ClassifyAndMake(const Location & location,std::string_view v)16 Token Token::ClassifyAndMake(const Location& location, std::string_view v) {
17   char first = v.size() > 0 ? v[0] : '\0';
18   char second = v.size() > 1 ? v[1] : '\0';
19   return Token(location, Tokenizer::ClassifyToken(first, second), v);
20 }
21 
IsIdentifierEqualTo(const char * v) const22 bool Token::IsIdentifierEqualTo(const char* v) const {
23   return type_ == IDENTIFIER && value_ == v;
24 }
25 
IsStringEqualTo(const char * v) const26 bool Token::IsStringEqualTo(const char* v) const {
27   return type_ == STRING && value_ == v;
28 }
29