Class ExpressionParser
java.lang.Object
org.cyclops.integrateddynamics.core.evaluate.expression.tree.ExpressionParser
Parses the text form of expressions, as written by
ExpressionPrinter.printExact(Expression, ValueDeseralizationContext, IntFunction, Function, IntFunction).
expression := [parameters "=>"] ternary
parameters := NAME | "(" parameter ("," parameter)* ")"
parameter := NAME [":" [NAME ":"] NAME]
ternary := or ["?" ternary ":" ternary]
or := and ("||" and)*
and := equality ("&&" equality)*
equality := relational (("==" | "!=") relational)*
relational := additive (("<" | "<=" | ">" | ">=") additive)*
additive := multiplicative (("+" | "-") multiplicative)*
multiplicative := unary (("*" | "/" | "%") unary)*
unary := "!" unary | ("-" NUMBER | primary) ("." NAME arguments)*
primary := NUMBER | STRING | "true" | "false" | "@" TYPE SNBT | "#" (ID | NAME | STRING) | "?"
| "[" [ternary ("," ternary)* [","]] "]" | NAME arguments | NAME | "(" (NAME | SYMBOL) ")" | "(" ternary ")"
arguments := "(" [ternary ("," ternary)*] ")"
Operator names are resolved by OperatorNames, using the type of the first argument.
A ? is an empty slot, and (name) an operator used as a value.
As in Integrated Scripting, a.f(b) is f(a, b), calling a parameter as in f(a) is apply(f, a),
+ joins strings, strings can be in single quotes, and ->, === and !==
can be written for =>, == and !=.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic final recordWhat can be completed at a cursor.static final recordWhat the parser needs to know about the world.static final recordstatic final recordstatic final recordstatic final record -
Field Summary
FieldsModifier and TypeFieldDescription -
Method Summary
Modifier and TypeMethodDescriptionstatic ExpressionParser.Completioncomplete(String text, int cursor, ExpressionParser.Context context) Find what can be completed at a cursor, as far as the text before it tells.static IValueType<?> getListType(List<? extends IValue> values) static intgetParameterList(String text, ExpressionParser.Context context) Find the parameters in front of a text, which does not need to parse as a whole.static StringgetTypeName(IValueType<?> valueType) static List<IValueType<?>> getTypes(ExpressionParser.Types types, ExpressionParser.Context context) static IValueType<?> getValueType(String name) static booleanisIdentifier(String text) static booleanisTypeNamePart(char c) static booleanisValidParameterName(String name) static Expressionparse(String text, ExpressionParser.Context context) static IValueparseLiteral(String text) static ExpressionParser.Tokenizedtokenize(String text, ExpressionParser.Context context) Parse the text of an expression, and split the text into tokens that tell what node each part belongs to, asExpressionPrinter.tokenizeExact(Expression, ValueDeseralizationContext, IntFunction, Function, ExpressionTypeChecker.Result)does for printed text, so typed text can be shown as typed.
-
Field Details
-
INFIX_SYMBOLS
-
PREFIX_SYMBOLS
-
-
Method Details
-
parseLiteral
-
getMaxLength
public static int getMaxLength()- Returns:
- The maximum length of the text of an expression, from the server config, which clients get when they join.
-
parse
public static Expression parse(String text, ExpressionParser.Context context) throws ExpressionParseException - Parameters:
text- The text of an expression.context- What the parser needs to know about the world.- Returns:
- The expression.
- Throws:
ExpressionParseException- If the text is not a valid expression.
-
tokenize
public static ExpressionParser.Tokenized tokenize(String text, ExpressionParser.Context context) throws ExpressionParseException Parse the text of an expression, and split the text into tokens that tell what node each part belongs to, asExpressionPrinter.tokenizeExact(Expression, ValueDeseralizationContext, IntFunction, Function, ExpressionTypeChecker.Result)does for printed text, so typed text can be shown as typed.- Parameters:
text- The text of an expression.context- What the parser needs to know about the world.- Returns:
- The expression and the tokens of the text.
- Throws:
ExpressionParseException- If the text is not a valid expression.
-
complete
public static ExpressionParser.Completion complete(String text, int cursor, ExpressionParser.Context context) Find what can be completed at a cursor, as far as the text before it tells.- Parameters:
text- The text of an expression.cursor- The position of the cursor.context- What the parser needs to know about the world.- Returns:
- What can be completed.
-
getParameterList
@Nullable public static ExpressionParser.ParameterList getParameterList(String text, ExpressionParser.Context context) Find the parameters in front of a text, which does not need to parse as a whole.- Parameters:
text- The text of an expression.context- What the parser needs to know about the world.- Returns:
- The parameters, or null if there are none.
-
getTypes
public static List<IValueType<?>> getTypes(ExpressionParser.Types types, ExpressionParser.Context context) - Parameters:
types- A type that is being typed.context- What the parser needs to know about the world.- Returns:
- The types whose name starts with what is typed, or whose name without the namespace of an add-on does, ordered by name, those of Integrated Dynamics first. For parameters, only the types they can have.
-
isValidParameterName
- Parameters:
name- A parameter name.- Returns:
- If the name can be written in the text form.
-
isIdentifier
- Parameters:
text- A text.- Returns:
- If the text is a single name.
-
getTypeName
- Parameters:
valueType- A value type.- Returns:
- The name of the type in the text form, see
IValueType.getExpressionName().
-
getValueType
- Parameters:
name- The name of a type in the text form, in any case, as inIntegerorinteger. Unique names are read too, as initemstackorintegratedmekanism:chemicalstack, where the namespace can be left out when no other type has that name.- Returns:
- The type, or null if unknown or ambiguous.
-
isTypeNamePart
public static boolean isTypeNamePart(char c) - Parameters:
c- A character.- Returns:
- If it can be part of the name of a type after
@, which can contain a namespace.
-
getListType
- Parameters:
values- The values of a list.- Returns:
- The type of a list literal with these values: the type they share, or Any if they differ or there are none.
-