Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
mhernyavsky committed Mar 14, 2022
1 parent a3d64dd commit b08f2b5
Show file tree
Hide file tree
Showing 18 changed files with 240 additions and 192 deletions.
7 changes: 6 additions & 1 deletion src/main/grammars/RustParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,18 @@ TypeArgumentList ::= TypeArgumentListImpl {
ColonTypeArgumentList ::= &'::' TypeArgumentListImpl { elementType = TypeArgumentList }

private TypeArgumentListImpl ::= '::'? '<' !'=' <<list_element AnyTypeArgument>>* '>' { pin = 3 }
private AnyTypeArgument ::= AssocTypeBinding | TypeReference | Lifetime | RestrictedConstExpr
private AnyTypeArgument ::= <<typeReferenceOrAssocTypeBinding TypePathGenericArgsNoTypeQual AssocTypeBinding_upper TypePathGenericArgs ImplicitTraitType TraitType_upper>>
| Lifetime
| RestrictedConstExpr
| never (AssocTypeBinding | TypeReference)

AssocTypeBinding ::= TypePathGenericArgsNoTypeQual (AssocTypeBindingType | AssocTypeBindingBound) {
extends = "org.rust.lang.core.psi.ext.RsStubbedElementImpl<?>"
stubClass = "org.rust.lang.core.stubs.RsPlaceholderStub"
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
}

private AssocTypeBinding_upper ::= AssocTypeBindingType | AssocTypeBindingBound
private AssocTypeBindingType ::= '=' TypeReference { pin = 1 }
private AssocTypeBindingBound ::= ':' TypeBounds { pin = 1 }

Expand Down Expand Up @@ -909,6 +913,7 @@ TypeReference ::= ArrayType
| ForInType { // FIXME O(2^n) for types like `for<'a> A<for<'b> B<for<'c> C<...>>>`
implements = "org.rust.lang.core.macros.RsExpandedElement"
stubClass = "com.intellij.psi.stubs.StubBase"
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
mixin = "org.rust.lang.core.psi.ext.RsTypeReferenceImplMixin"
name = "type"
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/kotlin/org/rust/lang/core/parser/RustParserUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,34 @@ object RustParserUtil : GeneratedParserUtilBase() {
return result
}

@JvmStatic
fun typeReferenceOrAssocTypeBinding(
b: PsiBuilder,
level: Int,
pathP1: Parser,
assocTypeBindingUpperP: Parser,
pathP2: Parser,
implicitTraitTypeP: Parser,
traitTypeUpperP: Parser
): Boolean {
val refOrBinding = enter_section_(b)

if (!pathP1.parse(b, level)) {
val result = baseOrTraitType(b, level, pathP2, implicitTraitTypeP, traitTypeUpperP)
exit_section_(b, refOrBinding, TYPE_REFERENCE, result)
return result
}

if (!nextTokenIs(b, EQ) && !nextTokenIs(b, COLON)) {
exit_section_(b, refOrBinding, TYPE_REFERENCE, true)
return true
}

val result = assocTypeBindingUpperP.parse(b, level)
exit_section_(b, refOrBinding, ASSOC_TYPE_BINDING, result)
return result
}

private val SPECIAL_MACRO_PARSERS: Map<String, (PsiBuilder, Int) -> Boolean>
private val SPECIAL_EXPR_MACROS: Set<String>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ FILE
PsiElement(identifier)('E')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('U')
PsiElement(>)('>')
Expand Down Expand Up @@ -112,7 +112,7 @@ FILE
PsiElement(identifier)('T')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('U')
PsiElement(>)('>')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ FILE
PsiElement(identifier)('S')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(Self)('Self')
PsiElement(>)('>')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ FILE
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(::)('::')
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('Z')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ FILE
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(::)('::')
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('f64')
PsiElement(>)('>')
Expand All @@ -319,7 +319,7 @@ FILE
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(::)('::')
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('isize')
PsiElement(>)('>')
Expand All @@ -328,7 +328,7 @@ FILE
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(::)('::')
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('usize')
PsiElement(>)('>')
Expand All @@ -350,12 +350,13 @@ FILE
PsiElement(identifier)('Box')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsArrayTypeImpl(ARRAY_TYPE)
PsiElement([)('[')
RsBaseTypeImpl(BASE_TYPE)
PsiElement(()('(')
PsiElement())(')')
PsiElement(])(']')
RsTypeReferenceImpl(TYPE_REFERENCE)
RsArrayTypeImpl(ARRAY_TYPE)
PsiElement([)('[')
RsBaseTypeImpl(BASE_TYPE)
PsiElement(()('(')
PsiElement())(')')
PsiElement(])(']')
PsiElement(>)('>')
PsiWhiteSpace(' ')
PsiElement(=)('=')
Expand All @@ -368,16 +369,17 @@ FILE
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(::)('::')
PsiElement(<)('<')
RsArrayTypeImpl(ARRAY_TYPE)
PsiElement([)('[')
RsBaseTypeImpl(BASE_TYPE)
PsiElement(()('(')
PsiElement())(')')
PsiElement(;)(';')
PsiWhiteSpace(' ')
RsLitExprImpl(LIT_EXPR)
PsiElement(INTEGER_LITERAL)('0')
PsiElement(])(']')
RsTypeReferenceImpl(TYPE_REFERENCE)
RsArrayTypeImpl(ARRAY_TYPE)
PsiElement([)('[')
RsBaseTypeImpl(BASE_TYPE)
PsiElement(()('(')
PsiElement())(')')
PsiElement(;)(';')
PsiWhiteSpace(' ')
RsLitExprImpl(LIT_EXPR)
PsiElement(INTEGER_LITERAL)('0')
PsiElement(])(']')
PsiElement(>)('>')
PsiElement(::)('::')
PsiElement(identifier)('new')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ FILE
PsiElement(identifier)('P')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('U')
PsiElement(>)('>')
Expand All @@ -163,7 +163,7 @@ FILE
PsiElement(identifier)('P')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('U')
PsiElement(>)('>')
Expand All @@ -187,7 +187,7 @@ FILE
PsiElement(identifier)('P')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('U')
PsiElement(>)('>')
Expand Down Expand Up @@ -294,7 +294,7 @@ FILE
PsiElement(QUOTE_IDENTIFIER)(''a')
PsiElement(,)(',')
PsiWhiteSpace(' ')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('T')
PsiElement(>)('>')
Expand Down Expand Up @@ -350,7 +350,7 @@ FILE
PsiElement(identifier)('GenVal')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('T')
PsiElement(>)('>')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ FILE
PsiElement(identifier)('Vec')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('i32')
PsiElement(>)('>')
Expand Down Expand Up @@ -691,7 +691,7 @@ FILE
PsiElement(identifier)('Vec')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('i32')
PsiElement(>)('>')
Expand Down Expand Up @@ -726,7 +726,7 @@ FILE
PsiElement(identifier)('Vec')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('i32')
PsiElement(>)('>')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ FILE
PsiElement(identifier)('Unique')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('T')
PsiElement(>)('>')
Expand Down Expand Up @@ -112,7 +112,7 @@ FILE
PsiElement(identifier)('Unique')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('T')
PsiElement(>)('>')
Expand Down Expand Up @@ -1042,7 +1042,7 @@ FILE
PsiElement(identifier)('Item')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('T')
PsiElement(>)('>')
Expand Down Expand Up @@ -1095,7 +1095,7 @@ FILE
PsiElement(identifier)('Item')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('T')
PsiElement(>)('>')
Expand Down Expand Up @@ -1154,7 +1154,7 @@ FILE
PsiElement(identifier)('Item1')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('T')
PsiElement(>)('>')
Expand All @@ -1172,7 +1172,7 @@ FILE
PsiElement(identifier)('Item2')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('T')
PsiElement(>)('>')
Expand Down Expand Up @@ -1224,7 +1224,7 @@ FILE
PsiElement(identifier)('Item1')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('T')
PsiElement(>)('>')
Expand All @@ -1241,7 +1241,7 @@ FILE
PsiElement(identifier)('Item2')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('T')
PsiElement(>)('>')
Expand Down Expand Up @@ -1300,7 +1300,7 @@ FILE
PsiElement(identifier)('Item')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsTypeReferenceImpl(TYPE_REFERENCE)
RsPathImpl(PATH)
PsiElement(identifier)('T')
PsiElement(>)('>')
Expand Down

0 comments on commit b08f2b5

Please sign in to comment.