Parse cpp_header as AidlToken in lex
Because cpp_header can be an identifier, it should be parsed as
AidlToken in lex stage so that it can carry comments.
Bug: n/a
Test: atest aidl_unittests
Change-Id: I5f5fd958c8d1b7b24e1083ce9e4201fce9dc944a
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 4c583bf..0471570 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -649,6 +649,25 @@
EXPECT_EQ("/* k */", interface->GetMethods()[2]->GetComments());
}
+TEST_P(AidlTest, CppHeaderCanBeIdentifierAsWell) {
+ io_delegate_.SetFileContents("p/cpp_header.aidl",
+ R"(package p;
+ parcelable cpp_header cpp_header "bar/header";)");
+ import_paths_.emplace("");
+ const string input_path = "p/IFoo.aidl";
+ const string input = R"(package p;
+ import p.cpp_header;
+ interface IFoo {
+ // get bar
+ cpp_header get();
+ })";
+
+ auto parse_result = Parse(input_path, input, typenames_, GetLanguage());
+ EXPECT_NE(nullptr, parse_result);
+ const AidlInterface* interface = parse_result->AsInterface();
+ EXPECT_EQ("// get bar\n", interface->GetMethods()[0]->GetComments());
+}
+
TEST_F(AidlTest, ParsesPreprocessedFile) {
string simple_content = "parcelable a.Foo;\ninterface b.IBar;";
io_delegate_.SetFileContents("path", simple_content);