From 720c5a33b6a49cf328fdd7611f49153cf8f60247 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 8 Apr 2020 14:51:57 +0300 Subject: Separate tests and examples into individual packages Also make cli module to be explicitly enabled via the config.cli configuration variable. --- cli/cli/token.hxx | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 cli/cli/token.hxx (limited to 'cli/cli/token.hxx') diff --git a/cli/cli/token.hxx b/cli/cli/token.hxx new file mode 100644 index 0000000..7045826 --- /dev/null +++ b/cli/cli/token.hxx @@ -0,0 +1,135 @@ +// file : cli/token.hxx +// author : Boris Kolpackov +// license : MIT; see accompanying LICENSE file + +#ifndef CLI_TOKEN_HXX +#define CLI_TOKEN_HXX + +#include +#include // std::size_t + +class token +{ +public: + enum token_type + { + t_eos, + t_keyword, + t_identifier, + t_punctuation, + t_cxx_path_lit, + t_cli_path_lit, + t_string_lit, + t_char_lit, + t_bool_lit, + t_int_lit, + t_float_lit, + t_call_expr, // The so called "call expression", e.g., (2, a). + t_template_expr // The so called "template expression", e.g., . + }; + + token_type + type () const; + + std::size_t + line () const; + + std::size_t + column () const; + + // Keyword + // +public: + enum keyword_type + { + k_source, + k_include, + k_namespace, + k_class, + k_signed, + k_unsigned, + k_bool, + k_char, + k_wchar, + k_short, + k_int, + k_long, + k_float, + k_double, + k_invalid + }; + + // Return the keyword id if type is t_keyword and k_invalid otherwise. + // + keyword_type + keyword () const; + + // Identifier + // +public: + std::string const& + identifier () const; + + // Punctuation + // +public: + enum punctuation_type + { + p_semi, + p_comma, + p_colon, + p_dcolon, + p_lcbrace, + p_rcbrace, + // p_lparen, + // p_rparen, + p_eq, + p_or, + p_invalid + }; + + // Return the punctuation id if type is t_punctuation and p_invalid + // otherwise. + // + punctuation_type + punctuation () const; + + // Literals. + // +public: + std::string const& + literal () const; + + // Expressions. + // +public: + std::string const& + expression () const; + + // C-tors. + // +public: + // EOS. + // + token (std::size_t l, std::size_t c); + + token (keyword_type k, std::size_t l, std::size_t c); + token (punctuation_type p, std::size_t l, std::size_t c); + + // Identifier, literals, and expressions. + // + token (token_type t, std::string const& s, std::size_t l, std::size_t c); + +private: + std::size_t l_; + std::size_t c_; + + token_type type_; + keyword_type keyword_; + punctuation_type punctuation_; + std::string str_; +}; + +#include + +#endif // CLI_TOKEN_HXX -- cgit v1.1