// <http://www.gnu.org/licenses/>.
#include "rust-ast-collector.h"
#include "rust-item.h"
+#include "rust-keyword-values.h"
namespace Rust {
namespace AST {
break;
case Lifetime::LifetimeType::STATIC:
push (Rust::Token::make_lifetime (lifetime.get_locus (),
- std::move ("static")));
+ Values::Keywords::STATIC_KW));
break;
case Lifetime::LifetimeType::WILDCARD:
- push (
- Rust::Token::make_lifetime (lifetime.get_locus (), std::move ("_")));
+ push (Rust::Token::make_lifetime (lifetime.get_locus (),
+ Values::Keywords::UNDERSCORE));
break;
}
}
lit.get_type_hint ()));
break;
case Literal::LitType::BOOL: {
- if (value == "false")
+ if (value == Values::Keywords::FALSE_LITERAL)
push (Rust::Token::make (FALSE_LITERAL, locus));
- else if (value == "true")
+ else if (value == Values::Keywords::TRUE_LITERAL)
push (Rust::Token::make (TRUE_LITERAL, locus));
else
rust_unreachable (); // Not a boolean
visit (expr.get_awaited_expr ());
push (Rust::Token::make (DOT, expr.get_locus ()));
// TODO: Check status of await keyword (Context dependant ?)
- push (Rust::Token::make_identifier (UNDEF_LOCATION, "await"));
+ push (Rust::Token::make_identifier (UNDEF_LOCATION, Values::Keywords::AWAIT));
}
void
#include "rust-token.h"
#include "rust-location.h"
#include "rust-diagnostics.h"
+#include "rust-keyword-values.h"
namespace Rust {
// TODO: remove typedefs and make actual types for these
const std::string &get_segment_name () const { return segment_name; }
bool is_super_path_seg () const
{
- return as_string ().compare ("super") == 0;
+ return as_string ().compare (Values::Keywords::SUPER) == 0;
}
bool is_crate_path_seg () const
{
- return as_string ().compare ("crate") == 0;
+ return as_string ().compare (Values::Keywords::CRATE) == 0;
+ }
+ bool is_lower_self_seg () const
+ {
+ return as_string ().compare (Values::Keywords::SELF) == 0;
+ }
+ bool is_big_self () const
+ {
+ return as_string ().compare (Values::Keywords::SELF_ALIAS) == 0;
}
- bool is_lower_self_seg () const { return as_string ().compare ("self") == 0; }
- bool is_big_self () const { return as_string ().compare ("Self") == 0; }
};
// A simple path without generic or type arguments
location_t crate_vis_location)
{
return Visibility (PUB_CRATE,
- SimplePath::from_str ("crate", crate_tok_location),
+ SimplePath::from_str (Values::Keywords::CRATE,
+ crate_tok_location),
crate_vis_location);
}
location_t self_vis_location)
{
return Visibility (PUB_SELF,
- SimplePath::from_str ("self", self_tok_location),
+ SimplePath::from_str (Values::Keywords::SELF,
+ self_tok_location),
self_vis_location);
}
location_t super_vis_location)
{
return Visibility (PUB_SUPER,
- SimplePath::from_str ("super", super_tok_location),
+ SimplePath::from_str (Values::Keywords::SUPER,
+ super_tok_location),
super_vis_location);
}
case SUPER:
lexer.skip_token ();
- return AST::PathIdentSegment ("super", t->get_locus ());
+ return AST::PathIdentSegment (Values::Keywords::SUPER, t->get_locus ());
case SELF:
lexer.skip_token ();
- return AST::PathIdentSegment ("self", t->get_locus ());
+ return AST::PathIdentSegment (Values::Keywords::SELF, t->get_locus ());
case SELF_ALIAS:
lexer.skip_token ();
- return AST::PathIdentSegment ("Self", t->get_locus ());
+ return AST::PathIdentSegment (Values::Keywords::SELF_ALIAS,
+ t->get_locus ());
case CRATE:
lexer.skip_token ();
- return AST::PathIdentSegment ("crate", t->get_locus ());
+ return AST::PathIdentSegment (Values::Keywords::CRATE, t->get_locus ());
case DOLLAR_SIGN:
if (lexer.peek_token (1)->get_id () == CRATE)
{
Identifier ident;
auto identifier = lexer.peek_token ();
if (identifier->get_id () == UNDERSCORE)
- ident = {"_", identifier->get_locus ()};
+ ident = {Values::Keywords::UNDERSCORE, identifier->get_locus ()};
else
ident = {identifier};
lexer.skip_token ();
break;
case SELF:
- crate_name = "self";
+ crate_name = Values::Keywords::SELF;
lexer.skip_token ();
break;
default:
lexer.skip_token ();
break;
case UNDERSCORE:
- as_name = "_";
+ as_name = Values::Keywords::UNDERSCORE;
lexer.skip_token ();
break;
default:
return std::unique_ptr<AST::UseTreeRebind> (
new AST::UseTreeRebind (AST::UseTreeRebind::WILDCARD,
std::move (path), locus,
- {"_", t->get_locus ()}));
+ {Values::Keywords::UNDERSCORE,
+ t->get_locus ()}));
default:
add_error (Error (
t->get_locus (),
* wildcard */
const_TokenPtr ident_tok = lexer.peek_token ();
// make default identifier the underscore wildcard one
- std::string ident ("_");
+ std::string ident (Values::Keywords::UNDERSCORE);
switch (ident_tok->get_id ())
{
case IDENTIFIER:
// use true and false keywords rather than "bool literal" Rust terminology
case TRUE_LITERAL:
type = AST::Literal::BOOL;
- literal_value = "true";
+ literal_value = Values::Keywords::TRUE_LITERAL;
lexer.skip_token ();
break;
case FALSE_LITERAL:
type = AST::Literal::BOOL;
- literal_value = "false";
+ literal_value = Values::Keywords::FALSE_LITERAL;
lexer.skip_token ();
break;
default:
else if (current->get_id () == UNDERSCORE && next->get_id () == COLON)
{
// wildcard param
- name = {"_", current->get_locus ()};
+ name = {Values::Keywords::UNDERSCORE, current->get_locus ()};
kind = AST::MaybeNamedParam::WILDCARD;
lexer.skip_token (1);
}
case TRUE_LITERAL:
lexer.skip_token ();
return std::unique_ptr<AST::LiteralPattern> (
- new AST::LiteralPattern ("true", AST::Literal::BOOL, t->get_locus (),
+ new AST::LiteralPattern (Values::Keywords::TRUE_LITERAL,
+ AST::Literal::BOOL, t->get_locus (),
t->get_type_hint ()));
case FALSE_LITERAL:
lexer.skip_token ();
return std::unique_ptr<AST::LiteralPattern> (
- new AST::LiteralPattern ("false", AST::Literal::BOOL, t->get_locus (),
+ new AST::LiteralPattern (Values::Keywords::FALSE_LITERAL,
+ AST::Literal::BOOL, t->get_locus (),
t->get_type_hint ()));
case CHAR_LITERAL:
case BYTE_CHAR_LITERAL:
tok->get_type_hint (), {}, tok->get_locus ()));
case TRUE_LITERAL:
return std::unique_ptr<AST::LiteralExpr> (
- new AST::LiteralExpr ("true", AST::Literal::BOOL, tok->get_type_hint (),
- {}, tok->get_locus ()));
+ new AST::LiteralExpr (Values::Keywords::TRUE_LITERAL,
+ AST::Literal::BOOL, tok->get_type_hint (), {},
+ tok->get_locus ()));
case FALSE_LITERAL:
return std::unique_ptr<AST::LiteralExpr> (
- new AST::LiteralExpr ("false", AST::Literal::BOOL,
- tok->get_type_hint (), {}, tok->get_locus ()));
+ new AST::LiteralExpr (Values::Keywords::FALSE_LITERAL,
+ AST::Literal::BOOL, tok->get_type_hint (), {},
+ tok->get_locus ()));
case LEFT_PAREN:
return parse_grouped_or_tuple_expr (std::move (outer_attrs),
tok->get_locus ());
const_TokenPtr next_tok = lexer.peek_token ();
if (next_tok->get_id () == IDENTIFIER
- && next_tok->get_str () == "await")
+ && next_tok->get_str () == Values::Keywords::AWAIT)
{
// await expression
return parse_await_expr (tok, std::move (left),
initial_str = tok->get_str ();
break;
case SUPER:
- initial_str = "super";
+ initial_str = Values::Keywords::SUPER;
break;
case SELF:
- initial_str = "self";
+ initial_str = Values::Keywords::SELF;
break;
case SELF_ALIAS:
- initial_str = "Self";
+ initial_str = Values::Keywords::SELF_ALIAS;
break;
case CRATE:
- initial_str = "crate";
+ initial_str = Values::Keywords::CRATE;
break;
case DOLLAR_SIGN:
if (lexer.peek_token ()->get_id () == CRATE)