diff options
author | 2016-10-07 16:31:03 +0000 | |
---|---|---|
committer | 2016-10-07 17:47:15 +0000 | |
commit | b566c7dbf940ba41dc996b1a86eb6ad46ad5a9da (patch) | |
tree | 13c9feea59bea2e346f8054ac02ef839a29b6343 /src/main/java/com | |
parent | 4f5e12d4978212380fc900b6a7b01e640b85a550 (diff) |
Remove support for "Python" parsing mode.
It was unused in Bazel.
--
MOS_MIGRATED_REVID=135483937
Diffstat (limited to 'src/main/java/com')
4 files changed, 21 insertions, 41 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java index 98ab05583e..497715adeb 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java @@ -253,12 +253,12 @@ public class BuildFileAST extends ASTNode { public static BuildFileAST parseBuildFile(ParserInputSource input, List<Statement> preludeStatements, EventHandler eventHandler) { - Parser.ParseResult result = Parser.parseFile(input, eventHandler, false); + Parser.ParseResult result = Parser.parseFile(input, eventHandler); return create(preludeStatements, result, /*contentHashCode=*/ null, eventHandler); } public static BuildFileAST parseBuildFile(ParserInputSource input, EventHandler eventHandler) { - Parser.ParseResult result = Parser.parseFile(input, eventHandler, false); + Parser.ParseResult result = Parser.parseFile(input, eventHandler); return create(ImmutableList.<Statement>of(), result, /*contentHashCode=*/ null, eventHandler); } @@ -322,7 +322,7 @@ public class BuildFileAST extends ASTNode { public static BuildFileAST parseBuildString(EventHandler eventHandler, String... content) { String str = Joiner.on("\n").join(content); ParserInputSource input = ParserInputSource.create(str, null); - Parser.ParseResult result = Parser.parseFile(input, eventHandler, false); + Parser.ParseResult result = Parser.parseFile(input, eventHandler); return create(ImmutableList.<Statement>of(), result, null, eventHandler); } @@ -339,9 +339,8 @@ public class BuildFileAST extends ASTNode { * * @return true if the input file is syntactically valid */ - public static boolean checkSyntax( - ParserInputSource input, EventHandler eventHandler, boolean parsePython) { - Parser.ParseResult result = Parser.parseFile(input, eventHandler, parsePython); + public static boolean checkSyntax(ParserInputSource input, EventHandler eventHandler) { + Parser.ParseResult result = Parser.parseFile(input, eventHandler); return !result.containsErrors; } diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java index 177c052c3f..a1dd6ea11a 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java @@ -934,7 +934,7 @@ public final class Environment implements Freezable { valid.validateAst(result.statements, eventHandler); statements = result.statements; } else { - statements = Parser.parseFile(input, eventHandler, /*parsePython=*/false).statements; + statements = Parser.parseFile(input, eventHandler).statements; } // Force the validation of imports BuildFileAST.fetchLoads(statements, eventHandler); diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java b/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java index 4c923d058a..d8b34be169 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Lexer.java @@ -91,19 +91,16 @@ public final class Lexer { private boolean containsErrors; - private boolean parsePython; - /** - * Constructs a lexer which tokenizes the contents of the specified - * InputBuffer. Any errors during lexing are reported on "handler". + * Constructs a lexer which tokenizes the contents of the specified InputBuffer. Any errors during + * lexing are reported on "handler". */ - public Lexer(ParserInputSource input, EventHandler eventHandler, boolean parsePython, - LineNumberTable lineNumberTable) { + public Lexer( + ParserInputSource input, EventHandler eventHandler, LineNumberTable lineNumberTable) { this.buffer = input.getContent(); // Empirical measurements show roughly 1 token per 8 characters in buffer. this.tokens = Lists.newArrayListWithExpectedSize(buffer.length / 8); this.pos = 0; - this.parsePython = parsePython; this.eventHandler = eventHandler; this.locationInfo = new LocationInfo(input.getPath(), lineNumberTable); @@ -114,13 +111,7 @@ public final class Lexer { } public Lexer(ParserInputSource input, EventHandler eventHandler) { - this(input, eventHandler, /*parsePython=*/false, - LineNumberTable.create(input.getContent(), input.getPath())); - } - - public Lexer(ParserInputSource input, EventHandler eventHandler, boolean parsePython) { - this(input, eventHandler, parsePython, - LineNumberTable.create(input.getContent(), input.getPath())); + this(input, eventHandler, LineNumberTable.create(input.getContent(), input.getPath())); } /** @@ -822,12 +813,7 @@ public final class Lexer { } else if (Character.isJavaIdentifierStart(c) && c != '$') { addToken(identifierOrKeyword()); } else { - // Some characters in Python are not recognized in Blaze syntax (e.g. '!') - if (parsePython) { - addToken(new Token(TokenKind.ILLEGAL, pos - 1, pos, Character.toString(c))); - } else { - error("invalid character: '" + c + "'"); - } + error("invalid character: '" + c + "'"); } break; } // default diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java index ffe9f02afb..73da09ba0b 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.syntax; import static com.google.devtools.build.lib.syntax.Parser.ParsingMode.BUILD; -import static com.google.devtools.build.lib.syntax.Parser.ParsingMode.PYTHON; import static com.google.devtools.build.lib.syntax.Parser.ParsingMode.SKYLARK; import com.google.common.annotations.VisibleForTesting; @@ -82,8 +81,6 @@ public class Parser { BUILD, /** Used for parsing .bzl files */ SKYLARK, - /** Used for syntax checking, ignoring all Python blocks (e.g. def, class, try) */ - PYTHON, } private static final EnumSet<TokenKind> STATEMENT_TERMINATOR_SET = @@ -212,14 +209,12 @@ public class Parser { } /** - * Entry-point to parser that parses a build file with comments. All errors - * encountered during parsing are reported via "reporter". + * Entry-point to parser that parses a build file with comments. All errors encountered during + * parsing are reported via "reporter". */ - public static ParseResult parseFile( - ParserInputSource input, EventHandler eventHandler, boolean parsePython) { - Lexer lexer = new Lexer(input, eventHandler, parsePython); - ParsingMode parsingMode = parsePython ? PYTHON : BUILD; - Parser parser = new Parser(lexer, eventHandler, parsingMode); + public static ParseResult parseFile(ParserInputSource input, EventHandler eventHandler) { + Lexer lexer = new Lexer(input, eventHandler); + Parser parser = new Parser(lexer, eventHandler, BUILD); List<Statement> statements = parser.parseFileInput(); return new ParseResult(statements, parser.comments, locationFromStatements(lexer, statements), parser.errorsCount > 0 || lexer.containsErrors()); @@ -232,7 +227,7 @@ public class Parser { */ public static ParseResult parseFileForSkylark( ParserInputSource input, EventHandler eventHandler) { - Lexer lexer = new Lexer(input, eventHandler, false); + Lexer lexer = new Lexer(input, eventHandler); Parser parser = new Parser(lexer, eventHandler, SKYLARK); List<Statement> statements = parser.parseFileInput(); return new ParseResult( @@ -249,7 +244,7 @@ public class Parser { */ @VisibleForTesting public static Expression parseExpression(ParserInputSource input, EventHandler eventHandler) { - Lexer lexer = new Lexer(input, eventHandler, false); + Lexer lexer = new Lexer(input, eventHandler); Parser parser = new Parser(lexer, eventHandler, null); Expression result = parser.parseExpression(); while (parser.token.kind == TokenKind.NEWLINE) { @@ -345,7 +340,7 @@ public class Parser { TokenKind.TRY, TokenKind.WITH, TokenKind.WHILE, TokenKind.YIELD); private void checkForbiddenKeywords(Token token) { - if (parsingMode == PYTHON || !FORBIDDEN_KEYWORDS.contains(token.kind)) { + if (!FORBIDDEN_KEYWORDS.contains(token.kind)) { return; } String error; @@ -1435,7 +1430,7 @@ public class Parser { reportError( lexer.createLocation(blockToken.left, blockToken.right), "syntax error at 'else': not allowed here."); - } else if (parsingMode != PYTHON) { + } else { String msg = ILLEGAL_BLOCK_KEYWORDS.containsKey(blockToken.kind) ? String.format("%ss are not supported.", ILLEGAL_BLOCK_KEYWORDS.get(blockToken.kind)) |