Webrexp action - Twinside/Webrexp GitHub Wiki

Actions

Home | Grammar

Types

The actions can manipulate 3 kind of data :

  1. Integers, relative number
  2. Strings
  3. Boolean value

Boolean value cannot be directly represented, they are created by using comparison operators. Strings follow the same notation as the one used in the rest of the webrexp. Integers use the normal notation for integers.

Special instruction

  • . Content dumping operator, given an element in the pipeline, will output it's value. If the element is a binary object, then a file will be written on disk, otherwise the content will be dumped on string.

  • # Deep content dumping operator, given an element in the pipeline, will output it's value and the value of all it's children in a depth first fashion. If the element is binary, it will be written on disk.

  • $ Pipelining operator, swap an element in the pipeline with the evaluation result of the action.

  • ? Name of operator, given an element int the pipeline, will output the node's name. If the element is a text or a blob, an error will be issued.

Operators

Here is the complete list of implemented operators :

Operator Meaning


  •      Add two numbers together
    
  •      Subtract two numbers
    
  •      Multiply two numbers
    

/ Divide two numbers < Compare two numbers (lower than)

     Compare two numbers (greater than)

<= Compare two numbers (lower than or equal)

= Compare two numbers (Greater than or equal) = Equality, types must be the same != Inequality, types must be the same & Logical and, work only on boolean | Logical or, work only on boolean =~ Regexp matching, left side is a string right side is a string representing a regexp. Return a boolean telling if the left string has been matched. ~= Left side is a list of value separated by space, check if right part is in it. Same as CSS3 operator.
^= Tell if right part is the beginning of left part. Same as CSS3 operator $= Tell if right part is the end of left part. Same as CSS3 operator *= Tell if right part is a substring of left part. Same as CSS3 operator |= Same as CSS3 operator

The regular expressions must be of the PCRE syntax. You can find the description of the PCRE syntax in the PCRE documentation.

Functions

  • trim : Only work on character string, remove the white space before and after it. Return the cleaned string.

  • replace : replace a string by another one : replace("abcdef", "bc", ".") will return "a.def"

  • to_num : Try to onvert a string or boolean to a number. If it fail, a type error is returned

  • to_str : Convert anything to a caracter string. Cannot fail.

  • sys : Call the shell to evaluate the string given in parameter.

  • format : see next section.

format function

This function take a string as first parameter (the template string) and a list of string to be inserted at some points.

The format string is made up of some tagged indices, for example '{0}' reference the first inserted content and '{2}' the third one. the '}' character can be escapped by prefixing it by a ''

   format( "da {0} bu {1} \\{0} do {1}", "head", "second")
   -> "da head bu second {0} do second"

It work as intented, there is no syntax error in the formated string, and all indices are in bound.

   format("da {0} bu {1} \\{0} do {2}", "head", "second")
   -> Type error

the '2' index is out of bound, so the function return a type error

   format( "da {0} bu {1} \\{0} do {1a}", "head", "second" )
   -> Type error

A type error is returned because '1a' is not a valid index.