@@ -53,7 +53,7 @@ Kotlin::
5353 val trueValue = parser.parseExpression("'black' < 'block'").getValue(Boolean::class.java)
5454
5555 // uses CustomValue:::compareTo
56- val trueValue = parser.parseExpression("new CustomValue(1) < new CustomValue(2)").getValue(Boolean::class.java);
56+ val trueValue = parser.parseExpression("new CustomValue(1) < new CustomValue(2)").getValue(Boolean::class.java)
5757----
5858======
5959
@@ -167,7 +167,7 @@ Kotlin::
167167[CAUTION]
168168====
169169The syntax for the `between` operator is `<input> between {<range_begin>, <range_end>}`,
170- which is effectively a shortcut for `<input> >= <range_begin> && <input> \<= <range_end>} `.
170+ which is effectively a shortcut for `<input> >= <range_begin> && <input> \<= <range_end>`.
171171
172172Consequently, `1 between {1, 5}` evaluates to `true`, while `1 between {5, 1}` evaluates
173173to `false`.
@@ -312,13 +312,13 @@ Kotlin::
312312
313313 // evaluates to 'a'
314314 val ch = parser.parseExpression("'d' - 3")
315- .getValue(Character ::class.java);
315+ .getValue(Char ::class.java)
316316
317317 // -- Repeat --
318318
319319 // evaluates to "abcabc"
320320 val repeated = parser.parseExpression("'abc' * 2")
321- .getValue(String::class.java);
321+ .getValue(String::class.java)
322322----
323323======
324324
@@ -485,7 +485,7 @@ Kotlin::
485485
486486 // -- Operator precedence --
487487
488- val minusTwentyOne = parser.parseExpression("1+2-3*8").getValue(Int::class.java) // -21
488+ val minusTwentyOne = parser.parseExpression("1+2-3*8").getValue(Int::class.java) // -21
489489----
490490======
491491
@@ -541,32 +541,7 @@ For example, if we want to overload the `ADD` operator to allow two lists to be
541541concatenated using the `+` sign, we can implement a custom `OperatorOverloader` as
542542follows.
543543
544- [source,java,indent=0,subs="verbatim,quotes"]
545- ----
546- pubic class ListConcatenation implements OperatorOverloader {
547-
548- @Override
549- public boolean overridesOperation(Operation operation, Object left, Object right) {
550- return (operation == Operation.ADD &&
551- left instanceof List && right instanceof List);
552- }
553-
554- @Override
555- @SuppressWarnings("unchecked")
556- public Object operate(Operation operation, Object left, Object right) {
557- if (operation == Operation.ADD &&
558- left instanceof List list1 && right instanceof List list2) {
559-
560- List result = new ArrayList(list1);
561- result.addAll(list2);
562- return result;
563- }
564- throw new UnsupportedOperationException(
565- "No overload for operation %s and operands [%s] and [%s]"
566- .formatted(operation, left, right));
567- }
568- }
569- ----
544+ include-code::./ListConcatenation[]
570545
571546If we register `ListConcatenation` as the `OperatorOverloader` in a
572547`StandardEvaluationContext`, we can then evaluate expressions like `{1, 2, 3} + {4, 5}`
@@ -589,8 +564,8 @@ Kotlin::
589564+
590565[source,kotlin,indent=0,subs="verbatim,quotes"]
591566----
592- StandardEvaluationContext context = StandardEvaluationContext()
593- context.setOperatorOverloader( ListConcatenation() )
567+ val context = StandardEvaluationContext()
568+ context.operatorOverloader = ListConcatenation()
594569
595570 // evaluates to a new list: [1, 2, 3, 4, 5]
596571 parser.parseExpression("{1, 2, 3} + {2 + 2, 5}").getValue(context, List::class.java)
0 commit comments