tfel
Loading...
Searching...
No Matches
tfel::utilities::Token Struct Reference

class representing a token in a C++-like file More...

#include </home/runner/work/tfel/tfel/include/TFEL/Utilities/Token.hxx>

Public Types

enum  TokenFlag {
  Standard , Comment , Number , DoxygenComment ,
  DoxygenBackwardComment , String , Char , Preprocessor
}
 possible type of the token
using size_type = size_t
 a simple alias

Public Member Functions

 Token ()
 default constructor
 Token (const std::string &, const size_type, const size_type, const TokenFlag=Standard)
 constructor
 Token (const Token &)
 copy constructor
 Token (Token &&) noexcept
 move constructor
Token & operator= (const Token &)
 assignement
Token & operator= (Token &&) noexcept
 move assignement
 ~Token () noexcept
 destructor

Public Attributes

std::string value
 string holded by the token
size_type line = 0u
 line number
size_type offset = 0u
 offset in the line
std::string comment
 comment
TokenFlag flag = Standard
 type of the token

Detailed Description

class representing a token in a C++-like file

Constructor & Destructor Documentation

◆ Token()

tfel::utilities::Token::Token ( const std::string & ,
const size_type ,
const size_type ,
const TokenFlag = Standard )

constructor

Parameters
[in]vtoken value
[in]lline number
[in]ooffset
[in]ftoken flag

Member Data Documentation

◆ offset

size_type tfel::utilities::Token::offset = 0u

offset in the line

The offset of a token is the position, in the line the token starts on, of the first character the token stands for, so that it is always strictly smaller than the size of that line. This is the case of a raw string token, whose offset is that of its R delimiter as the offset of a quoted string token is that of its opening quote, see issue #1390. The offset of a token whose value is empty, which is only possible for a comment, is that of the delimiter which opens it, see issue #1391.

A token may span several lines, which is the case of a comment and of a raw string literal: the line and the offset of such a token are those of its first line, whereas its value gathers the lines it spans. The offset of a comment without contents on the line it starts on, as the offset of an empty comment, is that of the delimiter which opens it.

◆ value

std::string tfel::utilities::Token::value

string holded by the token

The value of a token is the spelling of the token in the file, that is the substring of the line taken at the offset of the token, excepted for comments and for numbers:

  • the value of a comment, that is of a token whose flag is Comment, DoxygenComment or DoxygenBackwardComment, is the contents of the comment: the delimiters of the comment and the spaces which surround its contents are not a part of the value. An empty comment, as // or a C style comment without any contents, thus gives a token with an empty value,
  • the value of a string token holds the whole literal: the double quotes of a quoted string as well as the R"delim( prefix and the )delim" suffix of a raw string literal are a part of the value, so that the contents of a string token can be read back without relying on the flag of the token only, see issue #1390,
  • the value of a number does not hold the digit separators of the C++14 integer literals, see the description of the CxxTokenizer class.

The documentation for this struct was generated from the following file: