Remove parsing of StringLiteral.

The StringLiteral token was removed from the spec when all usage was
removed. This CL removes the remaining parsing bits from Tint.

Change-Id: I02f5dbdbad649c62c22c69a55616e0087a0f56d4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42440
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2021-02-24 18:56:34 +00:00 committed by Commit Bot service account
parent 8feb9b847f
commit 72260e44ae
6 changed files with 0 additions and 93 deletions

View File

@ -63,11 +63,6 @@ Token Lexer::next() {
return t;
}
t = try_string();
if (!t.IsUninitialized()) {
return t;
}
t = try_punctuation();
if (!t.IsUninitialized()) {
return t;
@ -334,29 +329,6 @@ Token Lexer::try_ident() {
return {Token::Type::kIdentifier, source, str};
}
Token Lexer::try_string() {
if (!matches(pos_, R"(")"))
return {};
auto source = begin_source();
pos_++;
auto start = pos_;
while (pos_ < len_ && !matches(pos_, R"(")")) {
pos_++;
}
auto end = pos_;
if (matches(pos_, R"(")")) {
pos_++;
}
location_.column += (pos_ - start) + 1;
end_source(source);
return {Token::Type::kStringLiteral, source,
content_->data.substr(start, end - start)};
}
Token Lexer::try_punctuation() {
auto source = begin_source();
auto type = Token::Type::kUninitialized;

View File

@ -52,7 +52,6 @@ class Lexer {
Token try_ident();
Token try_integer();
Token try_punctuation();
Token try_string();
Source begin_source() const;
void end_source(Source&) const;

View File

@ -75,59 +75,6 @@ ident1 //ends with comment
EXPECT_TRUE(t.IsEof());
}
TEST_F(LexerTest, StringTest_Parse) {
Source::FileContent content(R"(id "this is string content" id2)");
Lexer l("test.wgsl", &content);
auto t = l.next();
EXPECT_TRUE(t.IsIdentifier());
EXPECT_EQ(t.to_str(), "id");
EXPECT_EQ(t.source().range.begin.line, 1u);
EXPECT_EQ(t.source().range.begin.column, 1u);
EXPECT_EQ(t.source().range.end.line, 1u);
EXPECT_EQ(t.source().range.end.column, 3u);
t = l.next();
EXPECT_TRUE(t.IsStringLiteral());
EXPECT_EQ(t.to_str(), "this is string content");
EXPECT_EQ(t.source().range.begin.line, 1u);
EXPECT_EQ(t.source().range.begin.column, 4u);
EXPECT_EQ(t.source().range.end.line, 1u);
EXPECT_EQ(t.source().range.end.column, 28u);
t = l.next();
EXPECT_TRUE(t.IsIdentifier());
EXPECT_EQ(t.to_str(), "id2");
EXPECT_EQ(t.source().range.begin.line, 1u);
EXPECT_EQ(t.source().range.begin.column, 29u);
EXPECT_EQ(t.source().range.end.line, 1u);
EXPECT_EQ(t.source().range.end.column, 32u);
}
TEST_F(LexerTest, StringTest_Unterminated) {
Source::FileContent content(R"(id "this is string content)");
Lexer l("test.wgsl", &content);
auto t = l.next();
EXPECT_TRUE(t.IsIdentifier());
EXPECT_EQ(t.to_str(), "id");
EXPECT_EQ(t.source().range.begin.line, 1u);
EXPECT_EQ(t.source().range.begin.column, 1u);
EXPECT_EQ(t.source().range.end.line, 1u);
EXPECT_EQ(t.source().range.end.column, 3u);
t = l.next();
EXPECT_TRUE(t.IsStringLiteral());
EXPECT_EQ(t.to_str(), "this is string content");
EXPECT_EQ(t.source().range.begin.line, 1u);
EXPECT_EQ(t.source().range.begin.column, 4u);
EXPECT_EQ(t.source().range.end.line, 1u);
EXPECT_EQ(t.source().range.end.column, 27u);
t = l.next();
EXPECT_TRUE(t.IsEof());
}
struct FloatData {
const char* input;
float result;

View File

@ -29,8 +29,6 @@ std::string Token::TypeToName(Type type) {
return "kEOF";
case Token::Type::kIdentifier:
return "kIdentifier";
case Token::Type::kStringLiteral:
return "kStringLiteral";
case Token::Type::kFloatLiteral:
return "kFloatLiteral";
case Token::Type::kSintLiteral:

View File

@ -42,8 +42,6 @@ class Token {
/// An identifier
kIdentifier,
/// A string value
kStringLiteral,
/// A float value
kFloatLiteral,
/// An signed int value
@ -381,8 +379,6 @@ class Token {
bool IsEof() const { return type_ == Type::kEOF; }
/// @returns true if the token is an identifier
bool IsIdentifier() const { return type_ == Type::kIdentifier; }
/// @returns true if the token is a string
bool IsStringLiteral() const { return type_ == Type::kStringLiteral; }
/// @returns true if the token is a float
bool IsFloatLiteral() const { return type_ == Type::kFloatLiteral; }
/// @returns true if the token is an signed int

View File

@ -25,11 +25,6 @@ namespace {
using TokenTest = testing::Test;
TEST_F(TokenTest, ReturnsStr) {
Token t(Token::Type::kStringLiteral, Source{}, "test string");
EXPECT_EQ(t.to_str(), "test string");
}
TEST_F(TokenTest, ReturnsF32) {
Token t1(Source{}, -2.345f);
EXPECT_EQ(t1.to_f32(), -2.345f);