SpelExpressionParser class

The parser of the Spring Expression Language: it turns expression text into an Expression you can evaluate.

This is the starting point for evaluating expressions yourself, such as rules or message templates kept in configuration. The parser keeps no state between calls: keep one instance, parse each text once and keep the resulting Expression, which can be evaluated many times against different contexts and roots. A SpelParserConfiguration sets the limits that protect against hostile text (expression length, nesting depth, operations per evaluation) and auto-grow.

// A greeting and a template, evaluated against the same values.
final parser = SpelExpressionParser();
final context = StandardEvaluationContext({'name': 'Ada', 'price': 5});
parser.parseExpression("'Hello ' + name").getValue(context);
// 'Hello Ada'
parser
    .parseExpression('Total: #{price * 2}', ParserContext.template)
    .getValue(context); // 'Total: 10'

Spring (Java):

ExpressionParser parser = new SpelExpressionParser();
parser.parseExpression("'Hello ' + name").getValue(context);
parser.parseExpression("Total: #{price * 2}",
    ParserContext.TEMPLATE_EXPRESSION).getValue(context);

Differences from Spring: no compiler mode (SpelCompilerMode), though the generator compiles expressions to Dart (see SpelOperations); types in T(...) / new must be registered in a StandardTypeLocator; properties and methods of your classes need @Introspected or an accessor; matches and the String methods are Dart's. Integer and long literals are both Dart ints, and f / d real literals both doubles.

Implemented types

Constructors

SpelExpressionParser([SpelParserConfiguration? configuration])
Creates a parser with configuration (SpelParserConfiguration.withDefaults() when omitted).

Properties

configuration → SpelParserConfiguration
The limits and auto-grow options; the expressions this parser returns keep them for their evaluations.
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parseExpression(String expressionString, [ParserContext? context]) → Expression
Parses expressionString into an expression.
override
parseRaw(String expressionString) → SpelExpression
Parses expressionString as a single SpEL expression, never as a template (Spring's parseRaw), and returns it with its concrete type, so the tree in SpelExpression.ast can be inspected.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited