nixd
Loading...
Searching...
No Matches
Token.h
Go to the documentation of this file.
1#pragma once
2
3#include "Tokens.h"
4#include "nixf/Basic/Range.h"
5
6#include <cassert>
7#include <string_view>
8
9namespace nixf {
10
11/// \brief A token. With it's kind, and the range in source code.
12///
13/// This class is trivially copyable.
14class Token {
15 tok::TokenKind Kind;
16 LexerCursorRange Range;
17 std::string_view View;
18
19public:
20 Token(tok::TokenKind Kind, LexerCursorRange Range, std::string_view View)
21 : Kind(Kind), Range(Range), View(View) {}
22 [[nodiscard]] LexerCursor lCur() const { return Range.lCur(); }
23 [[nodiscard]] LexerCursor rCur() const { return Range.rCur(); }
24 [[nodiscard]] tok::TokenKind kind() const { return Kind; }
25 [[nodiscard]] LexerCursorRange range() const { return Range; }
26 [[nodiscard]] std::string_view view() const { return View; }
27};
28
29} // namespace nixf
A point in the source file.
Definition Range.h:57
LexerCursor lCur() const
Definition Token.h:22
tok::TokenKind kind() const
Definition Token.h:24
LexerCursorRange range() const
Definition Token.h:25
Token(tok::TokenKind Kind, LexerCursorRange Range, std::string_view View)
Definition Token.h:20
LexerCursor rCur() const
Definition Token.h:23
std::string_view view() const
Definition Token.h:26