Add "." accessors to GN.
Add support for values referring to a Scope, and add support for the dot operator to read such values out of a scope.
This is not currently used for anything. A followup patch will use this for the template implementation.
[email protected]
Review URL: https://codereview.chromium.org/207233003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259608 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/tools/gn/parser_unittest.cc b/tools/gn/parser_unittest.cc
index 7ef5ff6..adb8fdb4 100644
--- a/tools/gn/parser_unittest.cc
+++ b/tools/gn/parser_unittest.cc
@@ -27,6 +27,8 @@
Err err;
scoped_ptr<ParseNode> result = Parser::Parse(tokens, &err);
+ if (!result)
+ err.PrintToStdout();
ASSERT_TRUE(result);
std::ostringstream collector;
@@ -215,15 +217,31 @@
}
TEST(Parser, Accessor) {
- DoParserPrintTest("a=b[2]",
+ // Accessor indexing.
+ DoParserPrintTest("a=b[c+2]",
"BLOCK\n"
" BINARY(=)\n"
" IDENTIFIER(a)\n"
" ACCESSOR\n"
" b\n" // AccessorNode is a bit weird in that it holds
// a Token, not a ParseNode for the base.
- " LITERAL(2)\n");
+ " BINARY(+)\n"
+ " IDENTIFIER(c)\n"
+ " LITERAL(2)\n");
DoParserErrorTest("a = b[1][0]", 1, 5);
+
+ // Member accessors.
+ DoParserPrintTest("a=b.c+2",
+ "BLOCK\n"
+ " BINARY(=)\n"
+ " IDENTIFIER(a)\n"
+ " BINARY(+)\n"
+ " ACCESSOR\n"
+ " b\n"
+ " IDENTIFIER(c)\n"
+ " LITERAL(2)\n");
+ DoParserErrorTest("a = b.c.d", 1, 6); // Can't nest accessors (currently).
+ DoParserErrorTest("a.b = 5", 1, 1); // Can't assign to accessors (currently).
}
TEST(Parser, Condition) {