Advertisement
kacejot

Untitled

May 24th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. check value for wildcard/operator pattern:
  2.  
  3. 1. split pattern to OR statements (by | divider)
  4. 2. for each OR statement:
  5. 1. split statement to AND statements (by & divider)
  6. 2. set and_success to true
  7. 3. for each AND statement:
  8. 1. check value with this statement
  9. 2. if value does not pass check - set and_success to false, break
  10. 4. if and_success is true - return true, else - continue
  11.  
  12. When comparing two values in YAML file we can get pattern type:
  13. - bool - if target is also bool, check for equality, else - return false
  14. - int - if target is int or float without fraction (cast it to int then), check for equality, else - return false
  15. - float:
  16. * if pattern value has no fraction, cast it to int. GOTO int
  17. * pattern has fraction. If value is float - check for equality, else - return false
  18. - string - GOTO "if the pattern is string"
  19. - object - NOT SUPPORTED
  20. - array - NOT SUPPORTED
  21. - null - check that value is also null
  22.  
  23.  
  24. if the pattern is string:
  25.  
  26. 0. cast any value to string
  27. 1. grab operator from front it (could be only one of: !, >=, <=, >, <; and must be specified from very start of pattern)
  28. 2. let we have regexp that gets number and string suffix from pattern.
  29. 3. if string pattern is boolean value - check for bool and then apply operator; return
  30. 4. if number part is empty
  31. if operator is ! or empty
  32. return: check string value with wildcard from pattern string ("" is wildcard too)
  33. else
  34. error: could not apply comparison operators with strings
  35. end if
  36. else
  37. ok = check string value with string pattern
  38. if (ok) return: compare pattern number and value number with operator
  39. end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement