Simplify BuildFileAST and move BUILD file validation checks.

After this change, it will be easy to access the Environment from the Validation checks. This is needed to access StarlarkSemantics, and it is required for computing the scope of variables.

RELNOTES: None.
PiperOrigin-RevId: 243256778
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
index d2c6e44..fdb855e 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
@@ -40,7 +40,7 @@
 public class ParserTest extends EvaluationTestCase {
 
   private BuildFileAST parseFileWithComments(String... input) {
-    return BuildFileAST.parseBuildString(getEventHandler(), input);
+    return BuildFileAST.parseString(getEventHandler(), input);
   }
 
   /** Parses build code (not Skylark) */
@@ -1452,41 +1452,6 @@
   }
 
   @Test
-  public void testDefInBuild() throws Exception {
-    setFailFast(false);
-    parseFile("def func(): pass");
-    assertContainsError("function definitions are not allowed in BUILD files");
-  }
-
-  @Test
-  public void testForStatementForbiddenInBuild() throws Exception {
-    setFailFast(false);
-    parseFile("for _ in []: pass");
-    assertContainsError("for statements are not allowed in BUILD files");
-  }
-
-  @Test
-  public void testIfStatementForbiddenInBuild() throws Exception {
-    setFailFast(false);
-    parseFile("if False: pass");
-    assertContainsError("if statements are not allowed in BUILD files");
-  }
-
-  @Test
-  public void testKwargsForbiddenInBuild() throws Exception {
-    setFailFast(false);
-    parseFile("func(**dict)");
-    assertContainsError("**kwargs arguments are not allowed in BUILD files");
-  }
-
-  @Test
-  public void testArgsForbiddenInBuild() throws Exception {
-    setFailFast(false);
-    parseFile("func(*array)");
-    assertContainsError("*args arguments are not allowed in BUILD files");
-  }
-
-  @Test
   public void testArgumentAfterKwargs() throws Exception {
     setFailFast(false);
     parseFileForSkylark(