1 //===-- GoLexer.h -----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_GoLexer_h
11 #define liblldb_GoLexer_h
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/ADT/StringRef.h"
16 namespace lldb_private {
20 explicit GoLexer(const char *src);
106 explicit Token(TokenType t, llvm::StringRef text)
107 : m_type(t), m_value(text) {}
109 llvm::StringRef m_value;
114 size_t BytesRemaining() const { return m_end - m_src; }
115 llvm::StringRef GetString(int len) const {
116 return llvm::StringRef(m_src, len);
119 static TokenType LookupKeyword(llvm::StringRef id);
120 static llvm::StringRef LookupToken(TokenType t);
123 bool IsDecimal(char c) { return c >= '0' && c <= '9'; }
124 bool IsHexChar(char c) {
125 if (c >= '0' && c <= '9')
127 if (c >= 'A' && c <= 'F')
129 if (c >= 'a' && c <= 'f')
133 bool IsLetterOrDigit(char c) {
134 if (c >= 'a' && c <= 'z')
136 if (c >= 'A' && c <= 'Z')
140 if (c >= '0' && c <= '9')
142 // Treat all non-ascii chars as letters for simplicity.
143 return 0 != (c & 0x80);
145 bool IsWhitespace(char c) {
155 bool SkipWhitespace();
158 TokenType InternalLex(bool newline);
160 TokenType DoOperator();
164 TokenType DoNumber();
168 TokenType DoString();
170 static llvm::StringMap<TokenType> *InitKeywords();
172 static llvm::StringMap<TokenType> *m_keywords;
179 } // namespace lldb_private