[Parser] Modify parser so that it could parse contract description blocks of functions

This commit is contained in:
Arsen Nagdalian
2020-07-15 13:59:43 +03:00
parent e3fe9c3314
commit 0990434840
2 changed files with 45 additions and 0 deletions
@@ -1047,6 +1047,43 @@ public class KotlinExpressionParsing extends AbstractKotlinParsing {
} }
} }
public void parseContractDescriptionBlock() {
assert _at(CONTRACT_KEYWORD);
advance(); // CONTRACT_KEYWORD
parseContractEffectList();
}
private void parseContractEffectList() {
PsiBuilder.Marker block = mark();
expect(LBRACKET, "Expecting '['");
myBuilder.enableNewlines();
parseContractEffects();
expect(RBRACKET, "Expecting ']'");
myBuilder.restoreNewlinesState();
block.done(CONTRACT_EFFECT_LIST);
}
private void parseContractEffects() {
while (true) {
if (at(COMMA)) errorAndAdvance("Expecting a contract effect");
if (at(RBRACKET)) {
break;
}
PsiBuilder.Marker effect = mark();
parseExpression();
effect.done(CONTRACT_EFFECT);
if (!at(COMMA)) break;
advance(); // COMMA
}
}
/* /*
* SimpleName * SimpleName
*/ */
@@ -1673,6 +1673,8 @@ public class KotlinParsing extends AbstractKotlinParsing {
parseTypeConstraintsGuarded(typeParameterListOccurred); parseTypeConstraintsGuarded(typeParameterListOccurred);
parseFunctionContract();
if (at(SEMICOLON)) { if (at(SEMICOLON)) {
advance(); // SEMICOLON advance(); // SEMICOLON
} }
@@ -1993,6 +1995,12 @@ public class KotlinParsing extends AbstractKotlinParsing {
constraint.done(TYPE_CONSTRAINT); constraint.done(TYPE_CONSTRAINT);
} }
private void parseFunctionContract() {
if (at(CONTRACT_KEYWORD)) {
myExpressionParsing.parseContractDescriptionBlock();
}
}
/* /*
* typeParameter * typeParameter
* : modifiers SimpleName (":" userType)? * : modifiers SimpleName (":" userType)?