aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/lex
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/lex')
-rw-r--r--gcc/rust/lex/rust-lex.cc17
-rw-r--r--gcc/rust/lex/rust-lex.h9
-rw-r--r--gcc/rust/lex/rust-token.cc3
-rw-r--r--gcc/rust/lex/rust-token.h15
4 files changed, 28 insertions, 16 deletions
diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index e5c9148..b9f012b 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -21,7 +21,7 @@
#include "rust-lex.h"
#include "rust-diagnostics.h"
#include "rust-linemap.h"
-#include "rust-session-manager.h"
+#include "rust-edition.h"
#include "safe-ctype.h"
#include "cpplib.h"
#include "rust-keyword-values.h"
@@ -277,9 +277,7 @@ Lexer::classify_keyword (const std::string &str)
// https://doc.rust-lang.org/reference/keywords.html#reserved-keywords
// `try` is not a reserved keyword before 2018
- if (Session::get_instance ().options.get_edition ()
- == CompileOptions::Edition::E2015
- && id == TRY)
+ if (get_rust_edition () == Edition::E2015 && id == TRY)
return IDENTIFIER;
return id;
@@ -589,7 +587,8 @@ Lexer::build_token ()
if (current_char.is_eof ())
{
rust_error_at (
- loc, "unexpected EOF while looking for end of comment");
+ loc, ErrorCode::E0758,
+ "unexpected EOF while looking for end of comment");
break;
}
str += current_char;
@@ -644,7 +643,8 @@ Lexer::build_token ()
if (current_char.is_eof ())
{
rust_error_at (
- loc, "unexpected EOF while looking for end of comment");
+ loc, ErrorCode::E0758,
+ "unexpected EOF while looking for end of comment");
break;
}
@@ -708,7 +708,8 @@ Lexer::build_token ()
if (current_char.is_eof ())
{
rust_error_at (
- loc, "unexpected EOF while looking for end of comment");
+ loc, ErrorCode::E0758,
+ "unexpected EOF while looking for end of comment");
break;
}
@@ -2218,7 +2219,7 @@ Lexer::parse_raw_string (location_t loc, int initial_hash_count)
str.shrink_to_fit ();
- return Token::make_string (loc, std::move (str));
+ return Token::make_raw_string (loc, std::move (str));
}
template <typename IsDigitFunc>
diff --git a/gcc/rust/lex/rust-lex.h b/gcc/rust/lex/rust-lex.h
index feaa3e0..53f0774 100644
--- a/gcc/rust/lex/rust-lex.h
+++ b/gcc/rust/lex/rust-lex.h
@@ -115,14 +115,15 @@ private:
// Request new Location for current column in line_table
location_t get_current_location ();
- // Skips the current input char.
+ // Skips the current input character.
void skip_input ();
- // Advances current input char to n + 1 chars ahead of current position.
+ // Advances current input character to n + 1 characters ahead of current
+ // position.
void skip_input (int n);
- // Peeks the current char.
+ // Peeks the current character.
Codepoint peek_input ();
- // Returns char n bytes ahead of current position.
+ // Returns character n characters ahead of current position.
Codepoint peek_input (int n);
// Classifies keyword (i.e. gets id for keyword).
diff --git a/gcc/rust/lex/rust-token.cc b/gcc/rust/lex/rust-token.cc
index 7bb3273..e1eb78f 100644
--- a/gcc/rust/lex/rust-token.cc
+++ b/gcc/rust/lex/rust-token.cc
@@ -247,6 +247,9 @@ Token::as_string () const
case BYTE_STRING_LITERAL:
return "b\"" + escape_special_chars (get_str (), Context::String)
+ "\"";
+ case RAW_STRING_LITERAL:
+ return "r\"" + escape_special_chars (get_str (), Context::String)
+ + "\"";
case CHAR_LITERAL:
return "'" + escape_special_chars (get_str (), Context::Char) + "'";
case BYTE_CHAR_LITERAL:
diff --git a/gcc/rust/lex/rust-token.h b/gcc/rust/lex/rust-token.h
index 438b29b..09814c5 100644
--- a/gcc/rust/lex/rust-token.h
+++ b/gcc/rust/lex/rust-token.h
@@ -21,7 +21,6 @@
#include "rust-system.h"
#include "rust-linemap.h"
-#include "rust-make-unique.h"
#include "rust-unicode.h"
namespace Rust {
@@ -128,6 +127,7 @@ enum PrimitiveCoreType
RS_TOKEN (STRING_LITERAL, "string literal") \
RS_TOKEN (CHAR_LITERAL, "character literal") \
RS_TOKEN (BYTE_STRING_LITERAL, "byte string literal") \
+ RS_TOKEN (RAW_STRING_LITERAL, "raw string literal") \
RS_TOKEN (BYTE_CHAR_LITERAL, "byte character literal") \
RS_TOKEN (LIFETIME, "lifetime") /* TODO: improve token type */ \
/* Have "interpolated" tokens (whatever that means)? identifer, path, type, \
@@ -267,7 +267,7 @@ private:
: token_id (token_id), locus (location), type_hint (CORETYPE_UNKNOWN)
{
// Normalize identifier tokens
- str = Rust::make_unique<std::string> (
+ str = std::make_unique<std::string> (
nfc_normalize_token_string (location, token_id, paramStr));
}
@@ -284,7 +284,7 @@ private:
: token_id (token_id), locus (location), type_hint (CORETYPE_UNKNOWN)
{
// Normalize identifier tokens
- str = Rust::make_unique<std::string> (
+ str = std::make_unique<std::string> (
nfc_normalize_token_string (location, token_id,
paramCodepoint.as_string ()));
}
@@ -295,7 +295,7 @@ private:
: token_id (token_id), locus (location), type_hint (parType)
{
// Normalize identifier tokens
- str = Rust::make_unique<std::string> (
+ str = std::make_unique<std::string> (
nfc_normalize_token_string (location, token_id, paramStr));
}
@@ -377,6 +377,12 @@ public:
return TokenPtr (new Token (BYTE_STRING_LITERAL, locus, std::move (str)));
}
+ // Makes and returns a new TokenPtr of type RAW_STRING_LITERAL.
+ static TokenPtr make_raw_string (location_t locus, std::string &&str)
+ {
+ return TokenPtr (new Token (RAW_STRING_LITERAL, locus, std::move (str)));
+ }
+
// Makes and returns a new TokenPtr of type INNER_DOC_COMMENT.
static TokenPtr make_inner_doc_comment (location_t locus, std::string &&str)
{
@@ -450,6 +456,7 @@ return *str;
case STRING_LITERAL:
case BYTE_CHAR_LITERAL:
case BYTE_STRING_LITERAL:
+ case RAW_STRING_LITERAL:
return true;
default:
return false;