(brooklyn-server) branch master updated: expression parser - tweak to multi-word handling

2024-02-08 Thread heneveld
This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


The following commit(s) were added to refs/heads/master by this push:
 new 5b1ea500dc expression parser - tweak to multi-word handling
5b1ea500dc is described below

commit 5b1ea500dcdbe71d2c12490906a680e251f4f722
Author: Alex Heneveld 
AuthorDate: Thu Feb 8 15:32:03 2024 +

expression parser - tweak to multi-word handling

simplify non-final-match-raw semantics
---
 .../brooklyn/core/workflow/ShorthandProcessor.java |   3 +-
 .../core/workflow/ShorthandProcessorEpToQst.java   |  22 ++--
 .../brooklyn/core/workflow/WorkflowBasicTest.java  |  76 +---
 .../core/workflow/WorkflowMapAndListTest.java  |  15 +--
 .../core/workflow/WorkflowOperandsTest.java|  14 +--
 .../workflow/WorkflowParsingEdgeCasesTest.java | 134 +
 6 files changed, 209 insertions(+), 55 deletions(-)

diff --git 
a/core/src/main/java/org/apache/brooklyn/core/workflow/ShorthandProcessor.java 
b/core/src/main/java/org/apache/brooklyn/core/workflow/ShorthandProcessor.java
index 0adbaffc23..356d655705 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/workflow/ShorthandProcessor.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/workflow/ShorthandProcessor.java
@@ -37,7 +37,8 @@ public class ShorthandProcessor {
 return delegate.process(input);
 }
 
-/** whether the last match should preserve quotes and spaces; default 
false */
+/** optionally skip the automatic unwrapping of a single quoted last word 
lining up with the last word of a template;
+ * by default, we unwrap in that one special case, to facilitate eg return 
"something fancy" */
 public ShorthandProcessor withFinalMatchRaw(boolean finalMatchRaw) {
 delegate.withFinalMatchRaw(finalMatchRaw);
 return this;
diff --git 
a/core/src/main/java/org/apache/brooklyn/core/workflow/ShorthandProcessorEpToQst.java
 
b/core/src/main/java/org/apache/brooklyn/core/workflow/ShorthandProcessorEpToQst.java
index cb94600636..6e48f8dc80 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/workflow/ShorthandProcessorEpToQst.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/workflow/ShorthandProcessorEpToQst.java
@@ -83,7 +83,8 @@ public class ShorthandProcessorEpToQst {
 return new ShorthandProcessorQstAttempt(this, input).call();
 }
 
-/** whether the last match should preserve quotes and spaces; default 
false */
+/** optionally skip the automatic unwrapping of a single quoted last word 
lining up with the last word of a template;
+ * by default, we unwrap in that one special case, to facilitate eg return 
"something fancy" */
 public ShorthandProcessorEpToQst withFinalMatchRaw(boolean finalMatchRaw) {
 this.finalMatchRaw = finalMatchRaw;
 return this;
@@ -131,7 +132,6 @@ public class ShorthandProcessorEpToQst {
 inputRemaining = Strings.trimStart(inputRemaining);
 if (Strings.isNonBlank(inputRemaining)) {
 if (valueUpdater!=null) {
-//QuotedStringTokenizer qstInput = qst(inputRemaining);
 
valueUpdater.accept(getRemainderPossiblyRaw(inputRemaining));
 } else {
 // shouldn't come here
@@ -340,19 +340,13 @@ public class ShorthandProcessorEpToQst {
 return mp.get();
 }
 private Maybe getRemainderPossiblyRawEp(String inputRemaining) 
{
-if (options.finalMatchRaw) {
-return Maybe.of(inputRemaining);
-}
-Maybe> mp = 
ShorthandProcessorExprParser.tokenizer().parseEverything(inputRemaining);
-return mp.map(pnl -> {
-final boolean UNQUOTE_INDIVIDUAL_WORDS = false;  // legacy 
behaviour
-
-if (pnl.size()==1 || UNQUOTE_INDIVIDUAL_WORDS) {
-return ExpressionParser.getAllUnquoted(pnl);
-} else {
-return ExpressionParser.getUnescapedButNotUnquoted(pnl);
+if (!options.finalMatchRaw) {
+Maybe> mp = 
ShorthandProcessorExprParser.tokenizer().parseEverything(inputRemaining);
+if (mp.isPresent() && mp.get().size()==1 && 
ExpressionParser.isQuotedExpressionNode(mp.get().get(0))) {
+return Maybe.of(ExpressionParser.getUnquoted( 
mp.get().get(0) ));
 }
-});
+}
+return Maybe.of(inputRemaining);
 }
 
 private String 
getNextInputTokenUpToPossibleExpectedLiteralQst(QuotedStringTokenizer qstInput, 
String nextLiteral) {
diff --git 
a/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowBasicTest.java 
b/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowBasicTest.java
index 364a7090e9..1ab20b9887 100644
--- 

(brooklyn-server) 01/01: Merge pull request #1415 from ahgittin/expression-parsing

2024-02-08 Thread heneveld
This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 6d428e7ae722a6aa01ca1f14344894ee4ad1abd1
Merge: c2320ebe81 68597ff34b
Author: Alex Heneveld 
AuthorDate: Thu Feb 8 12:21:20 2024 +

Merge pull request #1415 from ahgittin/expression-parsing

Expression parsing

 .../brooklyn/core/workflow/ShorthandProcessor.java | 319 +-
 ...ocessor.java => ShorthandProcessorEpToQst.java} | 225 --
 .../workflow/ShorthandProcessorExprParser.java | 463 +
 ...ndProcessor.java => ShorthandProcessorQst.java} |  33 +-
 .../core/workflow/WorkflowStepDefinition.java  |   7 +-
 .../steps/appmodel/ClearSensorWorkflowStep.java|  36 +-
 .../steps/appmodel/SetConfigWorkflowStep.java  |  22 +-
 .../steps/appmodel/SetSensorWorkflowStep.java  | 238 ---
 .../steps/appmodel/UpdateChildrenWorkflowStep.java |   6 +-
 .../steps/variables/SetVariableWorkflowStep.java   |  59 +--
 .../workflow/steps/variables/TransformReplace.java |   3 -
 .../variables/TransformSetWorkflowVariable.java|   2 +-
 .../workflow/steps/variables/TransformSplit.java   |   9 -
 .../variables/TransformVariableWorkflowStep.java   |  29 +-
 .../core/workflow/utils/ExpressionParser.java  | 230 ++
 .../core/workflow/utils/ExpressionParserImpl.java  | 444 
 .../workflow/utils/WorkflowSettingItemsUtils.java  | 312 ++
 .../core/workflow/ExpressionParserTest.java|  97 +
 ...est.java => ShorthandProcessorEpToQstTest.java} |  50 ++-
 ...sorTest.java => ShorthandProcessorQstTest.java} |  26 +-
 .../core/workflow/WorkflowMapAndListTest.java  | 243 +--
 .../WorkflowNestedAndCustomExtensionTest.java  |   3 +-
 .../java/org/apache/brooklyn/test/Asserts.java |   7 +
 .../java/org/apache/brooklyn/util/guava/Maybe.java |   6 +
 24 files changed, 2182 insertions(+), 687 deletions(-)



(brooklyn-server) branch master updated (c2320ebe81 -> 6d428e7ae7)

2024-02-08 Thread heneveld
This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


from c2320ebe81 fix test case for more forgiving let parse
 add 95271552c3 add an expresson parser which understands interpolated 
strings etc
 add 0c6b44172a update shorthand processor to use expression processor
 add 68597ff34b refactor how map sensors are updated, consistent between 
let and set-sensor
 new 6d428e7ae7 Merge pull request #1415 from ahgittin/expression-parsing

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../brooklyn/core/workflow/ShorthandProcessor.java | 319 +-
 ...ocessor.java => ShorthandProcessorEpToQst.java} | 225 --
 .../workflow/ShorthandProcessorExprParser.java | 463 +
 ...ndProcessor.java => ShorthandProcessorQst.java} |  33 +-
 .../core/workflow/WorkflowStepDefinition.java  |   7 +-
 .../steps/appmodel/ClearSensorWorkflowStep.java|  36 +-
 .../steps/appmodel/SetConfigWorkflowStep.java  |  22 +-
 .../steps/appmodel/SetSensorWorkflowStep.java  | 238 ---
 .../steps/appmodel/UpdateChildrenWorkflowStep.java |   6 +-
 .../steps/variables/SetVariableWorkflowStep.java   |  59 +--
 .../workflow/steps/variables/TransformReplace.java |   3 -
 .../variables/TransformSetWorkflowVariable.java|   2 +-
 .../workflow/steps/variables/TransformSplit.java   |   9 -
 .../variables/TransformVariableWorkflowStep.java   |  29 +-
 .../core/workflow/utils/ExpressionParser.java  | 230 ++
 .../core/workflow/utils/ExpressionParserImpl.java  | 444 
 .../workflow/utils/WorkflowSettingItemsUtils.java  | 312 ++
 .../core/workflow/ExpressionParserTest.java|  97 +
 ...est.java => ShorthandProcessorEpToQstTest.java} |  50 ++-
 ...sorTest.java => ShorthandProcessorQstTest.java} |  26 +-
 .../core/workflow/WorkflowMapAndListTest.java  | 243 +--
 .../WorkflowNestedAndCustomExtensionTest.java  |   3 +-
 .../java/org/apache/brooklyn/test/Asserts.java |   7 +
 .../java/org/apache/brooklyn/util/guava/Maybe.java |   6 +
 24 files changed, 2182 insertions(+), 687 deletions(-)
 copy 
core/src/main/java/org/apache/brooklyn/core/workflow/{ShorthandProcessor.java 
=> ShorthandProcessorEpToQst.java} (62%)
 create mode 100644 
core/src/main/java/org/apache/brooklyn/core/workflow/ShorthandProcessorExprParser.java
 copy 
core/src/main/java/org/apache/brooklyn/core/workflow/{ShorthandProcessor.java 
=> ShorthandProcessorQst.java} (96%)
 create mode 100644 
core/src/main/java/org/apache/brooklyn/core/workflow/utils/ExpressionParser.java
 create mode 100644 
core/src/main/java/org/apache/brooklyn/core/workflow/utils/ExpressionParserImpl.java
 create mode 100644 
core/src/main/java/org/apache/brooklyn/core/workflow/utils/WorkflowSettingItemsUtils.java
 create mode 100644 
core/src/test/java/org/apache/brooklyn/core/workflow/ExpressionParserTest.java
 copy 
core/src/test/java/org/apache/brooklyn/core/workflow/{ShorthandProcessorTest.java
 => ShorthandProcessorEpToQstTest.java} (80%)
 rename 
core/src/test/java/org/apache/brooklyn/core/workflow/{ShorthandProcessorTest.java
 => ShorthandProcessorQstTest.java} (91%)



(brooklyn-server) branch expression-parsing deleted (was 68597ff34b)

2024-02-08 Thread heneveld
This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a change to branch expression-parsing
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


 was 68597ff34b refactor how map sensors are updated, consistent between 
let and set-sensor

This change permanently discards the following revisions:

 discard 68597ff34b refactor how map sensors are updated, consistent between 
let and set-sensor
 discard 0c6b44172a update shorthand processor to use expression processor
 discard 95271552c3 add an expresson parser which understands interpolated 
strings etc



(brooklyn-server) 03/03: refactor how map sensors are updated, consistent between let and set-sensor

2024-02-08 Thread heneveld
This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch expression-parsing
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 68597ff34b3a8e720a8eb78d1c94c1ece4ed615c
Author: Alex Heneveld 
AuthorDate: Wed Feb 7 17:06:43 2024 +

refactor how map sensors are updated, consistent between let and set-sensor
---
 .../steps/appmodel/ClearSensorWorkflowStep.java|  36 ++-
 .../steps/appmodel/SetConfigWorkflowStep.java  |  22 +-
 .../steps/appmodel/SetSensorWorkflowStep.java  | 238 +---
 .../steps/variables/SetVariableWorkflowStep.java   |  57 +---
 .../variables/TransformSetWorkflowVariable.java|   2 +-
 .../variables/TransformVariableWorkflowStep.java   |  27 +-
 .../workflow/utils/WorkflowSettingItemsUtils.java  | 312 +
 .../core/workflow/WorkflowMapAndListTest.java  | 243 +---
 .../WorkflowNestedAndCustomExtensionTest.java  |   3 +-
 9 files changed, 651 insertions(+), 289 deletions(-)

diff --git 
a/core/src/main/java/org/apache/brooklyn/core/workflow/steps/appmodel/ClearSensorWorkflowStep.java
 
b/core/src/main/java/org/apache/brooklyn/core/workflow/steps/appmodel/ClearSensorWorkflowStep.java
index 713735b1b8..e04b47b591 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/workflow/steps/appmodel/ClearSensorWorkflowStep.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/workflow/steps/appmodel/ClearSensorWorkflowStep.java
@@ -18,6 +18,10 @@
  */
 package org.apache.brooklyn.core.workflow.steps.appmodel;
 
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
 import com.google.common.collect.Iterables;
 import com.google.common.reflect.TypeToken;
 import org.apache.brooklyn.api.entity.Entity;
@@ -25,19 +29,12 @@ import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.entity.EntityInternal;
 import org.apache.brooklyn.core.sensor.Sensors;
-import org.apache.brooklyn.core.workflow.WorkflowExpressionResolution;
 import org.apache.brooklyn.core.workflow.WorkflowStepDefinition;
 import org.apache.brooklyn.core.workflow.WorkflowStepInstanceExecutionContext;
+import org.apache.brooklyn.core.workflow.utils.WorkflowSettingItemsUtils;
 import org.apache.brooklyn.util.collections.MutableList;
-import org.apache.brooklyn.util.collections.MutableMap;
-import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.guava.Maybe;
-import org.apache.brooklyn.util.text.Strings;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import org.apache.commons.lang3.tuple.Pair;
 
 public class ClearSensorWorkflowStep extends WorkflowStepDefinition {
 
@@ -54,27 +51,26 @@ public class ClearSensorWorkflowStep extends 
WorkflowStepDefinition {
 protected Object doTaskBody(WorkflowStepInstanceExecutionContext context) {
 EntityValueToSet sensor = context.getInput(SENSOR);
 if (sensor==null) throw new IllegalArgumentException("Sensor name is 
required");
-String sensorNameFull = 
context.resolve(WorkflowExpressionResolution.WorkflowExpressionStage.STEP_INPUT,
 sensor.name, String.class);
-if (Strings.isBlank(sensorNameFull)) throw new 
IllegalArgumentException("Sensor name is required");
 
-List sensorNameIndexes = MutableList.of();
-String sensorNameBase = 
SetSensorWorkflowStep.extractSensorNameBaseAndPopulateIndices(sensorNameFull, 
sensorNameIndexes);
+Pair> sensorNameAndIndices = 
WorkflowSettingItemsUtils.resolveNameAndBracketedIndices(context, sensor.name, 
false);
+if (sensorNameAndIndices==null) throw new 
IllegalArgumentException("Sensor name is required");
 
 TypeToken type = context.lookupType(sensor.type, () -> 
TypeToken.of(Object.class));
 Entity entity = sensor.entity;
 if (entity==null) entity = context.getEntity();
 
-if (sensorNameIndexes.isEmpty()) {
-((EntityInternal) 
entity).sensors().remove(Sensors.newSensor(Object.class, sensorNameFull));
+// TODO use WorkflowSettingItemsUtils
+if (sensorNameAndIndices.getRight().isEmpty()) {
+((EntityInternal) 
entity).sensors().remove(Sensors.newSensor(Object.class, 
sensorNameAndIndices.getLeft()));
 } else {
-((EntityInternal) 
entity).sensors().modify(Sensors.newSensor(Object.class, sensorNameBase), old 
-> {
+((EntityInternal) 
entity).sensors().modify(Sensors.newSensor(Object.class, 
sensorNameAndIndices.getLeft()), old -> {
 
 boolean setLast = false;
 
-Object newTarget = SetSensorWorkflowStep.makeMutable(old, 
sensorNameIndexes);
+Object newTarget = 
WorkflowSettingItemsUtils.makeMutableOrUnchangedDefaultingToMap(old);
 Object target = newTarget;
 
-MutableList indexes = 

(brooklyn-server) 02/03: update shorthand processor to use expression processor

2024-02-08 Thread heneveld
This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch expression-parsing
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 0c6b44172adc1e76caf4b84f6a4ec3c15d6afb1b
Author: Alex Heneveld 
AuthorDate: Wed Feb 7 14:36:49 2024 +

update shorthand processor to use expression processor

allows us to respect spaces and other things inside brackets
---
 .../brooklyn/core/workflow/ShorthandProcessor.java | 319 +-
 ...ocessor.java => ShorthandProcessorEpToQst.java} | 225 --
 .../workflow/ShorthandProcessorExprParser.java | 463 +
 ...ndProcessor.java => ShorthandProcessorQst.java} |  33 +-
 .../core/workflow/WorkflowStepDefinition.java  |   7 +-
 .../steps/appmodel/UpdateChildrenWorkflowStep.java |   6 +-
 .../steps/variables/SetVariableWorkflowStep.java   |   2 +-
 .../workflow/steps/variables/TransformReplace.java |   3 -
 .../workflow/steps/variables/TransformSplit.java   |   9 -
 .../variables/TransformVariableWorkflowStep.java   |   2 +-
 ...est.java => ShorthandProcessorEpToQstTest.java} |  50 ++-
 ...sorTest.java => ShorthandProcessorQstTest.java} |  26 +-
 12 files changed, 747 insertions(+), 398 deletions(-)

diff --git 
a/core/src/main/java/org/apache/brooklyn/core/workflow/ShorthandProcessor.java 
b/core/src/main/java/org/apache/brooklyn/core/workflow/ShorthandProcessor.java
index 32ba2f835c..0adbaffc23 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/workflow/ShorthandProcessor.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/workflow/ShorthandProcessor.java
@@ -18,337 +18,36 @@
  */
 package org.apache.brooklyn.core.workflow;
 
-import org.apache.brooklyn.util.collections.CollectionMerger;
-import org.apache.brooklyn.util.collections.MutableList;
-import org.apache.brooklyn.util.collections.MutableMap;
-import org.apache.brooklyn.util.guava.Maybe;
-import org.apache.brooklyn.util.text.QuotedStringTokenizer;
-import org.apache.brooklyn.util.text.Strings;
-
-import java.util.Arrays;
-import java.util.List;
 import java.util.Map;
-import java.util.function.Consumer;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
+
+import org.apache.brooklyn.util.guava.Maybe;
 
 /**
- * Accepts a shorthand template, and converts it to a map of values,
- * e.g. given template "[ ?${type_set} ${sensor.type} ] ${sensor.name} \"=\" 
${value}"
- * and input "integer foo=3", this will return
- * { sensor: { type: integer, name: foo }, value: 3, type_set: true }.
- *
- * Expects space-separated TOKEN where TOKEN is either:
- *
- * ${VAR} - to set VAR, which should be of the regex 
[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*, with dot separation used to set nested maps;
- *   will match a quoted string if supplied, else up to the next literal if 
the next token is a literal, else the next work.
- * ${VAR...} - as above, but will collect multiple args if needed (if the next 
token is a literal matched further on, or if at end of word)
- * "LITERAL" - to expect a literal expression. this must include the quotation 
marks and should include spaces if spaces are required.
- * [ TOKEN ] - to indicate TOKEN is optional, where TOKEN is one of the above 
sections. parsing is attempted first with it, then without it.
- * [ ?${VAR} TOKEN ] - as `[ TOKEN ]` but VAR is set true or false depending 
whether this optional section was matched.
- *
- * Would be nice to support A | B (exclusive or) for A or B but not both 
(where A might contain a literal for disambiguation),
- * and ( X ) for X required but grouped (for use with | (exclusive or) where 
one option is required).
- * Would also be nice to support any order, which could be ( A & B ) to allow 
A B or B A.
- *
- * But for now we've made do without it, with some compromises:
- * * keywords must follow the order indicated
- * * exclusive alternatives are disallowed by code subsequently or checked 
separately (eg Transform)
+ * This impl delegates to one of the various classes that do this -- see notes 
in individual ones.
  */
 public class ShorthandProcessor {
 
-private final String template;
-boolean finalMatchRaw = false;
-boolean failOnMismatch = true;
+ShorthandProcessorEpToQst delegate;
 
 public ShorthandProcessor(String template) {
-this.template = template;
+delegate = new ShorthandProcessorEpToQst(template);
 }
 
 public Maybe> process(String input) {
-return new ShorthandProcessorAttempt(this, input).call();
+return delegate.process(input);
 }
 
 /** whether the last match should preserve quotes and spaces; default 
false */
 public ShorthandProcessor withFinalMatchRaw(boolean finalMatchRaw) {
-this.finalMatchRaw = finalMatchRaw;
+delegate.withFinalMatchRaw(finalMatchRaw);
 return this;
 }
 
 /** whether to fail on mismatched quotes in the input, default true */
 public ShorthandProcessor 

(brooklyn-server) 01/03: add an expresson parser which understands interpolated strings etc

2024-02-08 Thread heneveld
This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch expression-parsing
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 95271552c3829afba3f058a56ecd4258fbc6a802
Author: Alex Heneveld 
AuthorDate: Tue Feb 6 07:56:02 2024 +

add an expresson parser which understands interpolated strings etc
---
 .../core/workflow/utils/ExpressionParser.java  | 230 +++
 .../core/workflow/utils/ExpressionParserImpl.java  | 444 +
 .../core/workflow/ExpressionParserTest.java|  97 +
 .../java/org/apache/brooklyn/test/Asserts.java |   7 +
 .../java/org/apache/brooklyn/util/guava/Maybe.java |   6 +
 5 files changed, 784 insertions(+)

diff --git 
a/core/src/main/java/org/apache/brooklyn/core/workflow/utils/ExpressionParser.java
 
b/core/src/main/java/org/apache/brooklyn/core/workflow/utils/ExpressionParser.java
new file mode 100644
index 00..e3c5f53ac0
--- /dev/null
+++ 
b/core/src/main/java/org/apache/brooklyn/core/workflow/utils/ExpressionParser.java
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.workflow.utils;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
+import 
org.apache.brooklyn.core.workflow.utils.ExpressionParserImpl.BackslashParseMode;
+import org.apache.brooklyn.util.collections.MutableList;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.text.Strings;
+
+import static 
org.apache.brooklyn.core.workflow.utils.ExpressionParserImpl.CharactersCollectingParseMode;
+import static 
org.apache.brooklyn.core.workflow.utils.ExpressionParserImpl.CommonParseMode;
+import static 
org.apache.brooklyn.core.workflow.utils.ExpressionParserImpl.ParseMode;
+import static 
org.apache.brooklyn.core.workflow.utils.ExpressionParserImpl.ParseNode;
+import static 
org.apache.brooklyn.core.workflow.utils.ExpressionParserImpl.ParseNodeOrValue;
+import static 
org.apache.brooklyn.core.workflow.utils.ExpressionParserImpl.ParseValue;
+import static 
org.apache.brooklyn.core.workflow.utils.ExpressionParserImpl.TopLevelParseMode;
+
+/** simplistic parser for workflow expressions and strings, recognizing single 
and double quotes, backslash escapes, and interpolated strings with ${...} */
+public abstract class ExpressionParser {
+
+public abstract Maybe parse(String input);
+public abstract Maybe> parseEverything(String 
inputRemaining);
+
+
+public static final ParseMode BACKSLASH_ESCAPE = new BackslashParseMode();
+public static final ParseMode WHITESPACE = new 
CharactersCollectingParseMode("whitespace", Character::isWhitespace);
+
+public static final ParseMode DOUBLE_QUOTE = 
CommonParseMode.transitionNested("double_quote", "\"", "\"");
+public static final ParseMode SINGLE_QUOTE = 
CommonParseMode.transitionNested("single_quote", "\'", "\'");
+public static final ParseMode INTERPOLATED = 
CommonParseMode.transitionNested("interpolated_expression", "${", "}");
+
+public static final ParseMode SQUARE_BRACKET = 
CommonParseMode.transitionNested("square_bracket", "[", "]");
+public static final ParseMode PARENTHESES = 
CommonParseMode.transitionNested("parenthesis", "(", ")");
+public static final ParseMode CURLY_BRACES = 
CommonParseMode.transitionNested("curly_brace", "{", "}");
+
+
+private static Multimap getCommonInnerTransitions() {
+ListMultimap m = 
Multimaps.newListMultimap(MutableMap.of(), MutableList::of);
+m.putAll(BACKSLASH_ESCAPE, MutableList.of());
+m.putAll(SINGLE_QUOTE, MutableList.of(BACKSLASH_ESCAPE, INTERPOLATED));
+m.putAll(DOUBLE_QUOTE, MutableList.of(BACKSLASH_ESCAPE, INTERPOLATED));
+m.putAll(INTERPOLATED, MutableList.of(BACKSLASH_ESCAPE, DOUBLE_QUOTE, 
SINGLE_QUOTE, INTERPOLATED));
+return Multimaps.unmodifiableMultimap(m);
+}
+public static final Multimap 

(brooklyn-server) branch expression-parsing created (now 68597ff34b)

2024-02-08 Thread heneveld
This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a change to branch expression-parsing
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


  at 68597ff34b refactor how map sensors are updated, consistent between 
let and set-sensor

This branch includes the following new commits:

 new 95271552c3 add an expresson parser which understands interpolated 
strings etc
 new 0c6b44172a update shorthand processor to use expression processor
 new 68597ff34b refactor how map sensors are updated, consistent between 
let and set-sensor

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.