From 055cc044a381a534c94541a4cab8f2fa27a74905 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Thu, 26 May 2022 14:17:01 +0100 Subject: Grammar fixes --- .../bnf/ai/vespa/intellij/schema/parser/sd.bnf | 34 ++++++++++++---------- .../main/java/ai/vespa/intellij/schema/SdUtil.java | 2 +- .../intellij/schema/psi/SdDeclarationType.java | 5 ++-- .../schema/psi/impl/SdNamedElementImpl.java | 17 +++++------ 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/integration/intellij/src/main/bnf/ai/vespa/intellij/schema/parser/sd.bnf b/integration/intellij/src/main/bnf/ai/vespa/intellij/schema/parser/sd.bnf index 87c4a012fb5..77e1bb12a74 100644 --- a/integration/intellij/src/main/bnf/ai/vespa/intellij/schema/parser/sd.bnf +++ b/integration/intellij/src/main/bnf/ai/vespa/intellij/schema/parser/sd.bnf @@ -111,7 +111,7 @@ AnnotationFieldDefinition ::= field IdentifierVal type FieldTypeName '{' '}' // The *Expr alternatives are consumed greedily so order matters. //------------------------- RankingExpression ::= LiteralOrGenerateTensorExpr | FilePathExpr | ParenthesisedExpr | BooleanExpr | ArithmeticExpr | IfFunctionExpr | - QueryDefinitionExpr | FunctionCallOrLambdaExpr | InListRankingExpr | PrimitiveExpr | SliceExpr + FunctionCallOrLambdaExpr | RankfeatureExpr | InListRankingExpr | PrimitiveExpr | SliceExpr FilePathExpr ::= file ':' (FilePath | WordWrapper) @@ -127,7 +127,7 @@ ArithmeticExpr ::= RankingExpression ArithmeticOperator RankingExpression ArithmeticOperator ::= '+' | '-' | '*' | '/' | '%' | '^' | "||" | "&&" -QueryDefinitionExpr ::= QueryDefinition | ItemRawScoreDefinition +RankFeatureExpr ::= RankFeature // Rough parsing but hard to do better due to greediness: If this is a lambda arg expressions must be identifiers FunctionCallOrLambdaExpr ::= IdentifierWithDashVal '(' RankingExpression (COMMA RankingExpression)* ')' ('.' IdentifierWithDashVal)? @@ -178,22 +178,22 @@ private RankProfileBodyOptions ::= MatchPhaseDefinition | NumThreadsDefinition | MatchPhaseDefinition ::= match-phase '{' MatchPhaseBody '}' MatchPhaseBody ::= MatchPhaseBodyOptions+ -MatchPhaseBodyOptions ::= (attribute ':' DottedIdentifiers) | (order ':' (ascending | descending)) | (max-hits ':' ('-')? INTEGER_REG) +MatchPhaseBodyOptions ::= (attribute ':' DottedIdentifier) | (order ':' (ascending | descending)) | (max-hits ':' ('-')? INTEGER_REG) | DiversityDefinition | (evaluation-point ':' ('-')? FLOAT_REG) | (pre-post-filter-tipping-point ':' ('-')? FLOAT_REG) // Does not support zero-or-one occurrences DiversityDefinition ::= diversity '{' DiversityBody '}' DiversityBody ::= DiversityBodyOptions* -private DiversityBodyOptions ::= (attribute ':' DottedIdentifiers) | (min-groups ':' ('-')? INTEGER_REG) | (cutoff-factor ':' ('-')? FLOAT_REG) | +private DiversityBodyOptions ::= (attribute ':' DottedIdentifier) | (min-groups ':' ('-')? INTEGER_REG) | (cutoff-factor ':' ('-')? FLOAT_REG) | (cutoff-strategy ':' (strict | loose)) private NumThreadsDefinition ::= num-threads-per-search ':' INTEGER_REG private TermwiseLimitDefinition ::= termwise-limit ':' ('-')? (FLOAT_REG | INTEGER_REG) private MinHitsDefinition ::= min-hits-per-thread ':' ('-')? INTEGER_REG private NumSearchPartitionDefinition ::= num-search-partition ':' INTEGER_REG -FieldWeightDefinition ::= weight DottedIdentifiers ':' INTEGER_REG +FieldWeightDefinition ::= weight DottedIdentifier ':' INTEGER_REG StrictDefinition ::= strict ':' (true | false) InputsDefinition ::= inputs '{' InputDefinition* '}' -InputDefinition ::= ( QueryDefinition | IdentifierVal) +InputDefinition ::= ( QueryFeature | IdentifierVal) (':')? ( TensorType | "double" )? (':' ( TensorValue | FLOAT_REG | INTEGER_REG) )? @@ -210,20 +210,23 @@ private SecondPhaseBodyOptions ::= (rerank-count ':' INTEGER_REG) | ExpressionDe RankPropertiesDefinition ::= rank-properties '{' RankPropertiesBody '}' RankPropertiesBody ::= (RankPropertiesKey ':' RankPropertiesValue)+ RankPropertiesKey ::= (IdentifierWithDashVal | STRING_REG | '(' | ')' | '.' | COMMA | '$' | INTEGER_REG)+ -RankPropertiesValue ::= (('-')? INTEGER_REG) | (('-')? FLOAT_REG) | WORD_REG | DottedIdentifiers | STRING_REG +RankPropertiesValue ::= (('-')? INTEGER_REG) | (('-')? FLOAT_REG) | WORD_REG | DottedIdentifier | STRING_REG -FunctionDefinition ::= (function | macro) inline? IdentifierVal ( '()' | '(' (ArgumentDefinition (COMMA ArgumentDefinition)*)? ')' ) +FunctionDefinition ::= (function | macro) inline? IdentifierVal Arguments '{' ExpressionDefinition '}' { mixin="ai.vespa.intellij.schema.psi.impl.SdNamedElementImpl" implements=["ai.vespa.intellij.schema.psi.SdFunctionDefinitionInterface" "ai.vespa.intellij.schema.psi.SdNamedElement"] } + +Arguments ::= '()' | ( '(' (ArgumentDefinition (COMMA ArgumentDefinition)*)? ')' ) + ArgumentDefinition ::= IdentifierVal { mixin="ai.vespa.intellij.schema.psi.impl.SdNamedElementImpl" implements=["ai.vespa.intellij.schema.psi.SdDeclaration" "ai.vespa.intellij.schema.psi.SdNamedElement"] } SummaryFeaturesDefinition ::= summary-features ((':' RankFeature+) | ((inherits IdentifierWithDashVal)? '{' RankFeature* '}')) -i + MatchFeaturesDefinition ::= match-features ((':' RankFeature+) | ((inherits IdentifierWithDashVal)? '{' RankFeature* '}')) RankFeaturesDefinition ::= rank-features ((':' RankFeature+) | ('{' RankFeature* '}')) @@ -234,16 +237,15 @@ InnerConstantDefinition ::= ( ("constant" '(' IdentifierVal ')') | IdentifierVal (':')? ( TensorType | "double" )? (':')? ( TensorValue | FLOAT_REG | INTEGER_REG | (file ':' FilePath) | (uri ':' UriPath)) -RankFeature ::= QueryDefinition | ItemRawScoreDefinition | FunctionCallExpr | DottedIdentifierWithDash -QueryDefinition ::= "query" '(' IdentifierWithDashVal ')' +RankFeature ::= IdentifierVal Arguments ( '.' IdentifierVal )? { mixin="ai.vespa.intellij.schema.psi.impl.SdNamedElementImpl" implements=["ai.vespa.intellij.schema.psi.SdDeclaration" "ai.vespa.intellij.schema.psi.SdNamedElement"] } -ItemRawScoreDefinition ::= "itemRawScore" '(' IdentifierVal ')' - { mixin="ai.vespa.intellij.schema.psi.impl.SdNamedElementImpl" - implements=["ai.vespa.intellij.schema.psi.SdDeclaration" "ai.vespa.intellij.schema.psi.SdNamedElement"] - } - +QueryFeature ::= "query" '(' IdentifierWithDashVal ')' + { mixin="ai.vespa.intellij.schema.psi.impl.SdNamedElementImpl" + implements=["ai.vespa.intellij.schema.psi.SdDeclaration" "ai.vespa.intellij.schema.psi.SdNamedElement"] + } + //------------------------- //---- Document rules ----- //------------------------- diff --git a/integration/intellij/src/main/java/ai/vespa/intellij/schema/SdUtil.java b/integration/intellij/src/main/java/ai/vespa/intellij/schema/SdUtil.java index 1b45c1bf4fd..b21790642cc 100644 --- a/integration/intellij/src/main/java/ai/vespa/intellij/schema/SdUtil.java +++ b/integration/intellij/src/main/java/ai/vespa/intellij/schema/SdUtil.java @@ -48,7 +48,7 @@ public class SdUtil { String rankProfileName; if (rankProfile != null) { rankProfileName = rankProfile.getName(); - List args = function.getArgumentDefinitionList(); + List args = function.getArguments().getArgumentDefinitionList(); StringBuilder text = new StringBuilder(rankProfileName + "." + function.getName() + "("); for (int i = 0; i < args.size(); i++) { text.append(args.get(i).getName()); diff --git a/integration/intellij/src/main/java/ai/vespa/intellij/schema/psi/SdDeclarationType.java b/integration/intellij/src/main/java/ai/vespa/intellij/schema/psi/SdDeclarationType.java index bb140c4ce75..6dabbc7a5fd 100644 --- a/integration/intellij/src/main/java/ai/vespa/intellij/schema/psi/SdDeclarationType.java +++ b/integration/intellij/src/main/java/ai/vespa/intellij/schema/psi/SdDeclarationType.java @@ -21,9 +21,8 @@ public enum SdDeclarationType { RANK_PROFILE("Rank Profile"), FUNCTION("Function"), FIUNCTION_ARGUMENT("Function argument"), - QUERY("Query (first use in file)"), - ITEM_RAW_SCORE("ItemRawScore (first use in file)"); - + FEATURE("Feature (first use in file)"); + private final String typeName; SdDeclarationType(String name) { this.typeName = name; diff --git a/integration/intellij/src/main/java/ai/vespa/intellij/schema/psi/impl/SdNamedElementImpl.java b/integration/intellij/src/main/java/ai/vespa/intellij/schema/psi/impl/SdNamedElementImpl.java index 8a2588ecf35..4d54eefee72 100644 --- a/integration/intellij/src/main/java/ai/vespa/intellij/schema/psi/impl/SdNamedElementImpl.java +++ b/integration/intellij/src/main/java/ai/vespa/intellij/schema/psi/impl/SdNamedElementImpl.java @@ -22,9 +22,8 @@ import ai.vespa.intellij.schema.psi.SdElementFactory; import ai.vespa.intellij.schema.psi.SdFunctionDefinition; import ai.vespa.intellij.schema.psi.SdIdentifier; import ai.vespa.intellij.schema.psi.SdImportFieldDefinition; -import ai.vespa.intellij.schema.psi.SdItemRawScoreDefinition; import ai.vespa.intellij.schema.psi.SdNamedElement; -import ai.vespa.intellij.schema.psi.SdQueryDefinition; +import ai.vespa.intellij.schema.psi.SdRankFeature; import ai.vespa.intellij.schema.psi.SdRankProfileDefinition; import ai.vespa.intellij.schema.psi.SdSchemaAnnotationDefinition; import ai.vespa.intellij.schema.psi.SdSchemaFieldDefinition; @@ -36,6 +35,7 @@ import javax.swing.Icon; /** * This abstract class is used to wrap a Psi Element with SdNamedElement interface, which enables the element to be a * "name owner" (like an identifier). It allows the element to take a part in references, find usages and more. + * * @author Shahar Ariel */ public abstract class SdNamedElementImpl extends ASTWrapperPsiElement implements SdNamedElement { @@ -50,7 +50,7 @@ public abstract class SdNamedElementImpl extends ASTWrapperPsiElement implements ASTNode asNode = this.getNode().findChildByType(SdTypes.AS); node = this.getNode().findChildByType(SdTypes.IDENTIFIER_VAL, asNode); } else if (this instanceof SdRankProfileDefinition || this instanceof SdDocumentSummaryDefinition - || this instanceof SdQueryDefinition) { + || this instanceof SdRankFeature) { node = this.getNode().findChildByType(SdTypes.IDENTIFIER_WITH_DASH_VAL); } else { node = this.getNode().findChildByType(SdTypes.IDENTIFIER_VAL); @@ -94,10 +94,8 @@ public abstract class SdNamedElementImpl extends ASTWrapperPsiElement implements return SdDeclarationType.STRUCT_FIELD; } else if (this instanceof SdAnnotationFieldDefinition) { return SdDeclarationType.ANNOTATION_FIELD; - } else if (this instanceof SdQueryDefinition) { - return SdDeclarationType.QUERY; - } else if (this instanceof SdItemRawScoreDefinition) { - return SdDeclarationType.ITEM_RAW_SCORE; + } else if (this instanceof SdRankFeature) { + return SdDeclarationType.FEATURE; } else { return null; } @@ -147,7 +145,7 @@ public abstract class SdNamedElementImpl extends ASTWrapperPsiElement implements } SdRankProfileDefinition rankProfileParent = PsiTreeUtil.getParentOfType(element, SdRankProfileDefinition.class); if (rankProfileParent != null) { - if (element instanceof SdQueryDefinition || element instanceof SdItemRawScoreDefinition) { + if (element instanceof SdRankFeature) { return element.getName() + " in " + rankProfileParent.getName(); } return rankProfileParent.getName() + "." + element.getName(); @@ -163,8 +161,7 @@ public abstract class SdNamedElementImpl extends ASTWrapperPsiElement implements @Override public Icon getIcon(boolean unused) { if (element instanceof SdSchemaFieldDefinition || element instanceof SdDocumentFieldDefinition || - element instanceof SdAnnotationFieldDefinition || element instanceof SdQueryDefinition || - element instanceof SdItemRawScoreDefinition) { + element instanceof SdAnnotationFieldDefinition || element instanceof SdRankFeature) { return AllIcons.Nodes.Field; } else if (element instanceof SdStructFieldDefinition || element instanceof SdDocumentStructFieldDefinition) { -- cgit v1.2.3