[PLAS-3] Users need to associate variable values with matched substrings using wildcards Created: 08/Jan/20  Updated: 14/Jan/20  Resolved: 14/Jan/20

Status: Done
Project: plastic
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Medium
Reporter: Allan Clarke Assignee: Allan Clarke
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: 3 days
Time Spent: Not Specified
Original Estimate: 3 days


 Description   

Proposal B: this is about providing a simplified wildcard-like matching for use in input schemas

If a designer knows how to use regex effectively then they won't be bothered much by creating a morpher.

So making a simpler matching mechanism will make it easier on less knowledgable users.

An example

|*${abc}/${def}*|

So the bars | are required and mark the beginning and end of a "wildcard expression" (the full value, no prefix, no suffix)
Variables are explicitly present and named in the schema, which is an advantage over the regex in Proposal A
An asterisk would match any number of characters (not greedily)
Any other characters outside of variables would be literal matches
All divisions between literals, asterisks, and variables would be assumed to be on word boundaries.
So if you want to break up a word, you have to use a morpher with regex
This feature would end up using regex underneath

Here is a fuller example (from discussion with Qasim)...

input schema...

{ "device": { "id": "|*/${aid}/*|", "bw": "${bandwidth}" }}

payload...

{ "device": { "id": "CX02DPM 43/DEV-53/aus Orlando", "bw": "1000" }}

resulting variable binding...

${aid} = "DEV-53"
${bandwidth} = 1000

 
Using this "wildcard matching" you can get "DEV-53" bound to "aid" but if you want, say, the "02" out of "CX02DPM", you would need to write a morpher and cannot use this facility. Wildcarding is a simplification of regex and relies on the Regex definition of word boundary to recognize substrings that can be variable values.
 



 Comments   
Comment by Allan Clarke [ 14/Jan/20 ]

The below was the original Proposal A and the one implemented in the main part of this story was Proposal B. But B won out due to its
more WYSIWYG characteristic, which fits Plastic better. Also the Proposal B below can now be done as a variant of Proposal A with reduced
effort (ie, shared code).

Proposal A: This is about exposing use of regex to schema designers.

For reference, an example regex:

/^.\s(.*?)\s(.*?).*$/

Allow user to do this:

${abc=~/...regex.../}

Note that = is used for assignment of default value and =~ is used for association of regex

In the example above, there are up to 2 captures, which would result in variable bindinds for abc/1 and abc/2

Note the way the variable is named is a reminder that it is from a regex

Any non-matches mean that there will be no binding for those variables and a likely complaint from Plastic. User will need to know it was a bad regex, but there is a hint due to unique variable name structure.

 

Generated at Wed Feb 07 20:36:49 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.