Allow creation and modification of scopes in GN.

Previously scope variables could only be created by exec_script() and read_file() functions. This patch adds the following syntax:
  foo = { a = 1 b = 2 }
  foo.a += 1
  foo.c = 3
This will be used in a followup for toolchain args for non-default toolchains, which will allow us to generalize the templates as the number of configurations grows over time (currently every variable has be to be forwarded in the root toolchain templates).

It also allows mutations of list elements which isn't actually necessary for this but the implementation is the same as for scope mutations:
  list[0] = "foo"

This does a significant rework of the operator implementation. This was required for the more general "destination" for assignments and mutations.

It also updates the operator functions to use move semantics more. Previously:
  list3 = list1 + list2
Would be implemented as:
  1. Copy list1 into new new variable.
  2. Copy list2 into a new variable.
  3. Copy list1's copy to a new variable.
  4. Append elements of list2 to list1's copy by copying.
  5. Copy that list to list3.
That's a lot of copies! The new implementation does:
  1. Copy list1 into a new variable.
  2. Copy list2 into a new variable.
  3. Append elements of list2's copy to list1's copy by moving.
  4. Move list2 to list3.
Assuming the lists contain strings, each string should now be copied exactly once rather than three times.

Added a lot of documentation to the grammar help on how the language works (not strictly grammar but it seems like the best place to put it.

BUG=

Review-Url: https://codereview.chromium.org/2187523003
Cr-Commit-Position: refs/heads/master@{#409672}
diff --git a/tools/gn/parser_unittest.cc b/tools/gn/parser_unittest.cc
index 3970373..6caeeb4 100644
--- a/tools/gn/parser_unittest.cc
+++ b/tools/gn/parser_unittest.cc
@@ -246,8 +246,14 @@
                     "    b\n"
                     "    IDENTIFIER(c)\n"
                     "   LITERAL(2)\n");
+  DoParserPrintTest("a.b = 5",
+                    "BLOCK\n"
+                    " BINARY(=)\n"
+                    "  ACCESSOR\n"
+                    "   a\n"
+                    "   IDENTIFIER(b)\n"
+                    "  LITERAL(5)\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).
 
   // Error at the bad dot in the RHS, not the + operator (crbug.com/472038).
   DoParserErrorTest("foo(a + b.c.d)", 1, 10);
@@ -701,11 +707,38 @@
 // a function with an associated block, or a standalone function with a
 // freestanding block.
 TEST(Parser, StandaloneBlock) {
+  // The error is reported at the end of the block when nothing is done
+  // with it. If we had said "a = { ..." then it would have been OK.
   DoParserErrorTest(
       "if (true) {\n"
       "}\n"
       "{\n"
       "  assert(false)\n"
       "}\n",
-      3, 1);
+      5, 1);
+}
+
+TEST(Parser, BlockValues) {
+  const char* input =
+    "print({a = 1 b = 2}, 3)\n"
+    "a = { b = \"asd\" }";
+  const char* expected =
+    "BLOCK\n"
+    " FUNCTION(print)\n"
+    "  LIST\n"
+    "   BLOCK\n"
+    "    BINARY(=)\n"
+    "     IDENTIFIER(a)\n"
+    "     LITERAL(1)\n"
+    "    BINARY(=)\n"
+    "     IDENTIFIER(b)\n"
+    "     LITERAL(2)\n"
+    "   LITERAL(3)\n"
+    " BINARY(=)\n"
+    "  IDENTIFIER(a)\n"
+    "  BLOCK\n"
+    "   BINARY(=)\n"
+    "    IDENTIFIER(b)\n"
+    "    LITERAL(\"asd\")\n";
+  DoParserPrintTest(input, expected);
 }