From 64aa9e062d09d33de99ab4ddc0dc73828af2543e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 22 Aug 2009 17:54:26 +0200 Subject: Convert to the lower case naming convention --- cli/cli.cxx | 6 +- cli/lexer.cxx | 152 +++++++++++++------------- cli/lexer.hxx | 66 ++++++------ cli/lexer.ixx | 42 ++++---- cli/parser.cxx | 278 ++++++++++++++++++++++++------------------------ cli/parser.hxx | 22 ++-- cli/token.hxx | 29 +++-- cli/token.ixx | 32 +++--- tests/lexer/driver.cxx | 28 ++--- tests/parser/driver.cxx | 6 +- 10 files changed, 330 insertions(+), 331 deletions(-) diff --git a/cli/cli.cxx b/cli/cli.cxx index b070913..39fff16 100644 --- a/cli/cli.cxx +++ b/cli/cli.cxx @@ -29,15 +29,15 @@ int main (int argc, char* argv[]) ifs.exceptions (ifstream::failbit | ifstream::badbit); - Parser parser; - parser.parse (ifs, argv[1]); + parser p; + p.parse (ifs, argv[1]); } catch (std::ios_base::failure const&) { wcerr << argv[1] << ": error: read failure" << endl; return 1; } - catch (Parser::InvalidInput const&) + catch (parser::invalid_input const&) { // Diagnostics has already been issued by the parser. // diff --git a/cli/lexer.cxx b/cli/lexer.cxx index 8adb783..8b17d8f 100644 --- a/cli/lexer.cxx +++ b/cli/lexer.cxx @@ -9,8 +9,8 @@ using namespace std; -Lexer:: -Lexer (istream& is, string const& id) +lexer:: +lexer (istream& is, string const& id) : loc_ ("C"), is_ (is), id_ (id), @@ -22,22 +22,22 @@ Lexer (istream& is, string const& id) buf_ (0, 0, 0), unget_ (false) { - keyword_map_["include"] = Token::k_include; - keyword_map_["namespace"] = Token::k_namespace; - keyword_map_["class"] = Token::k_class; - keyword_map_["signed"] = Token::k_signed; - keyword_map_["unsigned"] = Token::k_unsigned; - keyword_map_["bool"] = Token::k_bool; - keyword_map_["char"] = Token::k_char; - keyword_map_["wchar_t"] = Token::k_wchar; - keyword_map_["short"] = Token::k_short; - keyword_map_["int"] = Token::k_int; - keyword_map_["long"] = Token::k_long; - keyword_map_["float"] = Token::k_float; - keyword_map_["double"] = Token::k_double; + keyword_map_["include"] = token::k_include; + keyword_map_["namespace"] = token::k_namespace; + keyword_map_["class"] = token::k_class; + keyword_map_["signed"] = token::k_signed; + keyword_map_["unsigned"] = token::k_unsigned; + keyword_map_["bool"] = token::k_bool; + keyword_map_["char"] = token::k_char; + keyword_map_["wchar_t"] = token::k_wchar; + keyword_map_["short"] = token::k_short; + keyword_map_["int"] = token::k_int; + keyword_map_["long"] = token::k_long; + keyword_map_["float"] = token::k_float; + keyword_map_["double"] = token::k_double; } -Lexer::Char Lexer:: +lexer::xchar lexer:: peek () { if (unget_) @@ -45,20 +45,20 @@ peek () else { if (eos_) - return Char (Char::Traits::eof (), l_, c_); + return xchar (xchar::traits_type::eof (), l_, c_); else { - Char::IntType i (is_.peek ()); + xchar::int_type i (is_.peek ()); - if (i == Char::Traits::eof ()) + if (i == xchar::traits_type::eof ()) eos_ = true; - return Char (i, l_, c_); + return xchar (i, l_, c_); } } } -Lexer::Char Lexer:: +lexer::xchar lexer:: get () { if (unget_) @@ -74,7 +74,7 @@ get () // eof. But we can only call peek() on eof once; any subsequent // calls will spoil the failbit (even more stupid). // - Char c (peek ()); + xchar c (peek ()); if (!is_eos (c)) { @@ -93,8 +93,8 @@ get () } } -void Lexer:: -unget (Char c) +void lexer:: +unget (xchar c) { // Because iostream::unget cannot work once eos is reached, // we have to provide our own implementation. @@ -103,7 +103,7 @@ unget (Char c) unget_ = true; } -Token Lexer:: +token lexer:: next () { while (true) // Recovery loop. @@ -113,10 +113,10 @@ next () skip_spaces (); - Char c (get ()); + xchar c (get ()); if (is_eos (c)) - return Token (c.line (), c.column ()); + return token (c.line (), c.column ()); try { @@ -142,28 +142,28 @@ next () } case ';': { - return Token (Token::p_semi, c.line (), c.column ()); + return token (token::p_semi, c.line (), c.column ()); } case ',': { - return Token (Token::p_comma, c.line (), c.column ()); + return token (token::p_comma, c.line (), c.column ()); } case ':': { if (peek () == ':') { get (); - return Token (Token::p_dcolon, c.line (), c.column ()); + return token (token::p_dcolon, c.line (), c.column ()); } break; } case '{': { - return Token (Token::p_lcbrace, c.line (), c.column ()); + return token (token::p_lcbrace, c.line (), c.column ()); } case '}': { - return Token (Token::p_rcbrace, c.line (), c.column ()); + return token (token::p_rcbrace, c.line (), c.column ()); } case '(': { @@ -171,18 +171,18 @@ next () } case '=': { - return Token (Token::p_eq, c.line (), c.column ()); + return token (token::p_eq, c.line (), c.column ()); } case '|': { - return Token (Token::p_or, c.line (), c.column ()); + return token (token::p_or, c.line (), c.column ()); } case '-': { // This can be a beginning of an identifier or a an integer // literal. Figure out which one it is. // - Char p (peek ()); + xchar p (peek ()); if (is_dec_digit (p)) return int_literal (get (), true, c.line (), c.column ()); @@ -198,7 +198,7 @@ next () // cerr << id_ << ':' << c.line () << ':' << c.column () << ": error: unexpected character '-'" << endl; - throw InvalidInput (); + throw invalid_input (); } break; @@ -217,9 +217,9 @@ next () cerr << id_ << ':' << c.line () << ':' << c.column () << ": error: unexpected character '" << c << "'" << endl; - throw InvalidInput (); + throw invalid_input (); } - catch (InvalidInput const&) + catch (invalid_input const&) { valid_ = false; } @@ -231,15 +231,15 @@ next () c = get (); if (is_eos (c)) - return Token (c.line (), c.column ()); + return token (c.line (), c.column ()); } while (c != ';'); } } -void Lexer:: +void lexer:: skip_spaces () { - for (Char c (peek ());; c = peek ()) + for (xchar c (peek ());; c = peek ()) { if (is_eos (c)) break; @@ -247,7 +247,7 @@ skip_spaces () if (c == '/') { c = get (); - Char p (peek ()); + xchar p (peek ()); if (p == '/') { @@ -271,7 +271,7 @@ skip_spaces () cerr << id_ << ':' << c.line () << ':' << c.column () << ": error: end of stream reached while reading " << "C-style comment" << endl; - throw InvalidInput (); + throw invalid_input (); } if (c == '*') @@ -300,8 +300,8 @@ skip_spaces () } } -Token Lexer:: -identifier (Char c) +token lexer:: +identifier (xchar c) { size_t ln (c.line ()), cl (c.column ()); string lexeme; @@ -331,28 +331,28 @@ identifier (Char c) { cerr << id_ << ':' << c.line () << ':' << c.column () << ": error: " << "invalid character sequence '" << lexeme << "'" << endl; - throw InvalidInput (); + throw invalid_input (); } } - KeywordMap::const_iterator i (keyword_map_.find (lexeme)); + keyword_map::const_iterator i (keyword_map_.find (lexeme)); if (i != keyword_map_.end ()) { - if (i->second == Token::k_include) + if (i->second == token::k_include) include_ = true; - return Token (i->second, ln, cl); + return token (i->second, ln, cl); } if (lexeme == "true" || lexeme == "false") - return Token (Token::t_bool_lit, lexeme, ln, cl); + return token (token::t_bool_lit, lexeme, ln, cl); - return Token (Token::t_identifier, lexeme, ln, cl); + return token (token::t_identifier, lexeme, ln, cl); } -Token Lexer:: -int_literal (Char c, bool neg, size_t ml, size_t mc) +token lexer:: +int_literal (xchar c, bool neg, size_t ml, size_t mc) { size_t ln (neg ? ml : c.line ()), cl (neg ? mc : c.column ()); string lexeme; @@ -368,11 +368,11 @@ int_literal (Char c, bool neg, size_t ml, size_t mc) lexeme += c; } - return Token (Token::t_int_lit, lexeme, ln, cl); + return token (token::t_int_lit, lexeme, ln, cl); } -Token Lexer:: -char_literal (Char c) +token lexer:: +char_literal (xchar c) { size_t ln (c.line ()), cl (c.column ()); string lexeme; @@ -388,7 +388,7 @@ char_literal (Char c) { cerr << id_ << ':' << c.line () << ':' << c.column () << ": error: " << "end of stream reached while reading character literal" << endl; - throw InvalidInput (); + throw invalid_input (); } lexeme += c; @@ -405,11 +405,11 @@ char_literal (Char c) p = c; } - return Token (Token::t_char_lit, lexeme, ln, cl); + return token (token::t_char_lit, lexeme, ln, cl); } -Token Lexer:: -string_literal (Char c) +token lexer:: +string_literal (xchar c) { size_t ln (c.line ()), cl (c.column ()); string lexeme; @@ -432,10 +432,10 @@ string_literal (Char c) lexeme += " \""; } - return Token (Token::t_string_lit, lexeme, ln, cl); + return token (token::t_string_lit, lexeme, ln, cl); } -string Lexer:: +string lexer:: string_literal_trailer () { string r; @@ -443,13 +443,13 @@ string_literal_trailer () while (true) { - Char c = get (); + xchar c = get (); if (is_eos (c)) { cerr << id_ << ':' << c.line () << ':' << c.column () << ": error: " << "end of stream reached while reading string literal" << endl; - throw InvalidInput (); + throw invalid_input (); } r += c; @@ -469,8 +469,8 @@ string_literal_trailer () return r; } -Token Lexer:: -path_literal (Char c) +token lexer:: +path_literal (xchar c) { size_t ln (c.line ()), cl (c.column ()); string lexeme; @@ -486,7 +486,7 @@ path_literal (Char c) { cerr << id_ << ':' << c.line () << ':' << c.column () << ": error: " << "end of stream reached while reading path literal" << endl; - throw InvalidInput (); + throw invalid_input (); } lexeme += c; @@ -495,11 +495,11 @@ path_literal (Char c) break; } - return Token (Token::t_path_lit, lexeme, ln, cl); + return token (token::t_path_lit, lexeme, ln, cl); } -Token Lexer:: -call_expression (Char c) +token lexer:: +call_expression (xchar c) { size_t ln (c.line ()), cl (c.column ()); string lexeme; @@ -514,7 +514,7 @@ call_expression (Char c) { cerr << id_ << ':' << c.line () << ':' << c.column () << ": error: " << "end of stream reached while reading call expression" << endl; - throw InvalidInput (); + throw invalid_input (); } lexeme += c; @@ -534,11 +534,11 @@ call_expression (Char c) } } - return Token (Token::t_call_expr, lexeme, ln, cl); + return token (token::t_call_expr, lexeme, ln, cl); } -Token Lexer:: -template_expression (Char c) +token lexer:: +template_expression (xchar c) { size_t ln (c.line ()), cl (c.column ()); string lexeme; @@ -554,7 +554,7 @@ template_expression (Char c) cerr << id_ << ':' << c.line () << ':' << c.column () << ": error: " << "end of stream reached while reading template expression" << endl; - throw InvalidInput (); + throw invalid_input (); } lexeme += c; @@ -574,5 +574,5 @@ template_expression (Char c) } } - return Token (Token::t_template_expr, lexeme, ln, cl); + return token (token::t_template_expr, lexeme, ln, cl); } diff --git a/cli/lexer.hxx b/cli/lexer.hxx index c69021f..c5608cf 100644 --- a/cli/lexer.hxx +++ b/cli/lexer.hxx @@ -14,30 +14,30 @@ #include "token.hxx" -class Lexer +class lexer { public: - Lexer (std::istream& is, std::string const& id); + lexer (std::istream& is, std::string const& id); - Token + token next (); bool valid () const; protected: - class Char + class xchar { public: - typedef std::char_traits Traits; - typedef Traits::int_type IntType; - typedef Traits::char_type CharType; + typedef std::char_traits traits_type; + typedef traits_type::int_type int_type; + typedef traits_type::char_type char_type; - Char (IntType v, std::size_t l, std::size_t c); + xchar (int_type v, std::size_t l, std::size_t c); - operator CharType () const; + operator char_type () const; - IntType + int_type value () const; std::size_t @@ -47,52 +47,52 @@ protected: column () const; private: - IntType v_; + int_type v_; std::size_t l_; std::size_t c_; }; - Char + xchar peek (); - Char + xchar get (); void - unget (Char); + unget (xchar); protected: - class InvalidInput {}; + class invalid_input {}; void skip_spaces (); - Token - identifier (Char); + token + identifier (xchar); - Token - int_literal (Char, + token + int_literal (xchar, bool neg = false, std::size_t ml = 0, std::size_t mc = 0); - Token - char_literal (Char); + token + char_literal (xchar); - Token - string_literal (Char); + token + string_literal (xchar); std::string string_literal_trailer (); - Token - path_literal (Char); + token + path_literal (xchar); - Token - call_expression (Char); + token + call_expression (xchar); - Token - template_expression (Char); + token + template_expression (xchar); protected: bool @@ -114,13 +114,13 @@ protected: is_space (char c) const; bool - is_eos (Char const& c) const; + is_eos (xchar const& c) const; char to_upper (char c) const; private: - typedef std::map KeywordMap; + typedef std::map keyword_map; std::locale loc_; std::istream& is_; @@ -128,13 +128,13 @@ private: std::size_t l_; std::size_t c_; - KeywordMap keyword_map_; + keyword_map keyword_map_; bool eos_; bool include_; bool valid_; - Char buf_; + xchar buf_; bool unget_; }; diff --git a/cli/lexer.ixx b/cli/lexer.ixx index 7e84cfc..f346575 100644 --- a/cli/lexer.ixx +++ b/cli/lexer.ixx @@ -3,89 +3,89 @@ // copyright : Copyright (c) 2009 Code Synthesis Tools CC // license : MIT; see accompanying LICENSE file -// Lexer::Char +// lexer::xchar // -inline Lexer::Char:: -Char (IntType v, std::size_t l, std::size_t c) +inline lexer::xchar:: +xchar (int_type v, std::size_t l, std::size_t c) : v_ (v), l_ (l), c_ (c) { } -inline Lexer::Char:: -operator CharType () const +inline lexer::xchar:: +operator char_type () const { - return Traits::to_char_type (v_); + return traits_type::to_char_type (v_); } -inline Lexer::Char::IntType Lexer::Char:: +inline lexer::xchar::int_type lexer::xchar:: value () const { return v_; } -inline std::size_t Lexer::Char:: +inline std::size_t lexer::xchar:: line () const { return l_; } -inline std::size_t Lexer::Char:: +inline std::size_t lexer::xchar:: column () const { return c_; } -// Lexer +// lexer // -inline bool Lexer:: +inline bool lexer:: valid () const { return valid_; } -inline bool Lexer:: +inline bool lexer:: is_alpha (char c) const { return std::isalpha (c, loc_); } -inline bool Lexer:: +inline bool lexer:: is_oct_digit (char c) const { return std::isdigit (c, loc_) && c != '8' && c != '9'; } -inline bool Lexer:: +inline bool lexer:: is_dec_digit (char c) const { return std::isdigit (c, loc_); } -inline bool Lexer:: +inline bool lexer:: is_hex_digit (char c) const { return std::isxdigit (c, loc_); } -inline bool Lexer:: +inline bool lexer:: is_alnum (char c) const { return std::isalnum (c, loc_); } -inline bool Lexer:: +inline bool lexer:: is_space (char c) const { return std::isspace (c, loc_); } -inline bool Lexer:: -is_eos (Char const& c) const +inline bool lexer:: +is_eos (xchar const& c) const { - return c.value () == Char::Traits::eof (); + return c.value () == xchar::traits_type::eof (); } -inline char Lexer:: +inline char lexer:: to_upper (char c) const { return std::toupper (c, loc_); diff --git a/cli/parser.cxx b/cli/parser.cxx index 4e999c2..82a68dc 100644 --- a/cli/parser.cxx +++ b/cli/parser.cxx @@ -33,66 +33,66 @@ const char* punctuation[] = {";", ",", "::", "{", "}", /*"(", ")",*/ "=", "|"}; // Output the token type and value in a format suitable for diagnostics. // std::ostream& -operator<< (std::ostream& os, Token const& t) +operator<< (std::ostream& os, token const& t) { switch (t.type ()) { - case Token::t_eos: + case token::t_eos: { os << "end-of-stream"; break; } - case Token::t_keyword: + case token::t_keyword: { os << "keyword '" << keywords[t.keyword ()] << "'"; break; } - case Token::t_identifier: + case token::t_identifier: { os << "identifier '" << t.identifier () << "'"; break; } - case Token::t_punctuation: + case token::t_punctuation: { os << "'" << punctuation[t.punctuation ()] << "'"; break; } - case Token::t_path_lit: + case token::t_path_lit: { os << "path literal"; break; } - case Token::t_string_lit: + case token::t_string_lit: { os << "string literal"; break; } - case Token::t_char_lit: + case token::t_char_lit: { os << "char literal"; break; } - case Token::t_bool_lit: + case token::t_bool_lit: { os << "bool literal"; break; } - case Token::t_int_lit: + case token::t_int_lit: { os << "integer literal"; break; } - case Token::t_float_lit: + case token::t_float_lit: { os << "floating point literal"; break; } - case Token::t_call_expr: + case token::t_call_expr: { os << "call expression"; break; } - case Token::t_template_expr: + case token::t_template_expr: { os << "template expression"; break; @@ -102,17 +102,17 @@ operator<< (std::ostream& os, Token const& t) return os; } -void Parser:: -recover (Token& t) +void parser:: +recover (token& t) { // Recover by skipping past next ';'. // for (;; t = lexer_->next ()) { - if (t.type () == Token::t_eos) + if (t.type () == token::t_eos) break; - if (t.punctuation () == Token::p_semi) + if (t.punctuation () == token::p_semi) { t = lexer_->next (); break; @@ -120,34 +120,34 @@ recover (Token& t) } } -void Parser:: +void parser:: parse (std::istream& is, std::string const& id) { - Lexer lexer (is, id); - lexer_ = &lexer; + lexer l (is, id); + lexer_ = &l; id_ = &id; valid_ = true; def_unit (); - if (!valid_ || !lexer.valid ()) - throw InvalidInput (); + if (!valid_ || !l.valid ()) + throw invalid_input (); } -void Parser:: +void parser:: def_unit () { - Token t (lexer_->next ()); + token t (lexer_->next ()); // include-decl-seq // - while (t.keyword () == Token::k_include) + while (t.keyword () == token::k_include) { try { include_decl (); t = lexer_->next (); } - catch (Error const&) + catch (error const&) { valid_ = false; recover (t); @@ -156,7 +156,7 @@ def_unit () // decl-seq // - while (t.type () != Token::t_eos) + while (t.type () != token::t_eos) { try { @@ -169,9 +169,9 @@ def_unit () cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected namespace or class declaration instead of " << t << endl; - throw Error (); + throw error (); } - catch (Error const&) + catch (error const&) { valid_ = false; break; // Non-recoverable error. @@ -179,41 +179,41 @@ def_unit () } } -void Parser:: +void parser:: include_decl () { - Token t (lexer_->next ()); + token t (lexer_->next ()); - if (t.type () != Token::t_path_lit) + if (t.type () != token::t_path_lit) { cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected path literal instead of " << t << endl; - throw Error (); + throw error (); } t = lexer_->next (); - if (t.punctuation () != Token::p_semi) + if (t.punctuation () != token::p_semi) { cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected ';' instead of " << t << endl; - throw Error (); + throw error (); } } -bool Parser:: -decl (Token& t) +bool parser:: +decl (token& t) { - if (t.type () == Token::t_keyword) + if (t.type () == token::t_keyword) { switch (t.keyword ()) { - case Token::k_namespace: + case token::k_namespace: { namespace_def (); return true; } - case Token::k_class: + case token::k_class: { class_def (); return true; @@ -225,25 +225,25 @@ decl (Token& t) return false; } -void Parser:: +void parser:: namespace_def () { - Token t (lexer_->next ()); + token t (lexer_->next ()); - if (t.type () != Token::t_identifier) + if (t.type () != token::t_identifier) { cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected identifier instead of " << t << endl; - throw Error (); + throw error (); } t = lexer_->next (); - if (t.punctuation () != Token::p_lcbrace) + if (t.punctuation () != token::p_lcbrace) { cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected '{' instead of " << t << endl; - throw Error (); + throw error (); } // decl-seq @@ -253,34 +253,34 @@ namespace_def () while (decl (t)) t = lexer_->next (); - if (t.punctuation () != Token::p_rcbrace) + if (t.punctuation () != token::p_rcbrace) { cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected namespace declaration, class declaration, or '}' " << "instead of " << t << endl; - throw Error (); + throw error (); } } -void Parser:: +void parser:: class_def () { - Token t (lexer_->next ()); + token t (lexer_->next ()); - if (t.type () != Token::t_identifier) + if (t.type () != token::t_identifier) { cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected identifier instead of " << t << endl; - throw Error (); + throw error (); } t = lexer_->next (); - if (t.punctuation () != Token::p_lcbrace) + if (t.punctuation () != token::p_lcbrace) { cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected '{' instead of " << t << endl; - throw Error (); + throw error (); } // decl-seq @@ -296,32 +296,32 @@ class_def () t = lexer_->next (); } - catch (Error const&) + catch (error const&) { valid_ = false; recover (t); } } - if (t.punctuation () != Token::p_rcbrace) + if (t.punctuation () != token::p_rcbrace) { cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected option declaration or '}' instead of " << t << endl; - throw Error (); + throw error (); } t = lexer_->next (); - if (t.punctuation () != Token::p_semi) + if (t.punctuation () != token::p_semi) { cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected ';' instead of " << t << endl; - throw Error (); + throw error (); } } -bool Parser:: -option_def (Token& t) +bool parser:: +option_def (token& t) { // type-spec // @@ -337,8 +337,8 @@ option_def (Token& t) { switch (t.type ()) { - case Token::t_identifier: - case Token::t_string_lit: + case token::t_identifier: + case token::t_string_lit: { break; } @@ -346,13 +346,13 @@ option_def (Token& t) { cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " << "option name expected instead of " << t << endl; - throw Error (); + throw error (); } } t = lexer_->next (); - if (t.punctuation () == Token::p_or) + if (t.punctuation () == token::p_or) t = lexer_->next (); else break; @@ -360,7 +360,7 @@ option_def (Token& t) // initializer // - if (t.punctuation () == Token::p_eq) + if (t.punctuation () == token::p_eq) { t = lexer_->next (); @@ -373,12 +373,12 @@ option_def (Token& t) { switch (t.type ()) { - case Token::t_string_lit: - case Token::t_char_lit: - case Token::t_bool_lit: - case Token::t_int_lit: - case Token::t_float_lit: - case Token::t_call_expr: + case token::t_string_lit: + case token::t_char_lit: + case token::t_bool_lit: + case token::t_int_lit: + case token::t_float_lit: + case token::t_call_expr: { t = lexer_->next (); break; @@ -387,56 +387,56 @@ option_def (Token& t) { cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: expected intializer instead of " << t << endl; - throw Error (); + throw error (); } } } } - else if (t.type () == Token::t_call_expr) + else if (t.type () == token::t_call_expr) { // c-tor initializer // t = lexer_->next (); } - if (t.punctuation () != Token::p_semi) + if (t.punctuation () != token::p_semi) { cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected ';' instead of " << t << endl; - throw Error (); + throw error (); } return true; } -bool Parser:: -qualified_name (Token& t) +bool parser:: +qualified_name (token& t) { - if (t.type () != Token::t_identifier && t.punctuation () != Token::p_dcolon) + if (t.type () != token::t_identifier && t.punctuation () != token::p_dcolon) return false; - if (t.punctuation () == Token::p_dcolon) + if (t.punctuation () == token::p_dcolon) t = lexer_->next (); while (true) { - if (t.type () != Token::t_identifier) + if (t.type () != token::t_identifier) { cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected identifier after '::'" << endl; - throw Error (); + throw error (); } t = lexer_->next (); - if (t.type () == Token::t_template_expr) + if (t.type () == token::t_template_expr) { // Template-id. // t = lexer_->next (); } - if (t.punctuation () == Token::p_dcolon) + if (t.punctuation () == token::p_dcolon) t = lexer_->next (); else break; @@ -445,21 +445,21 @@ qualified_name (Token& t) return true; } -bool Parser:: -fundamental_type (Token& t) +bool parser:: +fundamental_type (token& t) { switch (t.keyword ()) { - case Token::k_signed: - case Token::k_unsigned: + case token::k_signed: + case token::k_unsigned: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_short: + case token::k_short: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_int: + case token::k_int: { t = lexer_->next (); } @@ -468,20 +468,20 @@ fundamental_type (Token& t) } break; } - case Token::k_long: + case token::k_long: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_int: + case token::k_int: { t = lexer_->next (); break; } - case Token::k_long: + case token::k_long: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_int: + case token::k_int: { t = lexer_->next (); } @@ -495,20 +495,20 @@ fundamental_type (Token& t) } break; } - case Token::k_int: + case token::k_int: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_short: + case token::k_short: { t = lexer_->next (); break; } - case Token::k_long: + case token::k_long: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_long: + case token::k_long: { t = lexer_->next (); } @@ -522,7 +522,7 @@ fundamental_type (Token& t) } break; } - case Token::k_char: + case token::k_char: { t = lexer_->next (); break; @@ -532,19 +532,19 @@ fundamental_type (Token& t) } break; } - case Token::k_short: - case Token::k_long: + case token::k_short: + case token::k_long: { - bool l (t.keyword () == Token::k_long); + bool l (t.keyword () == token::k_long); switch ((t = lexer_->next ()).keyword ()) { - case Token::k_signed: - case Token::k_unsigned: + case token::k_signed: + case token::k_unsigned: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_int: + case token::k_int: { t = lexer_->next (); } @@ -553,16 +553,16 @@ fundamental_type (Token& t) } break; } - case Token::k_long: + case token::k_long: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_signed: - case Token::k_unsigned: + case token::k_signed: + case token::k_unsigned: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_int: + case token::k_int: { t = lexer_->next (); } @@ -571,12 +571,12 @@ fundamental_type (Token& t) } break; } - case Token::k_int: + case token::k_int: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_signed: - case Token::k_unsigned: + case token::k_signed: + case token::k_unsigned: { t = lexer_->next (); } @@ -590,12 +590,12 @@ fundamental_type (Token& t) } break; } - case Token::k_int: + case token::k_int: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_signed: - case Token::k_unsigned: + case token::k_signed: + case token::k_unsigned: { t = lexer_->next (); } @@ -604,7 +604,7 @@ fundamental_type (Token& t) } break; } - case Token::k_double: + case token::k_double: { if (l) t = lexer_->next (); @@ -616,25 +616,25 @@ fundamental_type (Token& t) } break; } - case Token::k_int: + case token::k_int: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_signed: - case Token::k_unsigned: + case token::k_signed: + case token::k_unsigned: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_short: + case token::k_short: { t = lexer_->next (); break; } - case Token::k_long: + case token::k_long: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_long: + case token::k_long: { t = lexer_->next (); } @@ -647,12 +647,12 @@ fundamental_type (Token& t) } break; } - case Token::k_short: + case token::k_short: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_signed: - case Token::k_unsigned: + case token::k_signed: + case token::k_unsigned: { t = lexer_->next (); } @@ -661,22 +661,22 @@ fundamental_type (Token& t) } break; } - case Token::k_long: + case token::k_long: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_signed: - case Token::k_unsigned: + case token::k_signed: + case token::k_unsigned: { t = lexer_->next (); break; } - case Token::k_long: + case token::k_long: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_signed: - case Token::k_unsigned: + case token::k_signed: + case token::k_unsigned: { t = lexer_->next (); } @@ -695,12 +695,12 @@ fundamental_type (Token& t) } break; } - case Token::k_char: + case token::k_char: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_signed: - case Token::k_unsigned: + case token::k_signed: + case token::k_unsigned: { t = lexer_->next (); } @@ -709,18 +709,18 @@ fundamental_type (Token& t) } break; } - case Token::k_bool: - case Token::k_wchar: - case Token::k_float: + case token::k_bool: + case token::k_wchar: + case token::k_float: { t = lexer_->next (); break; } - case Token::k_double: + case token::k_double: { switch ((t = lexer_->next ()).keyword ()) { - case Token::k_long: + case token::k_long: { t = lexer_->next (); } diff --git a/cli/parser.hxx b/cli/parser.hxx index d1f4b4b..f09816f 100644 --- a/cli/parser.hxx +++ b/cli/parser.hxx @@ -9,19 +9,19 @@ #include #include -class Token; -class Lexer; +class token; +class lexer; -class Parser +class parser { public: - struct InvalidInput {}; + struct invalid_input {}; void parse (std::istream& is, std::string const& id); private: - struct Error {}; + struct error {}; void def_unit (); @@ -30,7 +30,7 @@ private: include_decl (); bool - decl (Token&); + decl (token&); void namespace_def (); @@ -39,21 +39,21 @@ private: class_def (); bool - option_def (Token&); + option_def (token&); bool - qualified_name (Token&); + qualified_name (token&); bool - fundamental_type (Token&); + fundamental_type (token&); private: void - recover (Token& t); + recover (token& t); private: bool valid_; - Lexer* lexer_; + lexer* lexer_; std::string const* id_; }; diff --git a/cli/token.hxx b/cli/token.hxx index 08918f8..b7b656a 100644 --- a/cli/token.hxx +++ b/cli/token.hxx @@ -9,10 +9,10 @@ #include #include // std::size_t -class Token +class token { public: - enum Type + enum token_type { t_eos, t_keyword, @@ -28,7 +28,7 @@ public: t_template_expr // The so called "template expression", e.g., . }; - Type + token_type type () const; std::size_t @@ -40,7 +40,7 @@ public: // Keyword // public: - enum Keyword + enum keyword_type { k_include, k_namespace, @@ -60,7 +60,7 @@ public: // Return the keyword id if type is t_keyword and k_invalid otherwise. // - Keyword + keyword_type keyword () const; // Identifier @@ -72,7 +72,7 @@ public: // Punctuation // public: - enum Punctuation + enum punctuation_type { p_semi, p_comma, @@ -89,7 +89,7 @@ public: // Return the punctuation id if type is t_punctuation and p_invalid // otherwise. // - Punctuation + punctuation_type punctuation () const; // Literals. @@ -109,23 +109,22 @@ public: public: // EOS. // - Token (std::size_t l, std::size_t c); + token (std::size_t l, std::size_t c); - Token (Keyword k, std::size_t l, std::size_t c); - Token (Punctuation p, 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 (Type t, std::string const& s, std::size_t l, std::size_t c); + 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_; - Type type_; - - Keyword keyword_; - Punctuation punctuation_; + token_type type_; + keyword_type keyword_; + punctuation_type punctuation_; std::string str_; }; diff --git a/cli/token.ixx b/cli/token.ixx index 93db6d8..4715813 100644 --- a/cli/token.ixx +++ b/cli/token.ixx @@ -3,74 +3,74 @@ // copyright : Copyright (c) 2009 Code Synthesis Tools CC // license : MIT; see accompanying LICENSE file -inline Token::Type Token:: +inline token::token_type token:: type () const { return type_; } -inline std::size_t Token:: +inline std::size_t token:: line () const { return l_; } -inline std::size_t Token:: +inline std::size_t token:: column () const { return c_; } -inline Token::Keyword Token:: +inline token::keyword_type token:: keyword () const { return type_ == t_keyword ? keyword_ : k_invalid; } -inline std::string const& Token:: +inline std::string const& token:: identifier () const { return str_; } -inline Token::Punctuation Token:: +inline token::punctuation_type token:: punctuation () const { return type_ == t_punctuation ? punctuation_ : p_invalid; } -inline std::string const& Token:: +inline std::string const& token:: literal () const { return str_; } -inline std::string const& Token:: +inline std::string const& token:: expression () const { return str_; } -inline Token:: -Token (std::size_t l, std::size_t c) +inline token:: +token (std::size_t l, std::size_t c) : l_ (l), c_ (c), type_ (t_eos) { } -inline Token:: -Token (Keyword k, std::size_t l, std::size_t c) +inline token:: +token (keyword_type k, std::size_t l, std::size_t c) : l_ (l), c_ (c), type_ (t_keyword), keyword_ (k) { } -inline Token:: -Token (Punctuation p, std::size_t l, std::size_t c) +inline token:: +token (punctuation_type p, std::size_t l, std::size_t c) : l_ (l), c_ (c), type_ (t_punctuation), punctuation_ (p) { } -inline Token:: -Token (Type t, std::string const& s, std::size_t l, std::size_t c) +inline token:: +token (token_type t, std::string const& s, std::size_t l, std::size_t c) : l_ (l), c_ (c), type_ (t), str_ (s) { } diff --git a/tests/lexer/driver.cxx b/tests/lexer/driver.cxx index 4b431eb..c888890 100644 --- a/tests/lexer/driver.cxx +++ b/tests/lexer/driver.cxx @@ -42,70 +42,70 @@ int main (int argc, char* argv[]) ifs.exceptions (ifstream::failbit | ifstream::badbit); ifs.open (argv[1]); - Lexer l (ifs, argv[1]); + lexer l (ifs, argv[1]); while (true) { - Token t (l.next ()); + token t (l.next ()); switch (t.type ()) { - case Token::t_eos: + case token::t_eos: { cout << "" << endl; return 0; } - case Token::t_keyword: + case token::t_keyword: { cout << "keyword: " << keywords[t.keyword ()] << endl; break; } - case Token::t_identifier: + case token::t_identifier: { cout << "identifier: " << t.identifier () << endl; break; } - case Token::t_punctuation: + case token::t_punctuation: { cout << punctuation[t.punctuation ()] << endl; break; } - case Token::t_path_lit: + case token::t_path_lit: { cout << "path: " << t.literal () << endl; break; } - case Token::t_string_lit: + case token::t_string_lit: { cout << t.literal () << endl; break; } - case Token::t_char_lit: + case token::t_char_lit: { cout << t.literal () << endl; break; } - case Token::t_bool_lit: + case token::t_bool_lit: { cout << t.literal () << endl; break; } - case Token::t_int_lit: + case token::t_int_lit: { cout << t.literal () << endl; break; } - case Token::t_float_lit: + case token::t_float_lit: { cout << t.literal () << endl; break; } - case Token::t_call_expr: + case token::t_call_expr: { cout << t.expression () << endl; break; } - case Token::t_template_expr: + case token::t_template_expr: { cout << t.expression () << endl; break; diff --git a/tests/parser/driver.cxx b/tests/parser/driver.cxx index c783503..27490b1 100644 --- a/tests/parser/driver.cxx +++ b/tests/parser/driver.cxx @@ -24,10 +24,10 @@ int main (int argc, char* argv[]) ifs.exceptions (ifstream::failbit | ifstream::badbit); ifs.open (argv[1]); - Parser parser; - parser.parse (ifs, argv[1]); + parser p; + p.parse (ifs, argv[1]); } - catch (Parser::InvalidInput const&) + catch (parser::invalid_input const&) { return 1; } -- cgit v1.1