Skip to content

Commit

Permalink
GRAM: support if_while_or_patterns syntax
Browse files Browse the repository at this point in the history
See rust-lang/rust#57532 for more details
  • Loading branch information
Undin authored and rrevenantt committed May 30, 2019
1 parent 74ee70f commit f8000ad
Show file tree
Hide file tree
Showing 9 changed files with 423 additions and 55 deletions.
8 changes: 5 additions & 3 deletions src/main/grammars/RustParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ PatField ::= identifier ':' Pat | box? PatBinding

BindingMode ::= ref mut? | mut

OrPats ::= '|'? Pat ('|' Pat)*

Constant ::= OuterAttr* default_? Vis? (static mut? | const) identifier TypeAscription [ '=' AnyExpr ] ';' {
pin = 'identifier'
implements = [ "org.rust.lang.core.psi.ext.RsQualifiedNamedElement"
Expand Down Expand Up @@ -1027,7 +1029,7 @@ WhileExpr ::= OuterAttr* LabelDecl? while Condition SimpleBlock {
implements = [ "org.rust.lang.core.psi.ext.RsLabeledExpression" ]
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
}
Condition ::= [ let Pat '=' ] NoStructLitExpr
Condition ::= [ let OrPats '=' ] NoStructLitExpr

LoopExpr ::= OuterAttr* LabelDecl? loop SimpleBlock {
pin = 'loop'
Expand Down Expand Up @@ -1063,8 +1065,8 @@ MatchExpr ::= OuterAttr* match NoStructLitExpr MatchBody {
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
}
MatchBody ::= '{' MatchArm* '}' { pin = 1 }
MatchArm ::= OuterAttr* '|'? Pat ('|' Pat)* MatchArmGuard? '=>' StmtModeExpr (',' | (&'}' | <<isBlock>>)) {
pin = 3
MatchArm ::= OuterAttr* OrPats MatchArmGuard? '=>' StmtModeExpr (',' | (&'}' | <<isBlock>>)) {
pin = 2
recoverWhile = MatchArm_recover
}
private MatchArm_recover ::= !(Pat_first | OuterAttr_first | '}' | '|')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class RsCompleteParsingTestCase : RsParsingTestCaseBase("complete") {
fun `test visibility`() = doTest(true)
fun `test polybounds`() = doTest(true)
fun `test async await`() = doTest(true)
fun `test conditions`() = doTest(true)

fun `test issue320`() = doTest(true)
fun `test diesel macros`() = doTest(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn main() {
if 1 < 2 {}
if let Some(x) = o {}
if let | Err(e) = r {}
if let V1(s) | V2(s) = value {}
if let | Cat(name) | Dog(name) | Parrot(name) = animal {}

while 1 < 2 {}
while let Some(x) = o {}
while let | Err(e) = r {}
while let V1(s) | V2(s) = value {}
while let | Cat(name) | Dog(name) | Parrot(name) = animal {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,340 @@
FILE
RsFunctionImpl(FUNCTION)
PsiElement(fn)('fn')
PsiWhiteSpace(' ')
PsiElement(identifier)('main')
RsValueParameterListImpl(VALUE_PARAMETER_LIST)
PsiElement(()('(')
PsiElement())(')')
PsiWhiteSpace(' ')
RsBlockImpl(BLOCK)
PsiElement({)('{')
PsiWhiteSpace('\n ')
RsExprStmtImpl(EXPR_STMT)
RsIfExprImpl(IF_EXPR)
PsiElement(if)('if')
PsiWhiteSpace(' ')
RsConditionImpl(CONDITION)
RsBinaryExprImpl(BINARY_EXPR)
RsLitExprImpl(LIT_EXPR)
PsiElement(INTEGER_LITERAL)('1')
PsiWhiteSpace(' ')
RsBinaryOpImpl(BINARY_OP)
PsiElement(<)('<')
PsiWhiteSpace(' ')
RsLitExprImpl(LIT_EXPR)
PsiElement(INTEGER_LITERAL)('2')
PsiWhiteSpace(' ')
RsBlockImpl(BLOCK)
PsiElement({)('{')
PsiElement(})('}')
PsiWhiteSpace('\n ')
RsExprStmtImpl(EXPR_STMT)
RsIfExprImpl(IF_EXPR)
PsiElement(if)('if')
PsiWhiteSpace(' ')
RsConditionImpl(CONDITION)
PsiElement(let)('let')
PsiWhiteSpace(' ')
RsOrPatsImpl(OR_PATS)
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('Some')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('x')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(=)('=')
PsiWhiteSpace(' ')
RsPathExprImpl(PATH_EXPR)
RsPathImpl(PATH)
PsiElement(identifier)('o')
PsiWhiteSpace(' ')
RsBlockImpl(BLOCK)
PsiElement({)('{')
PsiElement(})('}')
PsiWhiteSpace('\n ')
RsExprStmtImpl(EXPR_STMT)
RsIfExprImpl(IF_EXPR)
PsiElement(if)('if')
PsiWhiteSpace(' ')
RsConditionImpl(CONDITION)
PsiElement(let)('let')
PsiWhiteSpace(' ')
RsOrPatsImpl(OR_PATS)
PsiElement(|)('|')
PsiWhiteSpace(' ')
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('Err')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('e')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(=)('=')
PsiWhiteSpace(' ')
RsPathExprImpl(PATH_EXPR)
RsPathImpl(PATH)
PsiElement(identifier)('r')
PsiWhiteSpace(' ')
RsBlockImpl(BLOCK)
PsiElement({)('{')
PsiElement(})('}')
PsiWhiteSpace('\n ')
RsExprStmtImpl(EXPR_STMT)
RsIfExprImpl(IF_EXPR)
PsiElement(if)('if')
PsiWhiteSpace(' ')
RsConditionImpl(CONDITION)
PsiElement(let)('let')
PsiWhiteSpace(' ')
RsOrPatsImpl(OR_PATS)
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('V1')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('s')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(|)('|')
PsiWhiteSpace(' ')
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('V2')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('s')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(=)('=')
PsiWhiteSpace(' ')
RsPathExprImpl(PATH_EXPR)
RsPathImpl(PATH)
PsiElement(identifier)('value')
PsiWhiteSpace(' ')
RsBlockImpl(BLOCK)
PsiElement({)('{')
PsiElement(})('}')
PsiWhiteSpace('\n ')
RsExprStmtImpl(EXPR_STMT)
RsIfExprImpl(IF_EXPR)
PsiElement(if)('if')
PsiWhiteSpace(' ')
RsConditionImpl(CONDITION)
PsiElement(let)('let')
PsiWhiteSpace(' ')
RsOrPatsImpl(OR_PATS)
PsiElement(|)('|')
PsiWhiteSpace(' ')
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('Cat')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('name')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(|)('|')
PsiWhiteSpace(' ')
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('Dog')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('name')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(|)('|')
PsiWhiteSpace(' ')
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('Parrot')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('name')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(=)('=')
PsiWhiteSpace(' ')
RsPathExprImpl(PATH_EXPR)
RsPathImpl(PATH)
PsiElement(identifier)('animal')
PsiWhiteSpace(' ')
RsBlockImpl(BLOCK)
PsiElement({)('{')
PsiElement(})('}')
PsiWhiteSpace('\n\n ')
RsExprStmtImpl(EXPR_STMT)
RsWhileExprImpl(WHILE_EXPR)
PsiElement(while)('while')
PsiWhiteSpace(' ')
RsConditionImpl(CONDITION)
RsBinaryExprImpl(BINARY_EXPR)
RsLitExprImpl(LIT_EXPR)
PsiElement(INTEGER_LITERAL)('1')
PsiWhiteSpace(' ')
RsBinaryOpImpl(BINARY_OP)
PsiElement(<)('<')
PsiWhiteSpace(' ')
RsLitExprImpl(LIT_EXPR)
PsiElement(INTEGER_LITERAL)('2')
PsiWhiteSpace(' ')
RsBlockImpl(BLOCK)
PsiElement({)('{')
PsiElement(})('}')
PsiWhiteSpace('\n ')
RsExprStmtImpl(EXPR_STMT)
RsWhileExprImpl(WHILE_EXPR)
PsiElement(while)('while')
PsiWhiteSpace(' ')
RsConditionImpl(CONDITION)
PsiElement(let)('let')
PsiWhiteSpace(' ')
RsOrPatsImpl(OR_PATS)
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('Some')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('x')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(=)('=')
PsiWhiteSpace(' ')
RsPathExprImpl(PATH_EXPR)
RsPathImpl(PATH)
PsiElement(identifier)('o')
PsiWhiteSpace(' ')
RsBlockImpl(BLOCK)
PsiElement({)('{')
PsiElement(})('}')
PsiWhiteSpace('\n ')
RsExprStmtImpl(EXPR_STMT)
RsWhileExprImpl(WHILE_EXPR)
PsiElement(while)('while')
PsiWhiteSpace(' ')
RsConditionImpl(CONDITION)
PsiElement(let)('let')
PsiWhiteSpace(' ')
RsOrPatsImpl(OR_PATS)
PsiElement(|)('|')
PsiWhiteSpace(' ')
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('Err')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('e')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(=)('=')
PsiWhiteSpace(' ')
RsPathExprImpl(PATH_EXPR)
RsPathImpl(PATH)
PsiElement(identifier)('r')
PsiWhiteSpace(' ')
RsBlockImpl(BLOCK)
PsiElement({)('{')
PsiElement(})('}')
PsiWhiteSpace('\n ')
RsExprStmtImpl(EXPR_STMT)
RsWhileExprImpl(WHILE_EXPR)
PsiElement(while)('while')
PsiWhiteSpace(' ')
RsConditionImpl(CONDITION)
PsiElement(let)('let')
PsiWhiteSpace(' ')
RsOrPatsImpl(OR_PATS)
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('V1')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('s')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(|)('|')
PsiWhiteSpace(' ')
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('V2')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('s')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(=)('=')
PsiWhiteSpace(' ')
RsPathExprImpl(PATH_EXPR)
RsPathImpl(PATH)
PsiElement(identifier)('value')
PsiWhiteSpace(' ')
RsBlockImpl(BLOCK)
PsiElement({)('{')
PsiElement(})('}')
PsiWhiteSpace('\n ')
RsWhileExprImpl(WHILE_EXPR)
PsiElement(while)('while')
PsiWhiteSpace(' ')
RsConditionImpl(CONDITION)
PsiElement(let)('let')
PsiWhiteSpace(' ')
RsOrPatsImpl(OR_PATS)
PsiElement(|)('|')
PsiWhiteSpace(' ')
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('Cat')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('name')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(|)('|')
PsiWhiteSpace(' ')
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('Dog')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('name')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(|)('|')
PsiWhiteSpace(' ')
RsPatTupleStructImpl(PAT_TUPLE_STRUCT)
RsPathImpl(PATH)
PsiElement(identifier)('Parrot')
PsiElement(()('(')
RsPatIdentImpl(PAT_IDENT)
RsPatBindingImpl(PAT_BINDING)
PsiElement(identifier)('name')
PsiElement())(')')
PsiWhiteSpace(' ')
PsiElement(=)('=')
PsiWhiteSpace(' ')
RsPathExprImpl(PATH_EXPR)
RsPathImpl(PATH)
PsiElement(identifier)('animal')
PsiWhiteSpace(' ')
RsBlockImpl(BLOCK)
PsiElement({)('{')
PsiElement(})('}')
PsiWhiteSpace('\n')
PsiElement(})('}')
Loading

0 comments on commit f8000ad

Please sign in to comment.