diff --git a/src/main/gen/io/vlang/lang/VlangParser.java b/src/main/gen/io/vlang/lang/VlangParser.java index bfe8f477..4e62f7c8 100644 --- a/src/main/gen/io/vlang/lang/VlangParser.java +++ b/src/main/gen/io/vlang/lang/VlangParser.java @@ -10,6 +10,7 @@ import com.intellij.psi.tree.TokenSet; import com.intellij.lang.PsiParser; import com.intellij.lang.LightPsiParser; +import static io.vlang.lang.VlangParserHooks.*; @SuppressWarnings({"SimplifiableIfStatement", "UnusedAssignment"}) public class VlangParser implements PsiParser, LightPsiParser { @@ -509,25 +510,27 @@ public static boolean Attribute(PsiBuilder b, int l) { // '@[' AttributeExpressions ']' private static boolean Attribute_0(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "Attribute_0")) return false; - boolean r; - Marker m = enter_section_(b); + boolean r, p; + Marker m = enter_section_(b, l, _NONE_); r = consumeToken(b, AT_LBRACK); - r = r && AttributeExpressions(b, l + 1); - r = r && consumeToken(b, RBRACK); - exit_section_(b, m, null, r); - return r; + p = r; // pin = 1 + r = r && report_error_(b, AttributeExpressions(b, l + 1)); + r = p && consumeToken(b, RBRACK) && r; + exit_section_(b, l, m, r, p, null); + return r || p; } // '[' AttributeExpressions ']' private static boolean Attribute_1(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "Attribute_1")) return false; - boolean r; - Marker m = enter_section_(b); + boolean r, p; + Marker m = enter_section_(b, l, _NONE_); r = consumeToken(b, LBRACK); - r = r && AttributeExpressions(b, l + 1); - r = r && consumeToken(b, RBRACK); - exit_section_(b, m, null, r); - return r; + p = r; // pin = 1 + r = r && report_error_(b, AttributeExpressions(b, l + 1)); + r = p && consumeToken(b, RBRACK) && r; + exit_section_(b, l, m, r, p, null); + return r || p; } /* ********************************************************** */ @@ -2045,14 +2048,14 @@ static boolean FieldDeclarations(PsiBuilder b, int l) { } /* ********************************************************** */ - // identifier + // <> identifier public static boolean FieldDefinition(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "FieldDefinition")) return false; - if (!nextTokenIs(b, IDENTIFIER)) return false; boolean r; - Marker m = enter_section_(b); - r = consumeToken(b, IDENTIFIER); - exit_section_(b, m, FIELD_DEFINITION, r); + Marker m = enter_section_(b, l, _NONE_, FIELD_DEFINITION, ""); + r = remapToIdentifier(b, l + 1); + r = r && consumeToken(b, IDENTIFIER); + exit_section_(b, l, m, r, false, null); return r; } @@ -2333,31 +2336,32 @@ public static boolean FormatSpecifierWidthAndPrecision(PsiBuilder b, int l) { } /* ********************************************************** */ - // fnDecl identifier GenericParameters? Signature BlockWithConsume? + // fnDecl <> identifier GenericParameters? Signature BlockWithConsume? public static boolean FunctionDeclaration(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "FunctionDeclaration")) return false; boolean r, p; Marker m = enter_section_(b, l, _NONE_, FUNCTION_DECLARATION, ""); r = fnDecl(b, l + 1); + r = r && remapToIdentifier(b, l + 1); r = r && consumeToken(b, IDENTIFIER); - r = r && FunctionDeclaration_2(b, l + 1); + r = r && FunctionDeclaration_3(b, l + 1); r = r && Signature(b, l + 1); - p = r; // pin = 4 - r = r && FunctionDeclaration_4(b, l + 1); + p = r; // pin = 5 + r = r && FunctionDeclaration_5(b, l + 1); exit_section_(b, l, m, r, p, null); return r || p; } // GenericParameters? - private static boolean FunctionDeclaration_2(PsiBuilder b, int l) { - if (!recursion_guard_(b, l, "FunctionDeclaration_2")) return false; + private static boolean FunctionDeclaration_3(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "FunctionDeclaration_3")) return false; GenericParameters(b, l + 1); return true; } // BlockWithConsume? - private static boolean FunctionDeclaration_4(PsiBuilder b, int l) { - if (!recursion_guard_(b, l, "FunctionDeclaration_4")) return false; + private static boolean FunctionDeclaration_5(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "FunctionDeclaration_5")) return false; BlockWithConsume(b, l + 1); return true; } @@ -3206,7 +3210,7 @@ private static boolean InterfaceMethodDefinition_1(PsiBuilder b, int l) { } /* ********************************************************** */ - // interface identifier GenericParameters? '{' MembersGroup* '}' + // interface identifier GenericParameters? '{' <> MembersGroup* <> '}' public static boolean InterfaceType(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "InterfaceType")) return false; if (!nextTokenIs(b, INTERFACE)) return false; @@ -3216,7 +3220,9 @@ public static boolean InterfaceType(PsiBuilder b, int l) { p = r; // pin = 1 r = r && report_error_(b, InterfaceType_2(b, l + 1)); r = p && report_error_(b, consumeToken(b, LBRACE)) && r; - r = p && report_error_(b, InterfaceType_4(b, l + 1)) && r; + r = p && report_error_(b, enterMode(b, l + 1, "checkForAccessModifiers")) && r; + r = p && report_error_(b, InterfaceType_5(b, l + 1)) && r; + r = p && report_error_(b, exitModeSafe(b, l + 1, "checkForAccessModifiers")) && r; r = p && consumeToken(b, RBRACE) && r; exit_section_(b, l, m, r, p, null); return r || p; @@ -3230,12 +3236,12 @@ private static boolean InterfaceType_2(PsiBuilder b, int l) { } // MembersGroup* - private static boolean InterfaceType_4(PsiBuilder b, int l) { - if (!recursion_guard_(b, l, "InterfaceType_4")) return false; + private static boolean InterfaceType_5(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "InterfaceType_5")) return false; while (true) { int c = current_position_(b); if (!MembersGroup(b, l + 1)) break; - if (!empty_element_parsed_guard_(b, "InterfaceType_4", c)) break; + if (!empty_element_parsed_guard_(b, "InterfaceType_5", c)) break; } return true; } @@ -3826,10 +3832,10 @@ public static boolean MethodDeclaration(PsiBuilder b, int l) { r = r && Receiver(b, l + 1); r = r && consumeToken(b, RPAREN); r = r && MethodName(b, l + 1); - p = r; // pin = 5 - r = r && report_error_(b, MethodDeclaration_5(b, l + 1)); - r = p && report_error_(b, Signature(b, l + 1)) && r; - r = p && MethodDeclaration_7(b, l + 1) && r; + r = r && MethodDeclaration_5(b, l + 1); + r = r && Signature(b, l + 1); + p = r; // pin = 7 + r = r && MethodDeclaration_7(b, l + 1); exit_section_(b, l, m, r, p, null); return r || p; } @@ -3849,12 +3855,12 @@ private static boolean MethodDeclaration_7(PsiBuilder b, int l) { } /* ********************************************************** */ - // identifier | AddOp | MulOp | RelOp + // <> identifier | AddOp | MulOp | RelOp public static boolean MethodName(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "MethodName")) return false; boolean r; Marker m = enter_section_(b, l, _NONE_, METHOD_NAME, ""); - r = consumeToken(b, IDENTIFIER); + r = MethodName_0(b, l + 1); if (!r) r = AddOp(b, l + 1); if (!r) r = MulOp(b, l + 1); if (!r) r = RelOp(b, l + 1); @@ -3862,6 +3868,17 @@ public static boolean MethodName(PsiBuilder b, int l) { return r; } + // <> identifier + private static boolean MethodName_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "MethodName_0")) return false; + boolean r; + Marker m = enter_section_(b); + r = remapToIdentifier(b, l + 1); + r = r && consumeToken(b, IDENTIFIER); + exit_section_(b, m, null, r); + return r; + } + /* ********************************************************** */ // Attributes? module identifier semi public static boolean ModuleClause(PsiBuilder b, int l) { @@ -4157,10 +4174,9 @@ private static boolean PlainAttribute_1(PsiBuilder b, int l) { } /* ********************************************************** */ - // FieldDefinition Type Attribute? DefaultFieldValue? + // FieldDefinition Type DefaultFieldValue? Attribute? static boolean PlainFieldDeclaration(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "PlainFieldDeclaration")) return false; - if (!nextTokenIs(b, IDENTIFIER)) return false; boolean r; Marker m = enter_section_(b); r = FieldDefinition(b, l + 1); @@ -4171,17 +4187,17 @@ static boolean PlainFieldDeclaration(PsiBuilder b, int l) { return r; } - // Attribute? + // DefaultFieldValue? private static boolean PlainFieldDeclaration_2(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "PlainFieldDeclaration_2")) return false; - Attribute(b, l + 1); + DefaultFieldValue(b, l + 1); return true; } - // DefaultFieldValue? + // Attribute? private static boolean PlainFieldDeclaration_3(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "PlainFieldDeclaration_3")) return false; - DefaultFieldValue(b, l + 1); + Attribute(b, l + 1); return true; } @@ -5752,19 +5768,21 @@ private static boolean StructDeclaration_1(PsiBuilder b, int l) { } /* ********************************************************** */ - // (struct | union) identifier GenericParameters? ImplementsClause? '{' FieldsGroup* '}' + // (struct | union) identifier GenericParameters? ImplementsClause? '{' <> FieldsGroup* <> '}' public static boolean StructType(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "StructType")) return false; if (!nextTokenIs(b, "", STRUCT, UNION)) return false; boolean r, p; - Marker m = enter_section_(b, l, _NONE_, STRUCT_TYPE, ""); + Marker m = enter_section_(b, l, _COLLAPSE_, STRUCT_TYPE, ""); r = StructType_0(b, l + 1); p = r; // pin = 1 r = r && report_error_(b, consumeToken(b, IDENTIFIER)); r = p && report_error_(b, StructType_2(b, l + 1)) && r; r = p && report_error_(b, StructType_3(b, l + 1)) && r; r = p && report_error_(b, consumeToken(b, LBRACE)) && r; - r = p && report_error_(b, StructType_5(b, l + 1)) && r; + r = p && report_error_(b, enterMode(b, l + 1, "checkForAccessModifiers")) && r; + r = p && report_error_(b, StructType_6(b, l + 1)) && r; + r = p && report_error_(b, exitModeSafe(b, l + 1, "checkForAccessModifiers")) && r; r = p && consumeToken(b, RBRACE) && r; exit_section_(b, l, m, r, p, null); return r || p; @@ -5794,12 +5812,12 @@ private static boolean StructType_3(PsiBuilder b, int l) { } // FieldsGroup* - private static boolean StructType_5(PsiBuilder b, int l) { - if (!recursion_guard_(b, l, "StructType_5")) return false; + private static boolean StructType_6(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "StructType_6")) return false; while (true) { int c = current_position_(b); if (!FieldsGroup(b, l + 1)) break; - if (!empty_element_parsed_guard_(b, "StructType_5", c)) break; + if (!empty_element_parsed_guard_(b, "StructType_6", c)) break; } return true; } diff --git a/src/main/gen/io/vlang/lang/psi/VlangAttribute.java b/src/main/gen/io/vlang/lang/psi/VlangAttribute.java index ef5c2517..e14ce709 100644 --- a/src/main/gen/io/vlang/lang/psi/VlangAttribute.java +++ b/src/main/gen/io/vlang/lang/psi/VlangAttribute.java @@ -18,7 +18,7 @@ public interface VlangAttribute extends VlangCompositeElement, StubBasedPsiEleme @Nullable PsiElement getLbrack(); - @NotNull + @Nullable PsiElement getRbrack(); } diff --git a/src/main/gen/io/vlang/lang/psi/impl/VlangAttributeImpl.java b/src/main/gen/io/vlang/lang/psi/impl/VlangAttributeImpl.java index 2eac07fc..deb1c8cb 100644 --- a/src/main/gen/io/vlang/lang/psi/impl/VlangAttributeImpl.java +++ b/src/main/gen/io/vlang/lang/psi/impl/VlangAttributeImpl.java @@ -51,9 +51,9 @@ public PsiElement getLbrack() { } @Override - @NotNull + @Nullable public PsiElement getRbrack() { - return notNullChild(findChildByType(RBRACK)); + return findChildByType(RBRACK); } } diff --git a/src/main/kotlin/io/vlang/lang/VlangParserUtil.kt b/src/main/kotlin/io/vlang/lang/VlangParserUtil.kt index 3aeb1766..4c7e8998 100644 --- a/src/main/kotlin/io/vlang/lang/VlangParserUtil.kt +++ b/src/main/kotlin/io/vlang/lang/VlangParserUtil.kt @@ -71,7 +71,7 @@ object VlangParserUtil : GeneratedParserUtilBase() { // } @JvmStatic - fun isModeOn(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int, mode: String?): Boolean { + fun isModeOn(builder: PsiBuilder, @Suppress("UNUSED") level: Int, mode: String?): Boolean { return getParsingModes(builder).getInt(mode) > 0 } @@ -149,23 +149,23 @@ object VlangParserUtil : GeneratedParserUtilBase() { @Suppress("UNUSED") @JvmStatic - fun isModeOff(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int, mode: String?): Boolean { + fun isModeOff(builder: PsiBuilder, @Suppress("UNUSED") level: Int, mode: String?): Boolean { return getParsingModes(builder).getInt(mode) == 0 } @JvmStatic - fun isLastIs(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int, mode: String?): Boolean { + fun isLastIs(builder: PsiBuilder, @Suppress("UNUSED") level: Int, mode: String?): Boolean { return getParsingModesStack(builder).peek() == mode } @Suppress("UNUSED") @JvmStatic - fun isLastNotIs(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int, mode: String?): Boolean { + fun isLastNotIs(builder: PsiBuilder, @Suppress("UNUSED") level: Int, mode: String?): Boolean { return getParsingModesStack(builder).peek() != mode } @JvmStatic - fun prevIsType(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int): Boolean { + fun prevIsType(builder: PsiBuilder, @Suppress("UNUSED") level: Int): Boolean { var tokenBefore = builder.rawLookup(-1) if (tokenBefore == VlangTokenTypes.WS) { tokenBefore = builder.rawLookup(-2) @@ -184,7 +184,7 @@ object VlangParserUtil : GeneratedParserUtilBase() { } @JvmStatic - fun prevIsNotFunType(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int): Boolean { + fun prevIsNotFunType(builder: PsiBuilder, @Suppress("UNUSED") level: Int): Boolean { val marker = builder.latestDoneMarker val type = marker?.tokenType return type !== FUNCTION_TYPE @@ -208,7 +208,7 @@ object VlangParserUtil : GeneratedParserUtilBase() { } @JvmStatic - fun gtGt(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int): Boolean { + fun gtGt(builder: PsiBuilder, @Suppress("UNUSED") level: Int): Boolean { val marker = builder.mark() if (!consumeToken(builder, GREATER)) { marker.rollbackTo() @@ -223,7 +223,7 @@ object VlangParserUtil : GeneratedParserUtilBase() { } @JvmStatic - fun leftBracket(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int): Boolean { + fun leftBracket(builder: PsiBuilder, @Suppress("UNUSED") level: Int): Boolean { val marker = builder.mark() if (!consumeToken(builder, LBRACK)) { marker.rollbackTo() @@ -254,7 +254,7 @@ object VlangParserUtil : GeneratedParserUtilBase() { } @JvmStatic - fun gtGtGt(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int): Boolean { + fun gtGtGt(builder: PsiBuilder, @Suppress("UNUSED") level: Int): Boolean { val marker = builder.mark() if (!consumeToken(builder, GREATER)) { marker.rollbackTo() @@ -273,17 +273,42 @@ object VlangParserUtil : GeneratedParserUtilBase() { } @JvmStatic - fun remapToIdentifier(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int): Boolean { + fun remapToIdentifier(builder: PsiBuilder, @Suppress("UNUSED") level: Int): Boolean { if (builder.tokenType == IDENTIFIER) { return true } - if (builder.tokenType in VlangTokenTypes.KEYWORDS.types || builder.tokenType in VlangTokenTypes.BOOL_LITERALS.types) { + + val currentToken = builder.tokenType + val nextToken = builder.lookAhead(1) + + // If mode checkForAccessModifiers is set, and it is access modifier ( pub: pub mut: __global: ) + // than skip remapping + if (isModeOn(builder, level, "checkForAccessModifiers") && ((currentToken in arrayOf(PUB, MUT, BUILTIN_GLOBAL) && nextToken == COLON) + || (currentToken in arrayOf(PUB, MUT) && nextToken in arrayOf(PUB, MUT) && builder.lookAhead(2) == COLON))) { + return false + } + + if (currentToken in VlangTokenTypes.KEYWORDS.types || currentToken in VlangTokenTypes.BOOL_LITERALS.types) { builder.remapCurrentToken(IDENTIFIER) return true } return false } +// @JvmStatic +// fun identOrKeyword(builder: PsiBuilder, @Suppress("UNUSED") level: Int): Boolean { +// val currentToken = builder.tokenType ?: return false +// val m = builder.mark() +// var r = false +// if (currentToken in VlangTokenTypes.KEYWORDS.types || currentToken in VlangTokenTypes.BOOL_LITERALS.types) { +// r = consumeToken(builder, currentToken) +// m.collapse(IDENTIFIER) +// } else { +// m.rollbackTo() +// } +// return r +// } + @JvmStatic fun callExpr(builder: PsiBuilder, level: Int): Boolean { val m = builder.latestDoneMarker @@ -413,7 +438,7 @@ object VlangParserUtil : GeneratedParserUtilBase() { } @JvmStatic - fun enterMode(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int, mode: String): Boolean { + fun enterMode(builder: PsiBuilder, @Suppress("UNUSED") level: Int, mode: String): Boolean { val flags = getParsingModes(builder) flags.addTo(mode, 1) val stack = getParsingModesStack(builder) @@ -421,7 +446,7 @@ object VlangParserUtil : GeneratedParserUtilBase() { return true } - private fun exitMode(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int, mode: String, safe: Boolean, all: Boolean = false): Boolean { + private fun exitMode(builder: PsiBuilder, @Suppress("UNUSED") level: Int, mode: String, safe: Boolean, all: Boolean = false): Boolean { val flags = getParsingModes(builder) val count = flags.getInt(mode) if (count == 1) { @@ -473,7 +498,7 @@ object VlangParserUtil : GeneratedParserUtilBase() { } @JvmStatic - fun endOfLimit(builder: PsiBuilder, @Suppress("UNUSED_PARAMETER") level: Int): Boolean { + fun endOfLimit(builder: PsiBuilder, @Suppress("UNUSED") level: Int): Boolean { val tokenText = builder.tokenText return !(tokenText == "limit" || tokenText == "asc" || tokenText == "desc") } diff --git a/src/main/kotlin/io/vlang/lang/grammar/v.bnf b/src/main/kotlin/io/vlang/lang/grammar/v.bnf index 9fa99732..753abf0d 100644 --- a/src/main/kotlin/io/vlang/lang/grammar/v.bnf +++ b/src/main/kotlin/io/vlang/lang/grammar/v.bnf @@ -14,6 +14,7 @@ psiPackage='io.vlang.lang.psi' psiImplPackage='io.vlang.lang.psi.impl' psiImplUtilClass="io.vlang.lang.psi.impl.VlangPsiImplUtil" + parserImports="static io.vlang.lang.VlangParserHooks.*" parserUtilClass="io.vlang.lang.VlangParserUtil" tokens=[ @@ -139,7 +140,7 @@ private list_separator ::= semi | ',' // #!/usr/bin/env v ShebangClause ::= shebang -// [attr] module +// @[attr] module ModuleClause ::= Attributes? module identifier semi { pin=2 methods=[getName] @@ -252,8 +253,7 @@ Attributes ::= Attribute (semi Attribute)* semi? { } // @[] or [] Attribute ::= ('@[' AttributeExpressions ']') | ('[' AttributeExpressions ']') { - pin("@[")=1 - pin("[")=1 + pin(".*")=1 stubClass="io.vlang.lang.stubs.VlangAttributeStub" } // [; ] @@ -398,7 +398,8 @@ AnonymousStructType ::= struct '{' FieldsGroup* '}' { methods=[getFieldList getOwnFieldList] } -StructType ::= (struct | union) identifier GenericParameters? ImplementsClause? '{' FieldsGroup* '}' { +StructType ::= (struct | union) identifier GenericParameters? ImplementsClause? '{' <> FieldsGroup* <> '}' { +//StructType ::= (struct | union) identifier GenericParameters? ImplementsClause? '{' FieldsGroup* '}' { pin=1 implements="io.vlang.lang.psi.VlangFieldListOwner" methods=[getFieldList getOwnFieldList getEmbeddedStructs getEmbeddedStructList isUnion] @@ -427,12 +428,13 @@ private WithoutModifiersFieldsGroup ::= !MemberModifiers FieldDeclarations private FieldDeclarations ::= FieldDeclaration+ FieldDeclaration ::= (PlainFieldDeclaration | EmbeddedDefinition) semi? -private PlainFieldDeclaration ::= FieldDefinition Type Attribute? DefaultFieldValue? +private PlainFieldDeclaration ::= FieldDefinition Type DefaultFieldValue? Attribute? DefaultFieldValue ::= '=' Expression {pin=1} -FieldDefinition ::= identifier { +FieldDefinition ::= <> identifier { methods=[getQualifier getQualifiedName getTypeInner isPublic isMutable isPrimary makeMutable makeImmutable getOwner] implements="io.vlang.lang.psi.VlangMutabilityOwner" stubClass="io.vlang.lang.stubs.VlangFieldDefinitionStub" +// hooks=[MyHook='"FieldDefinition remapping"'] } EmbeddedDefinition ::= Type { @@ -447,7 +449,8 @@ InterfaceDeclaration ::= Attributes? SymbolVisibility? InterfaceType { methods=[getName getIdentifier getTypeInner] } -InterfaceType ::= interface identifier GenericParameters? '{' MembersGroup* '}' { +InterfaceType ::= interface identifier GenericParameters? '{' <> MembersGroup* <> '}' { +//InterfaceType ::= interface identifier GenericParameters? '{' MembersGroup* '}' { pin=1 implements="io.vlang.lang.psi.VlangFieldListOwner" methods=[getFieldList getOwnFieldList getMethodList getEmbeddedInterfaces getEmbeddedInterfacesList] @@ -585,15 +588,15 @@ private fnDecl ::= Attributes? SymbolVisibility? fn { pin=3 } -FunctionDeclaration ::= fnDecl identifier GenericParameters? Signature BlockWithConsume? { - pin=4 +FunctionDeclaration ::= fnDecl <> identifier GenericParameters? Signature BlockWithConsume? { + pin=5 stubClass="io.vlang.lang.stubs.VlangFunctionDeclarationStub" methods=[getName getTypeInner isDefinition isNoReturn isGeneric isCompileTime] mixin="io.vlang.lang.psi.impl.VlangFunctionDeclarationWithScopeHolder" } MethodDeclaration ::= fnDecl '(' Receiver ')' MethodName GenericParameters? Signature BlockWithConsume? { - pin=5 + pin=7 stubClass="io.vlang.lang.stubs.VlangMethodDeclarationStub" methods=[getReceiverType getTypeInner getIdentifier getQualifiedName getOwner isMutable byReference] mixin="io.vlang.lang.psi.impl.VlangMethodDeclarationWithScopeHolder" @@ -607,7 +610,7 @@ StaticMethodDeclaration ::= fnDecl TypeReferenceExpression '.' identifier Generi } // or for overload -MethodName ::= identifier | AddOp | MulOp | RelOp +MethodName ::= <> identifier | AddOp | MulOp | RelOp // [] Receiver ::= VarModifiers? identifier Type ','? { diff --git a/src/main/kotlin/io/vlang/lang/psi/impl/VlangPsiImplUtil.kt b/src/main/kotlin/io/vlang/lang/psi/impl/VlangPsiImplUtil.kt index 68dbebc8..b737d507 100644 --- a/src/main/kotlin/io/vlang/lang/psi/impl/VlangPsiImplUtil.kt +++ b/src/main/kotlin/io/vlang/lang/psi/impl/VlangPsiImplUtil.kt @@ -18,6 +18,7 @@ import io.vlang.ide.codeInsight.VlangCodeInsightUtil import io.vlang.ide.codeInsight.VlangGenericInferer import io.vlang.ide.codeInsight.VlangTypeInferenceUtil import io.vlang.lang.VlangTypes +import io.vlang.lang.VlangTypes.IDENTIFIER import io.vlang.lang.VlangTypes.SAFE_DOT import io.vlang.lang.codeInsight.controlFlow.VlangControlFlow import io.vlang.lang.codeInsight.controlFlow.VlangControlFlowUtil @@ -57,7 +58,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun getErrorDescription(@Suppress("UNUSED_PARAMETER") o: VlangLastComma): String { + fun getErrorDescription(@Suppress("UNUSED", "UNUSED_PARAMETER") o: VlangLastComma): String { return "Trailing comma not supported" } @@ -93,6 +94,16 @@ object VlangPsiImplUtil { return o.methodName.identifier } + @JvmStatic + fun getIdentifier(o: VlangReferenceExpression): PsiElement { + return o.node.findChildByType(IDENTIFIER)!!.psi + } + + @JvmStatic + fun getIdentifier(o: VlangFieldDefinition): PsiElement { + return o.node.findChildByType(IDENTIFIER)!!.psi + } + @JvmStatic fun getIdentifier(o: VlangStaticMethodDeclaration): PsiElement { return o.getIdentifier() @@ -104,7 +115,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun getTypeInner(o: VlangInterfaceDeclaration, @Suppress("UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { + fun getTypeInner(o: VlangInterfaceDeclaration, @Suppress("UNUSED", "UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { return o.interfaceType.toEx() } @@ -259,7 +270,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun getTypeInner(o: VlangTypeAliasDeclaration, @Suppress("UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { + fun getTypeInner(o: VlangTypeAliasDeclaration, @Suppress("UNUSED", "UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { return o.aliasType.toEx() } @@ -359,7 +370,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun getQualifier(@Suppress("UNUSED_PARAMETER") o: VlangFieldName): VlangCompositeElement? { + fun getQualifier(@Suppress("UNUSED", "UNUSED_PARAMETER") o: VlangFieldName): VlangCompositeElement? { return null } @@ -559,7 +570,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun getType(o: VlangEmbeddedDefinition, @Suppress("UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { + fun getType(o: VlangEmbeddedDefinition, @Suppress("UNUSED", "UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { return o.type.toEx() } @@ -664,7 +675,7 @@ object VlangPsiImplUtil { val text = value.text.removePrefix("0b").removePrefix("0o").removePrefix("0x") return try { text.toLong(radix) - } catch (e: NumberFormatException) { + } catch (_: NumberFormatException) { null } } @@ -687,12 +698,12 @@ object VlangPsiImplUtil { } @JvmStatic - fun getTypeInner(o: VlangEnumFieldDefinition, @Suppress("UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { + fun getTypeInner(o: VlangEnumFieldDefinition, @Suppress("UNUSED", "UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { return o.parentOfType().toEx() } @JvmStatic - fun isPublic(@Suppress("UNUSED_PARAMETER") o: VlangInterfaceMethodDefinition): Boolean { + fun isPublic(@Suppress("UNUSED", "UNUSED_PARAMETER") o: VlangInterfaceMethodDefinition): Boolean { return true } @@ -718,12 +729,12 @@ object VlangPsiImplUtil { } @JvmStatic - fun makeMutable(@Suppress("UNUSED_PARAMETER") o: VlangFieldDefinition) { + fun makeMutable(@Suppress("UNUSED", "UNUSED_PARAMETER") o: VlangFieldDefinition) { // TODO: implement } @JvmStatic - fun makeImmutable(@Suppress("UNUSED_PARAMETER") o: VlangFieldDefinition) { + fun makeImmutable(@Suppress("UNUSED", "UNUSED_PARAMETER") o: VlangFieldDefinition) { // TODO: implement } @@ -791,7 +802,7 @@ object VlangPsiImplUtil { return o.receiver.type } - @Suppress("UNUSED") + @Suppress("UNUSED", "UNUSED_PARAMETER") fun getTypeReference(o: VlangType?): VlangTypeReferenceExpression? { if (o is VlangPointerType) { return PsiTreeUtil.findChildOfAnyType(o, VlangTypeReferenceExpression::class.java) @@ -847,7 +858,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun getQualifier(@Suppress("UNUSED_PARAMETER") o: VlangFieldDefinition): VlangCompositeElement? { + fun getQualifier(@Suppress("UNUSED", "UNUSED_PARAMETER") o: VlangFieldDefinition): VlangCompositeElement? { return null } @@ -1146,7 +1157,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun isPublic(@Suppress("UNUSED_PARAMETER") o: VlangParamDefinition): Boolean = true + fun isPublic(@Suppress("UNUSED", "UNUSED_PARAMETER") o: VlangParamDefinition): Boolean = true class VlangLiteralFileReferenceSet( str: String, @@ -1165,7 +1176,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun isValidHost(@Suppress("UNUSED_PARAMETER") o: VlangStringLiteral): Boolean { + fun isValidHost(@Suppress("UNUSED", "UNUSED_PARAMETER") o: VlangStringLiteral): Boolean { return true } @@ -1350,7 +1361,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun getQualifier(@Suppress("UNUSED_PARAMETER") o: VlangEnumFetch): VlangCompositeElement? { + fun getQualifier(@Suppress("UNUSED", "UNUSED_PARAMETER") o: VlangEnumFetch): VlangCompositeElement? { return null } @@ -1437,12 +1448,12 @@ object VlangPsiImplUtil { } @JvmStatic - fun getTypeInner(o: VlangReceiver, @Suppress("UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { + fun getTypeInner(o: VlangReceiver, @Suppress("UNUSED", "UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { return o.type.toEx() } @JvmStatic - fun getTypeInner(o: VlangFieldDefinition, @Suppress("UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { + fun getTypeInner(o: VlangFieldDefinition, @Suppress("UNUSED", "UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { val fieldDeclaration = o.parent as? VlangFieldDeclaration return fieldDeclaration?.type.toEx() } @@ -1465,14 +1476,14 @@ object VlangPsiImplUtil { } @JvmStatic - fun getTypeInner(o: VlangStructDeclaration, @Suppress("UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { + fun getTypeInner(o: VlangStructDeclaration, @Suppress("UNUSED", "UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx { return o.structType.toEx() } @JvmStatic fun getTypeInner( o: VlangEnumDeclaration, - @Suppress("UNUSED_PARAMETER") context: ResolveState?, + @Suppress("UNUSED", "UNUSED_PARAMETER") context: ResolveState?, ): VlangTypeEx { return o.enumType.toEx() } @@ -1485,7 +1496,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun getUnderlyingType(@Suppress("UNUSED_PARAMETER") o: VlangType): VlangType? { + fun getUnderlyingType(@Suppress("UNUSED", "UNUSED_PARAMETER") o: VlangType): VlangType? { return null // TODO } @@ -1530,7 +1541,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun getTypeInner(param: VlangGenericParameter, @Suppress("UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx? { + fun getTypeInner(param: VlangGenericParameter, @Suppress("UNUSED", "UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx? { if (param.name == null) { return null } @@ -1996,7 +2007,7 @@ object VlangPsiImplUtil { private fun processMapMethodCall( resolved: VlangMethodDeclaration, - @Suppress("UNUSED_PARAMETER") signature: VlangSignature?, + @Suppress("UNUSED", "UNUSED_PARAMETER") signature: VlangSignature?, expr: VlangCallExpr, ): VlangTypeEx? { val receiverTypeEx = resolved.receiverType.toEx() @@ -2153,7 +2164,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun getSymbolVisibility(@Suppress("UNUSED_PARAMETER") o: VlangVarDefinition): VlangSymbolVisibility? { + fun getSymbolVisibility(@Suppress("UNUSED", "UNUSED_PARAMETER") o: VlangVarDefinition): VlangSymbolVisibility? { return null } @@ -2195,7 +2206,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun isPublic(@Suppress("UNUSED_PARAMETER") o: VlangVarDefinition): Boolean = true + fun isPublic(@Suppress("UNUSED", "UNUSED_PARAMETER") o: VlangVarDefinition): Boolean = true @JvmStatic fun isMutable(o: VlangVarDefinition): Boolean { @@ -2261,7 +2272,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun isPublic(@Suppress("UNUSED_PARAMETER") o: VlangReceiver): Boolean = true + fun isPublic(@Suppress("UNUSED", "UNUSED_PARAMETER") o: VlangReceiver): Boolean = true fun getBuiltinType(name: String, context: PsiElement): VlangType? { val builtin = VlangConfiguration.getInstance(context.project).builtinLocation @@ -2276,7 +2287,7 @@ object VlangPsiImplUtil { } @JvmStatic - fun getTypeInner(o: VlangSignatureOwner, @Suppress("UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx? { + fun getTypeInner(o: VlangSignatureOwner, @Suppress("UNUSED", "UNUSED_PARAMETER") context: ResolveState?): VlangTypeEx? { return VlangFunctionTypeEx.from(o) } @@ -2391,7 +2402,7 @@ object VlangPsiImplUtil { rightType: VlangTypeEx, ): VlangTypeEx? { val method = rightType.findMethod(o.project, "next") ?: return VlangAnyTypeEx.INSTANCE - val result = method.getSignature()?.result ?: return VlangAnyTypeEx.INSTANCE + val result = method.getSignature().result ?: return VlangAnyTypeEx.INSTANCE val resultType = result.type.toEx() return unwrapOptionOrResultType(resultType) } diff --git a/src/test/kotlin/io/vlang/lang/parser/ParserTest.kt b/src/test/kotlin/io/vlang/lang/parser/ParserTest.kt index f0c2bc05..dd4c0e79 100644 --- a/src/test/kotlin/io/vlang/lang/parser/ParserTest.kt +++ b/src/test/kotlin/io/vlang/lang/parser/ParserTest.kt @@ -27,4 +27,6 @@ class ParserTest : ParserTestBase("parser", "v", VlangParserDefinition()) { fun `test sql`() = doTest(true) fun `test static function`() = doTest(true) fun `test enum keyword fields`() = doTest(true) + fun `test struct keyword fields`() = doTest(true) + fun `test keyword as function name`() = doTest(true) }