Simplify ParsingScope interface: remove unnecessary flags, specify sync/async for function

This commit is contained in:
Semyon Proshev
2016-04-18 14:07:05 +03:00
parent 673bc32291
commit af40ac7d84
3 changed files with 11 additions and 18 deletions
@@ -50,9 +50,7 @@ public class FunctionParsing extends Parsing {
parseReturnTypeAnnotation();
checkMatches(PyTokenTypes.COLON, message("PARSE.expected.colon"));
final ParsingContext context = getParsingContext();
ParsingScope newScope = context.getScope().withFunction(true);
if (async) newScope = newScope.withAsync();
context.pushScope(newScope);
context.pushScope(context.getScope().withFunction(async));
getStatementParser().parseSuite(functionMarker, getFunctionType());
context.popScope();
}
@@ -27,27 +27,22 @@ public class ParsingScope {
protected ParsingScope() {}
public ParsingScope withFunction(boolean flag) {
public ParsingScope withFunction(boolean async) {
final ParsingScope result = copy();
result.myFunction = flag;
result.myFunction = true;
result.myAsync = async;
return result;
}
public ParsingScope withClass(boolean flag) {
public ParsingScope withClass() {
final ParsingScope result = copy();
result.myClass = flag;
result.myClass = true;
return result;
}
public ParsingScope withSuite(boolean flag) {
public ParsingScope withSuite() {
final ParsingScope result = copy();
result.mySuite = flag;
return result;
}
public ParsingScope withAsync() {
final ParsingScope result = copy();
result.myAsync = true;
result.mySuite = true;
return result;
}
@@ -807,7 +807,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
inheritMarker.done(PyElementTypes.ARGUMENT_LIST);
}
final ParsingContext context = getParsingContext();
context.pushScope(context.getScope().withClass(true));
context.pushScope(context.getScope().withClass());
parseColonAndSuite();
context.popScope();
classMarker.done(PyElementTypes.CLASS_DECLARATION);
@@ -874,14 +874,14 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
}
else {
final ParsingContext context = getParsingContext();
context.pushScope(context.getScope().withSuite(true));
context.pushScope(context.getScope().withSuite());
parseSimpleStatement();
context.popScope();
while (matchToken(PyTokenTypes.SEMICOLON)) {
if (matchToken(PyTokenTypes.STATEMENT_BREAK)) {
break;
}
context.pushScope(context.getScope().withSuite(true));
context.pushScope(context.getScope().withSuite());
parseSimpleStatement();
context.popScope();
}