php - Converting pseudocode into usable (using regular expression?) -


as part of system writing, users can create own custom rules, run when events happen.

there set number of objects can use create these rules, of have set number of properties , methods:

list of objects

so example of rule, say:

“if unit award ‘distinction’ set criteria on unit award ‘achieved’”

if unit.award equals “distinction” unit.criteria.set_award(‘a’) 

“else if unit award ‘merit’ set award of criteria on unit name starts either ‘p’ or ‘m’ ‘achieved’”

if unit.award equals “merit” unit.criteria.filter(‘starts’, ‘name’, ‘p’, ‘m’).set_award(‘a’) 

“else if unit award ‘pass set award of criteria on unit name starts ‘p’ ‘achieved’”

if unit.award equals “merit” unit.criteria.filter(‘starts’, ‘name’, ‘p’).set_award(‘a’) 

the problem having, not sure how take string of object, properties & methods, e.g. “unit.criteria.filter(‘starts’, ‘name’, ‘p’).set_award(‘a’)” , convert usable.

the end result i’d convert string along lines of:

example result

so can convert actual proper objects , return relevant values or run relevant methods.

since there set number of things need support (for @ least) , don’t need complex calculation support or variables, seems overkill create lexer system, thinking of using regular expression split sections.

so using examples above, simple split on “.” character, if character used in method parameter, e.g. “criterion.filter(‘is’, ‘name’, ‘p.1’)” screws completely.

i use less common character split them, example double colon or “::” if whatever reason puts parameter still cause same problem. i’ve tried creating regular expression splits on character, if it’s not between quotes, haven’t been able work.

so question is: regular expression best way this? (if so, me getting ignore specified character if it’s in method). or there way easier/better?

thanks.

i'd think orm language eloquent you.

but if had first i'd split if else parts. leaving:

  1. unit.award equals “distinction”
  2. unit.criteria.filter(‘starts’, ‘name’, ‘p’, ‘m’).set_award(‘a’)

i'm guessing "equals" "not equals" or "greater" so... i'd split first bit around that.

/(?'ident'[a-z.]*?) (?'expression'equals|greater) (?'compare'[0-9a-z\“\”]+)/gi 

but explode around 'equals' same.

then i'd explode second part around dots. giving:

  1. unit
  2. criteria
  3. filter(a,b,c,d)
  4. set_ward(e)

pop off first 2 object , property , list of possible filters , actions.

but frankly i'd develop language not mix properties actions , filters.

something like:

if object.prop equals const|var  update object.prop  const|var [where object.prop filter const|var [and|or const|var]]  

eloquent straight in php:

db::table('users')             ->where('id', 1)             ->update(['votes' => 1]); 

so maybe i'd like:

then object.prop->filter(a,b,c,d)->set('award','a') 

this makes easy split actions around -> , properties around .

anyway... regex on https://regex101.com/ hope helps.


Comments

Popular posts from this blog

javascript - Add class to another page attribute using URL id - Jquery -

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -