1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "lexer/token.h"
10
11 #include <unordered_map>
12
13 #include "util/common.h"
14 #include "util/file.h"
15 #include "util/string_builder.h"
16 #include "util/string_helper.h"
17
18 namespace OHOS {
19 namespace HDI {
Dump()20 std::string Token::Dump()
21 {
22 StringBuilder sb;
23 sb.AppendFormat(
24 "{kind_:%u, row_:%u, col_:%u, value_:%s}", (size_t)kind_, location_.row_, location_.col_, value_.c_str());
25 return sb.ToString();
26 }
27
LocInfo(const Token & token)28 std::string LocInfo(const Token &token)
29 {
30 size_t index = token.location_.filePath_.rfind(SEPARATOR);
31 std::string fileName =
32 (index == std::string::npos) ? token.location_.filePath_ : token.location_.filePath_.substr(index + 1);
33 return StringHelper::Format("%s:%u:%u", fileName.c_str(), token.location_.row_, token.location_.col_);
34 }
35 } // namespace HDI
36 } // namespace OHOS