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_language_l.ll b/aidl_language_l.ll
index a41b96a..369700a 100644
--- a/aidl_language_l.ll
+++ b/aidl_language_l.ll
@@ -109,7 +109,8 @@
 in                    { return yy::parser::token::IN; }
 out                   { return yy::parser::token::OUT; }
 inout                 { return yy::parser::token::INOUT; }
-cpp_header            { return yy::parser::token::CPP_HEADER; }
+cpp_header            { yylval->token = new AidlToken("cpp_header", extra_text);
+                        return yy::parser::token::CPP_HEADER; }
 const                 { yylval->token = new AidlToken("const", extra_text);
                         return yy::parser::token::CONST; }
 true                  { return yy::parser::token::TRUE_LITERAL; }
diff --git a/aidl_language_y.yy b/aidl_language_y.yy
index 7ce8859..fc35741 100644
--- a/aidl_language_y.yy
+++ b/aidl_language_y.yy
@@ -117,7 +117,7 @@
 
 %token '(' ')' ',' '=' '[' ']' '.' '{' '}' ';'
 %token UNKNOWN "unrecognized character"
-%token CPP_HEADER "cpp_header (which can also be used as an identifier)"
+%token<token> CPP_HEADER "cpp_header (which can also be used as an identifier)"
 %token IMPORT "import"
 %token IN "in"
 %token INOUT "inout"
@@ -198,9 +198,7 @@
  */
 identifier
  : IDENTIFIER
-  { $$ = $1; }
  | CPP_HEADER
-  { $$ = new AidlToken("cpp_header", ""); }
  ;
 
 package
@@ -313,6 +311,7 @@
     $$ = new AidlParcelable(loc(@2), $2->GetText(), ps->Package(), $1->GetComments(), $4->GetText());
     delete $1;
     delete $2;
+    delete $3;
     delete $4;
   }
  | PARCELABLE error ';' {
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);