Annotation of parser3/operators.txt, revision 1.279
1.260 moko 1: operators
2: ^eval(expression)[format] expressions, apart from the usual functions, supports:
3: #comments allowed
4: they work until the end of the line or the closing parenthesis
5: nested parentheses are allowed inside comments
6: among the non-obvious operators:
7: | bitwise XOR
8: || logical XOR
9: ~ bitwise negation
10: \ integer division 10\3=3
11: def checks if defined:
12: an empty string is not defined
13: an empty table is not defined
14: an empty hash is not defined
15: eq ne lt gt le ge for string comparison,
16: in "/dir/" to check if the current document is located in the specified directory
17: ["no expressions allowed inside; if you need a complex comparison, assign it to a variable"]
18: is 'type' to check the type of the left operand,
19: e.g., "is the method parameter not a hash?"
20: -f checks if a file exists on disk,
21: -d checks if a directory exists on disk,
1.279 ! moko 22: -l checks if a symbolic link exists on disk,
1.260 moko 23: a quoted string (double or single quotes) is treated as a string, unquoted text is a string until the nearest whitespace
24: numeric literals can be in hex format like 0xABC
25: priorities:
1.250 moko 26: /* logical */
27: %left "!||"
28: %left "||"
29: %left "&&"
1.260 moko 30: %left '<' '>' "<=" ">=" "lt" "gt" "le" "ge"
31: %left "==" "!=" "eq" "ne"
1.279 ! moko 32: %left "is" "def" "in" "-f" "-d" "-l"
1.250 moko 33: %left '!'
1.1 paf 34:
1.259 moko 35: /* bitwise */
1.250 moko 36: %left '!|'
37: %left '|'
1.260 moko 38: %left '&'
1.250 moko 39: %left '~'
1.1 paf 40:
1.259 moko 41: /* numerical */
1.250 moko 42: %left '-' '+'
43: %left '*' '/' '%' '\\'
44: %left '~' /* negation: unary */
1.259 moko 45:
1.260 moko 46: literals:
1.250 moko 47: true
48: false
49:
1.260 moko 50: ^if(condition){then}{else}
51: ^if(condition1){yes}[(condition2){yes}[(condition3){yes}[...]]]{no}
52: unlimited number of additional conditions (elseif)
1.250 moko 53:
1.260 moko 54: ^switch[value]{^case[var1[;var2...]]{action}^case[DEFAULT]{default action}}
1.250 moko 55:
1.260 moko 56: ^while(condition){body}[[delimiter]|{delimiter executed before each non-empty non-first body}]
1.250 moko 57:
1.260 moko 58: ^for[i](0;4){body}[[delimiter]|{delimiter executed before each non-empty non-first body}]
1.250 moko 59:
60: ^try{
1.21 paf 61: ...
1.260 moko 62: ^throw[sql.connect[;vasya[;mistaken]]] // previously ^error[text]
1.250 moko 63: ^throw[
64: $.type[sql.connect]
1.260 moko 65: $.source[vasya]
66: $.comment[mistaken]
1.207 misha 67: ]
1.20 paf 68: ...
69: }{
1.207 misha 70: ^if($exception.type eq "sql"){
1.260 moko 71: $exception.handled(1|true) ^rem{flag that exception is handled}
1.21 paf 72: ....
73: }
1.207 misha 74: ^switch[$exception.type]{
1.21 paf 75: ^case[sql;mail]{
76: $exception.handled(1)
1.260 moko 77: code handling sql error
1.21 paf 78: $exception.type = sql.connect
1.260 moko 79: $exception.file $exception.lineno $exception.colno [if not disabled at compile time]
80: $exception.source = vasya
81: $exception.comment = mistaken
1.21 paf 82: }
1.194 misha 83: ^case[DEFAULT]{
1.260 moko 84: code handling another error
1.207 misha 85: ^throw[$exception] << re-throw // DON'T! It's default behaviour!
1.21 paf 86: }
87: }
1.20 paf 88: }
1.250 moko 89:
1.259 moko 90: ^break[]
1.260 moko 91: breaks the loop
1.259 moko 92: ^break(true|false)
1.260 moko 93: breaks the loop if true
1.259 moko 94:
95: ^continue[]
1.260 moko 96: breaks the current iteration of the loop
1.259 moko 97: ^continue(true|false)
1.260 moko 98: breaks the current iteration if true
1.259 moko 99:
100: ^return[]
1.260 moko 101: stops method execution
1.259 moko 102: ^return[value]
1.260 moko 103: assigns $result the value and stops method execution
1.250 moko 104:
1.260 moko 105: ^untaint[[as-is|file-spec|uri|http-header|mail-header|sql|js|json|parser-code|regex|xml|html|optimized-[as-is|xml|html]]]{code}
1.1 paf 106: default as-is
1.250 moko 107:
1.260 moko 108: ^taint[[lang]][code]
1.1 paf 109: default "just tainted, language unknown"
1.250 moko 110:
1.260 moko 111: ^apply-taint[[lang;]text]
112: applies transformations specified in the string, "indefinitely dirty" is considered as lang, producing a clean string
1.250 moko 113:
1.260 moko 114: ^process[[$caller.CLASS|$object|$CLASS:CLASS]]{string to be processed as code}[
115: $.main[what to rename @main to]
116: $.file[name of the file supposedly containing this text]
117: $.lineno(line number in the file from where this text originated, can be negative)
1.151 paf 118: ]
1.260 moko 119: ^process..[path][what to rename @main to]
120: by default, methods are compiled into $self [in case of operator, $self=$MAIN:CLASS]
1.250 moko 121:
1.260 moko 122: ^connect[protocol://connection-string]]{code with ^sql[...] calls}
1.254 moko 123: mysql://user:pass@{host[:port][, host[:port]]|[/unix/socket]}/database?
1.161 paf 124: ClientCharset=parser-charset << charset in which parser thinks client works
1.248 moko 125: charset=UTF-8&
1.1 paf 126: timeout=3&
1.210 misha 127: compress=0&
1.136 paf 128: named_pipe=1&
1.260 moko 129: multi_statements=1& allow executing more than one query in a single :sql{} request
1.254 moko 130: config_file=.my.cnf&
131: config_group=parser3& use group name from .my.cnf
1.136 paf 132: autocommit=1
1.260 moko 133: if autocommit is set to 0, it will perform commit/rollback
1.1 paf 134:
1.250 moko 135: pgsql://user:pass@{host[:port]|[local]}/database?
1.163 paf 136: client_encoding=win,[to-find-out]
137: &datestyle=ISO,SQL,Postgres,European,NonEuropean=US,German,DEFAULT=ISO
138: &ClientCharset=parser-charset << charset in which parser thinks client works
1.250 moko 139:
140: odbc://DSN=dsn^;UID=user^;PWD=password^;ClientCharset=parser-charset
1.162 paf 141: ClientCharset << charset in which parser thinks client works
1.250 moko 142:
143: sqlite://DBfile?
1.230 misha 144: ClientCharset=parser-charset& << charset in which parser thinks client works
145: autocommit=1
1.1 paf 146:
1.260 moko 147: to use ^connect, the $SQL table must be defined beforehand (recommended in the system configuration auto.p)
1.1 paf 148: #sql drivers
149: $SQL[
1.207 misha 150: $.drivers[^table::create{protocol driver client
1.259 moko 151: mysql $prefix/libparser3mysql.so libmysqlclient.so
152: pgsql $prefix/libparser3pgsql.so libpq.so
153: sqlite $prefix/libparser3sqlite.so sqlite3.so
1.257 moko 154: odbc parser3odbc.dll
1.1 paf 155: }]
156: ]
1.250 moko 157: ^rem{}
1.260 moko 158: a comment, removed at compile time
1.250 moko 159:
1.267 moko 160: ^syslog[ident;message[;info|warning|error|debug]]
161: writes a message to syslog
162:
1.260 moko 163: ^cache[file](seconds){code}[{catch code}]
164: relative time assignment
165: caches the string resulting from the code execution for 'seconds' seconds
166: if 0 seconds, do not cache, and remove any existing old cache
167: in the catch code, $exception.handled[cache] ^rem{flag that exception is handled}
168: ^cache[file][expires date]{code}[{catch code}]
169: absolute time assignment
1.278 moko 170: ^cache[file][ $.expires(seconds)|[expires date] $.extend(seconds) ]{code}[{catch code}]
1.277 moko 171: the same, with the options
1.278 moko 172: $.extend(seconds) if the cache expired no more than 'seconds' ago [$MAIN:LIMITS.lock_wait_timeout by default], one request renews it, the others get the old copy meanwhile
173: for no more than 'seconds': if the code runs longer or fails, the next request renews the cache
174: if cache expired more than 'seconds' ago, there is no copy, or with $.extend(0), the others wait for the result: the code does not run twice
1.260 moko 175: ^cache[file]
176: deletes the file [no error if it doesn't exist]
177: ^cache(seconds)
1.250 moko 178: ^cache[expires date]
1.260 moko 179: signals to the upper-level ^cache "reduce it to these many 'seconds'/'expires'"
180: ultimately: ^cache(0) cancels caching
1.259 moko 181: ^cache[]
1.260 moko 182: returns the current expires date
1.250 moko 183:
1.260 moko 184: each method has a local variable $result. If you put something in it,
185: that will be the method's result, not its body
1.250 moko 186:
1.260 moko 187: each method has a local variable $caller, containing the parent stack frame,
188: you can write to its local variables
1.250 moko 189:
1.260 moko 190: use(^use or @USE) searches for and includes a file:
191: 1. If the path starts with /, it is considered a path from the web root
192: 2. Relative to the current directory
193: 3. Relative to strings from the $MAIN:CLASS_PATH table, bottom-up
194: $MAIN:CLASS_PATH is a global string or table with a path or paths to a directory
195: with classes (from the web root), set it in the configuration auto.p
196:
197: A global table $CHARSETS[$.name[filename]]
198: defines which characters are considered what (whitespace, letter, etc.), as well as their Unicode
199: format: tab-delimited file, with a header:
1.250 moko 200: char white-space digit hex-digit letter word lowercase unicode1 unicode2
1.260 moko 201: A x x x a 0x0041 0xFF21
202: where char and lowercase can be letters or 0xCODES
203: if the character has a single Unicode representation equal to itself, you can omit unicode
204: UTF-8 is always available and is the default encoding for request and response
205: WARNING: the encoding name is case-insensitive
206:
207: syntax
208: $name[new value]
209: $name(arithmetic expression of new value)
210: $name{code of new value}
211: $name whitespace or ${name}something - variable value
212: ^name parameters - call
213: $name.CLASS - class of the value
214: $name.CLASS_NAME - name of the class
215: $name[$.key[] () {}] - constructor of a hash variable with element $name.key
216: ^method[$.key[] () {}] - constructor of a hash parameter with element $parameter.key
217: $CLASS.name access a class variable
218:
219: the name ends before: space tab linefeed ; ] } ) " < > + * / % & | = ! ' , ?
220: i.e. you can do $name,aaaa
221: but if you need a character after the name, say -, then ${name}-
222:
223: in expressions, + and - are additional name boundaries
224:
225: you can access compound objects as: $name.subname where subname can be:
226: a string
227: a $variable
228: a string$variable
229: [code computing a string]
230: for example: $hash[$.age(88)] $get[$.field[age]] ^hash.[$get.field].format{%05d}
231:
232: parameters := one or more parameters
233: parameter :=
234: (arithmetic expression) evaluated multiple times inside the call,
235: | [code] evaluated once before the call,
236: | {code} evaluated zero or many times inside the call,
237: ';' are allowed, making multiple parameters in a single bracket
238:
1.250 moko 239:
240: void
1.260 moko 241: all methods present in the string class object are available, the result behaves as if it were an empty string
242: ^void:sql{query without result}{$.bind[see table::sql]}
1.250 moko 243:
244: int,double
1.260 moko 245: ^name.int[]
246: integer value
247: ^name.double[]
248: double value
249: ^name.bool[] ^name.bool(true|false)
250: boolean value
251: ^name.inc(how much +)
252: ^name.dec(how much -)
1.271 moko 253: ^name.++[] output the value, then increment by 1
254: ^name.--[] output the value, then decrement by 1
1.260 moko 255: ^name.mul(how much *)
256: ^name.div(how much /)
257: ^name.mod(how much %)
258: ^name.format[format]
259: ^int/double:sql{query}[[$.limit(2) $.offset(4) $.default{0} $.bind[see table::sql]]]
260: the query result should be one column/one row
1.1 paf 261:
1.250 moko 262: string
1.260 moko 263: in expression
264: def value means "not empty?"
265: logical/numerical value equals an attempt to convert to double,
266: an empty string quietly converts to 0
267: example:
268: ^if(def $form:name) not empty?
269: ^if($user.isAlive) true? [auto-convert to number, not zero?]
270: ^string:sql{query}[[$.limit(1) $.offset(4) $.default{n/a} $.bind[see table::sql]]]
271: the query result should be one column/one row
272: ^string.int[] ^string.int(default)
273: integer value of the string, if conversion fails, default is taken
274: ^string.double[] ^string.double(default)
275: double value of the string, if conversion fails, default is taken
276: ^string.bool[] ^string.bool(default)
277: boolean value of the string, if conversion fails, default is taken
278: ^string.format[format] %d %.2f %02d...
279: ^string.match[string-pattern|regex-pattern][[search options]] $prematch $match $postmatch $1 $2...
280: search options:
1.21 paf 281: i CASELESS
282: x whitespace in regex ignored
1.260 moko 283: s singleline = $ matches end of entire text
284: m multiline = $ matches end of line[\n], not end of entire text
285: g find all occurrences, not just one
286: ' create columns prematch, match, postmatch
287: n return the number of matches instead of a table
288: U invert the meaning of the '?' modifier
289: ^string.match[string-pattern|regex-pattern][search options]{replacement}
290: additional search option:
291: g replace all occurrences, not just one
292: ^string.split[delimiter|regex][[lrhva]][[column name for vertical splitting]]
293: l left to right [default]
294: r right to left
295: h nameless table with keys 0, 1, 2, ...
296: v table of one column 'piece' or as provided [default]
297: a array
298: ^string.{l|r}split[delimiter] a table from the $piece column
299: kept for compatibility
300: ^string.upper|lower[]
301: ^string.length[]
302: ^string.mid(P[;N])
303: without N - "until the end of the string"
304: ^string.left(N), -1 returns the entire string
305: ^string.right(N)
306: ^string.pos[substring]
307: ^string.pos[substring](position from which to search)
308: <0 = not found
1.275 moko 309: ^string.rpos[substring]
310: the last substring in the string
311: ^string.rpos[substring](maximum position of the substring start)
312: the last substring that starts at or before the position
313: <0 = not found
1.260 moko 314: ^string.replace[$table_of_substitutions_string_to_string]
315: ^string.replace[$what;$to]
316: ^string.save[[append;]path]
317: ^string.save[path[;$.charset[in which encoding save] $.append(true)]]
318: saves the string to a file
319: ^string.trim[start|both|end|left|right[;chars]]
320: removes chars from the start/end/or both start and end
1.259 moko 321: default 'chars' = whitespace chars
1.260 moko 322: ^string.trim[chars]
323: removes chars from start and end
324: ^string.base64[ $.pad(bool) $.wrap(bool) $.url-safe(bool) ] encode
1.259 moko 325: ^string:base64[encoded[; $.pad(bool) $.strict(bool) $.url-safe(bool) ]] decode
1.260 moko 326: ^string.idna[]
327: IDNA encoding, supports Cyrillic domains
1.250 moko 328: ^string:idna[encoded]
1.260 moko 329: IDNA decoding, supports Cyrillic domains
330: ^string.js-escape[]
331: encoding for passing to JS (%uXXXX)
1.257 moko 332: ^string:js-unescape[escaped]
1.260 moko 333: decoding from js
1.257 moko 334: ^string:unescape[js|uri;escaped; $.charset[] ]
1.260 moko 335: decoding passed from js or uri
336: ^string.contains[key]
337: for compatibility with hashtable
1.255 moko 338:
1.251 moko 339: table
1.260 moko 340: in expression
341: logical value means "not empty?"
342: numerical value equals count[]
343: $table.field
344: $table.field[new value]
345: $table.fields
346: from a named table returns the current record as a Hash
347: ^table::create[[nameless]]{data}[[$.separator[^#09] $.encloser[]]]
1.251 moko 348: ^table::create[table][[$.limit(1) $.offset(5) $.offset[cur] $.reverse(1)]]
1.260 moko 349: clones the table
350: reverse - in reverse order
351: ^table::load[[nameless;]path[;options]]
352: if not nameless, column names are taken from the first line
353: empty lines, and lines in the first column containing '#' are ignored
1.251 moko 354: $.separator[^#09]
1.260 moko 355: $.encloser["] by default, none
1.251 moko 356: ^table::sql{query}[[$.limit(2) $.offset(4) $.bind[hash]]]
1.260 moko 357: bind associates variables in the query with their values
358: currently implemented only for oracle
359: in the query you need to write ":name"
360: in the bind parameter pass a hash from which the value is taken (or where it is written)
361: ^table.save[[nameless|append;]path[;options, see load]]
362: saves the table to a file
363: ^table.menu{body}[[delimiter]]
364: executes the body code for each row of the table
365: ^table.foreach[position;value]{body}[[delimiter]]
366: ^table.line[]
367: current table row, starting from 1
368: ^table.offset[]
369: offset of the current row from the start, starting from 0
370: ^table.offset[[whence]](5)
371: shifts whence=cur|set, without whence = cur
372: ^table.count[], ^table.count[rows]
373: number of rows in the table
374: ^table.count[columns]
375: number of columns
376: ^table.count[cells]
377: number of cells in the current row
378: ^table.sort{{string-key-maker}|(numeric-key-maker)}[{desc|asc}] default=asc
379: ^table.append{data}
380: ^table.append[ $.column_name[column_value] ]
381: ^table.insert{data} add a record at the current position
382: ^table.insert[ $.column_name[column_value] ]
383: ^table.delete[]
384: deletes the record at the current position
385: ^table.join[table][$.limit(1) $.offset(5) $.offset[cur]]
386: adds records from the table, tables must have the same structure
387: ^table.flip[]
388: returns the transposed version
389: ^table.locate[field;value][[$.limit(1) $.offset(5) $.offset[cur] $.reverse(1)]]
390: moves the current row if found. returns bool
391: ^table.locate(logical expression)[[$.limit(1) $.offset(5) $.offset[cur] $.reverse(1)]]
392: moves the current row if found. returns bool
393: ^table.hash{[field]|{code}|(expression)}[[value field(s)|table of value fields]{value code}][[$.distinct(1) $.distinct[tables] $.type[hash]]]
394: by default $hash.key value is a hash where value fields are keys
395: value fields may not be specified, then they are all columns including the key
396: if distinct is true, no error if duplicate keys
397: if distinct is tables, a hash of tables is created, containing rows with that key
398: $.type[string/table] changes the element value to a string (specify one column) or a table
399: ^table.columns[[column name]]
400: table of one column 'column' or as provided
401: ^table.cells[], ^table.cells(limit)
402: returns an array of cells of the current row
403: ^table.array[]
404: returns an array of hashes, each hash representing the data of one row
405: ^table.array[column]
406: returns an array of values from the specified column
407: ^table.array{code}
408: returns an array of results from executing the given code for each row
409: ^table.rename[column name;new column name] ^table.rename[ $.column_name[new column name] ...]
410: renames a column or multiple columns
411: $selected[^table.select(expression)]
412: a table from those columns and rows where the condition matched
1.86 paf 413: $adults[^man.select($man.age>=18)]
1.260 moko 414: ^table.color[color1;color2]
415: alternates color1 and color2 for each row
1.1 paf 416:
1.251 moko 417: hash
1.260 moko 418: in expression
419: logical value means "not empty?", a hash with _default is already not empty
420: numerical value equals count[]
421: $hash.key
422: _default - a special key, if defined,
423: then when accessing a non-existing key, _default value is returned
424: $hash.fields
425: returns $hash, making hash class more similar to table class
1.251 moko 426: ^hash::create[[|copy_from_hash|copy_from_hashfile]]
1.260 moko 427: creates a new hash, a copy of the old one
428: ^hash.add[term]
429: overwrites entries with the same name
430: ^hash.sub[subtracted]
431: ^hash.union[b]
432: union, same-named remain
433: ^hash.intersection[b][[$.order[self|arg]]]
434: intersection, new hash, order defines the element order (as in the source hash or parameter hash)
435: ^hash.intersects[b] = bool
436: ^hash::sql{query}[[$.distinct(1) $.limit(2) $.offset(4) $.type[hash|string|table]]]
437: results is hash(keys = values of the first column of the response) of hash(keys = names of the other columns), or
438: string = each element's value is a string (need exactly two columns), or
439: table = each element's value is a table
440: ^hash.keys[[name of key column]]
441: a table of one 'key' column or as provided
442: ^hash.count[]
443: ^hash.foreach[key;value]{body}[[delimiter]|{delimiter executed before each non-empty non-first body}]
444: ^hash.delete[key]
445: delete key
1.265 moko 446: ^hash.contains[key]
1.260 moko 447: checks if hash contains a key (bool)
448: ^hash.at[first|last][[key|value|hash]]
449: ^hash.at([-]N)[[key|value|hash]]
450: access specified elements of an ordered hash
451: ^hash.set[first|last;value]
452: ^hash.set([-+]N)[value]
453: sets the value of the specified ordered hash element
1.268 moko 454: ^hash.array[[keys|values]]
455: is equivalent to ^array::copy[$hash] or returns an array of the hash’s keys or values
1.260 moko 456: ^hash.rename[old_key;new_key]
457: ^hash.rename[ $.old_key[new_key] ...]
458: renames the specified hash keys
459: ^hash.sort[key;value]{{string-key-maker}|(numeric-key-maker)}[[desc|asc]] default=asc
460: $reversed_hash[^hash.reverse[]]
461: $selected[^hash.select[key;value](expression)[ $.limit(N) $.reverse(bool) $.default(bool) ]]
462: a hash of keys and values for which the condition is true
1.255 moko 463:
1.252 moko 464: hashfile
465: ^hashfile::open[filename]
1.260 moko 466: ^hashfile.clear[]
467: forget all
468: $hashfile.key[value]
469: put value
470: $hashfile.key[$.value[value] $.expires[VALUE]]
471: put value until expires
472: expires can be a date, or number of days (0days=forever)
473: $hashfile.key retrieve
474: ^hashfile.delete[key] delete key
475: ^hashfile.delete[] delete files containing data
476: ^hashfile.hash[]
477: convert to a regular hash
478: removing expired pairs along the way
479: ^hashfile.foreach[key;value]{body}[[delimiter]|{delimiter executed before each non-empty non-first body}]
480: ^hashfile.release[]
481: write data and release locks.
482: next access to elements will reopen automatically.
483: ^hashfile.cleanup[]
484: iterate all elements and delete expired ones.
1.132 paf 485:
1.260 moko 486: example:
1.170 paf 487: $sessions[^hashfile::open[/db/sessions]]
488: $sid[^math:uuid[]]
489: $sessions.$sid[$.value[$uid] $.expires(1)]
490: $uid[$sessions.$sid]
1.132 paf 491:
1.255 moko 492: array
1.260 moko 493: in expression
494: logical value means "not empty?"
495: numerical value equals count[]
496: $array.index, $array.(expression)
497: returns the value at the given index
498: $array.index[value], $array.(expression)[value]
499: assigns a value by index
500: $array[value;value;...]
501: creates an array with the given values
1.255 moko 502: ^array::create[]
1.260 moko 503: ^array::create[value;value;...]
504: creates an array with the given values or an empty array
505: ^array::copy[array or hash with numeric keys]
506: copies an array or a hash with numeric keys
507: ^array.add[array or hash with numeric keys]
508: adds elements from another array or hash, overwriting values for matching indexes
509: ^array.join[array or any hash]
510: appends elements from another array or hash to the end of the array
511: ^array.append[value;value;...]
512: appends elements to the end of the array
513: ^array.insert(index)[value;value;...]
514: inserts elements at the specified position in the array
515: ^array.left(n)
516: returns a new array of the first n elements
517: ^array.right(n)
518: returns a new array of the last n elements
519: ^array.mid(m;n)
520: returns a new array containing n initialized elements starting from position m
521: ^array.delete(index)
522: deletes an array element, leaving an empty spot
523: ^array.remove(index)
524: deletes an element and shifts subsequent elements to fill the gap
525: ^array.push[value]
526: adds an element to the end of the array
527: ^array.pop[]
528: returns the last element and removes it from the array
1.265 moko 529: ^array.contains(index)
1.260 moko 530: checks if an element exists at the given index (bool)
531: ^array::sql{query}[ $.sparse(false|true) $.distinct(false|true) $.limit(n) $.offset(n) $.type[hash|string|table] ]
532: creates an array based on a database query
533: $.sparse(false), default - create a normal array. Row values from the query are added sequentially
534: $.sparse(true) - create a sparse array. The first column must contain indexes
535: at which values will be placed (similar to ^hash::sql{})
536: result is an array of hash (keys=column names of the rest of the answer) or
537: string = each element's value is a string (need exactly two columns), or
538: table = each element's value is a table
539: ^array.keys[[column name for keys]]
540: a table of one 'key' column (or as provided) with the indexes of initialized elements
541: ^array.count[]
542: the number of initialized elements in the array
543: ^array.count[all]
544: the total number of elements, including uninitialized ones
545: ^array.foreach[index;value]{code}[[delimiter]|{delimiter executed before each non-empty non-first body}]
546: iterates over all initialized elements
547: ^array.for[index;value]{code}[[delimiter]|{delimiter executed before each non-empty non-first body}]
548: iterates over all elements
549: ^array.at[first|last][[key|value|hash]]
550: ^array.at([-]number)[[key|value|hash]]
551: accesses an array element by its ordinal number
552: ^array.set[first|last][value]
553: ^array.set([-]number)[value]
554: sets the value of an array element by ordinal number
555: ^array.compact[]
556: removes uninitialized elements
557: ^array.compact[undef]
558: removes uninitialized and empty elements
559: ^array.sort[key;value]{{string-key-maker}|(numeric-key-maker)}[[desc|asc]] default=asc
560: sorts the array
561: $reversed_array[^array.reverse[]]
562: returns a new array with elements in reverse order
563: $selected[^array.select[key;value](expression)[ $.limit(N) $.reverse(bool) ]]
564: selects array elements for which the condition is true
1.255 moko 565:
1.262 moko 566: date
567: date type can be used in expressions, substituting the number of days since epoch [1 January 1970 (UTC)], fractional
568: the string value is in local time, numerically in UTC, range from 0000-00-00 00:00:00 to 9999-12-31 23:59:59
569: by default the OS-defined timezone is used
570:
571: ^date::now[]
572: ^date::now(days offset)
573: returns now+offset
574: ^date::today[]
575: date at 00:00:00 of the current day
576: ^date::today(integer days offset)
577: date at 00:00:00 of current day+offset
578: ^date::create(days since epoch)
579: ^date::create(year;month[;day[;hour[;minute[;second[;TZ]]]]])
580: ^date::create[date in format %Y-%m-%d %H:%M:%S]
581: convenient creation from a value from a database
582: format1: %Y[-%m[-%d[ %H[:%M[:%S]]]]]
583: format2: %H:%M[:%S]
584: ^date::create[date in format %Y-%m-%dT%H:%M[:%S]TZ]
585: for creation from ISO 8601 format
586: TZ format: Z(UTC) or +-hour[:minute] (offset from UTC)
587: ^date::unix-timestamp()
588: ^date.unix-timestamp[]
589: $date.year month day hour minute second weekday yearday(0...) daylightsaving TZ weekyear
590: TZ="" << local zone
591: $date.year month day hour minute second can be set to new values, others are read-only
592: ^date.double[] ^date.int[]
593: the number of days since epoch [1 January 1970 (UTC)], fractional or truncated
594: ^date.roll[year|month|day](+-offset)
595: shifts the date
596: ^date.roll[TZ;New zone]
597: says that the date is in such a timezone: affects .hour & Co
598: ^date:roll[TZ;New zone]
599: says that by default all dates are in that timezone
600: ^date.sql-string[[datetime|date|time]]
601: datetime or without parameter - %Y-%m-%d %H:%M:%S
602: date - %Y-%m-%d
603: time - %H:%M:%S
604: where published='^date.sql-string[]'
1.269 moko 605: ^date:sql-string[[datetime|date|time]]
606: sql-string for now
1.262 moko 607: ^date:calendar[rus|eng](year;month)
608: returns an unnamed table, columns: 0..6, week, year
609: ^date:calendar[rus|eng](year;month;day)
610: returns a named table, columns: year, month, day, weekday
611: ^date:last-day(year;month)
612: returns the last day of the month
613: ^date.last-day[]
614: returns the last day of $date's month
615: ^date.gmt-string[]
616: Fri, 23 Mar 2001 09:32:23 GMT
1.269 moko 617: ^date:gmt-string[]
618: gmt-string for now
1.262 moko 619: ^date.iso-string[]
620: 2001-03-23T12:32:23+03
1.269 moko 621: ^date:iso-string[]
622: iso-string for now
1.262 moko 623:
624: file
625: $uploaded_file_from_post.name
626: $uploaded_file_from_post.size
627: $uploaded_file_from_post.text
1.268 moko 628: ^file.save[text|binary;filename[;$.charset[which charset to save in] $.append(false)]]
1.262 moko 629: ^file:delete[filename]
1.275 moko 630: ^file:rmdir[dirname[; $.exception(false) ]]
631: removes the empty directory
1.262 moko 632: ^file:find[filename][{if not found}]
633: ^file:list[path[;pattern-string|pattern-regex]]
1.279 ! moko 634: table with columns name dir symlink
1.262 moko 635: ^file:list[path;$.filter[pattern-string|pattern-regex] $.stat(true)]
1.279 ! moko 636: table with columns name dir symlink size [mca]date
1.262 moko 637: ^file::load[text|binary;big.zip[;domain_press_release_2001_03_01.zip][;options]]
638: ^file::create[text|binary;filename;data]
639: ^file::create[text|binary;filename;data[;$.charset[charset of the created file] $.content-type[...]]]
640: ^file::create[string-or-file-content[;$.name[name] $.mode[text|binary] $.content-type[...] $.charset[...]]]
641: $loaded_file.size
642: $loaded_or_created_file.mode = text/binary
643: ^file::stat[filename]
644: $stated_or_loaded_file.size .adate .mdate .cdate
645: ^file::cgi[[text|binary;]filename[;env hash +options[;1cmd[;2line[;3ar[;4g[;5s]]]]]]]
646: any argument can be string or array of strings
647: the returned header is split into $fields
648: $status
649: $stderr
650: ^file::exec[[text|binary;]filename[;env hash[;1cmd[;2line[;3ar[;4g[;5s;...under unix max 50 args]]]]]]]
651: any argument can be string or array of strings
652: options:
653: $.stdin[text|file] if empty, disables automatic passing of HTTP-POST data
654: ^file:move[oldfilename;newfilename]
1.275 moko 655: can rename and move files and directories, but not across disk boundaries
656: the existing file is replaced, as well as the empty directory if a directory is moved
1.262 moko 657: directories for dest are created with 775 permissions
658: source directory is removed if empty after move
659: ^file:copy[filename;copy_filename[; $.append(1) ]]
660: can only copy files
661: ^file:lock[filename]{code}
662: the file is created if necessary
663: locked
664: code executed
665: unlocked
666: ^file:dirname[/a/some.tar.gz|file]=/a (works like *nix command)
667: ^file:dirname[/a/b/|file]=/a (works like *nix command)
668: ^file:basename[/a/some.tar.gz|file]=some.tar.gz (like *nix)
669: ^file:basename[/a/b/|file]=b (like *nix)
670: ^file:justname[/a/some.tar.gz|file]=some.tar
671: ^file:justext[/a/some.tar.gz|file]=gz
672: /some/page.html: ^file:fullpath[a.gif] => /some/a.gif
673: ^file.sql-string[]
674: inside ^connect gives a correctly escaped string that can be used in queries
675: ^file::sql{query}[[ $.name[filename_for_download] $.content-type[user content-type] ]]
676: the query result should be "one row".
677: columns:
678: first column - data
679: if second exists - filename
680: if third - content-type
681: ^file.base64[ $.pad(bool) $.wrap(bool) $.url-safe(bool) ]
682: encode
683: ^file:base64[filename[; $.pad(bool) $.wrap(bool) $.url-safe(bool) ]]
684: encode
685: ^file::base64[encoded string[; $.pad(bool) $.strict(bool) $.url-safe(bool) ]]
686: decode
687: ^file::base64[mode;filename;encoded string[; $.content-type[...] $.pad(bool) $.strict(bool) $.url-safe(bool) ]]
688: decode
689: ^file:crc32[filename]
690: calculates crc32 of the specified file
691: ^file.crc32[]
692: calculates crc32 of the object
693: ^file.md5[], ^file:md5[filename]
694: returns the file's digest, 16 bytes as a string,
695: bytes in hex, contiguous, lowercase
696:
697: image
698: $image[^image::measure[DATA[; $.exif(bool) $.xmp(bool) $.xmp-charset[] $.video(bool) ]]]
699: checks the file extension case-insensitively
700: can measure gif, jpg, tiff, bmp, webp and mp4 (mov)
701: $image.exif << hash after measure jpeg with exif information and $.exif(true)
702: $image.exif.DateTime & co
703: [full list see https://exiftool.org/TagNames/EXIF.html]
704: numbers as int/double,
705: dates as date,
706: enumerations as hash with keys 0..count-1
707: $image.src .width .height
708: $image.line-width number=line width
709: $image.line-style string=line style '*** * '='*** * *** * *** * '
710: ^image.html[[hash]]
711: <img ...>
712: ^image::load[background.gif]
713: only gif so far
714: ^image::create(width X;height Y[;background color default white]])
715: ^image.line(x0;y0;x1;y1;0xffFFff)
716: ^image.fill(x;y;0xffFFff)
717: ^image.rectangle(x0;y0;x1;y1;0xffFFff)
718: ^image.bar(x0;y0;x1;y1;0xffFFff)
719: ^image.replace(hex-color1;hex-color2)[table x:y polygon_vertices]
720: ^image.polyline(color)[table x:y points]
721: ^image.polygon(color)[table x:y polygon_vertices]
722: ^image.polybar(color)[table x;y polygon_vertices]
723: ^image.font[set_of_letters;font_file.gif][(space_width[;char_width])]
724: the character height = image height/number of letters in the set
725: if char_width is specified, then monospaced, if 0, char_width = gif width
726: ^image.font[set_of_letters;font_file.gif;
727: $.space(space_width) // default = gif width
728: $.width(char_width) // see above, default proportional
729: $.spacing(letter_spacing) // default = 1
730: ]
731: ^image.text(x;y)[text] AS_IS
732: ^image.length[text] AS_IS
733: ^image.gif[optional filename]
734: encodes to FILE with content-type=image/gif the filename will be used by $response:download
735: ^image.arc(center x;center y;width;height;start in degrees;end in degrees;color)
736: ^image.sector(center x;center y;width;height;start in degrees;end in degrees;color)
737: ^image.circle(center x;center y;r;color)
738: ^image.copy[source](src x;src y;src w;src h;dst x;dst y[;dest w[;dest h[;tolerance]]])
739: if dest_w/dest_h are specified, resizes the piece
740: when reducing size, does resample
741: only suitable for simplifying low-color graphics like charts/pie,
742: not suitable for thumbnails
743: if dest_h is not specified, aspect ratio is kept
744: tolerance - a number [square distance in RGB space to the target color],
745: defining how greedy the color approximation from the palette is [default=150]
746: smaller - more accurate but colors run out quickly
747: larger - less accurate approximation, but covers a bigger part
748: ^image.pixel(x;y)[(color)]
749: get or set pixel color
750:
751: regex
752: in expression
753: logical value is always true
754: numerical value is equal to the number of bytes of the compiled pattern
755: ^regex::create[pattern-string|regex][[search options]]
756: ^pattern.size[]
757: number of bytes of the compiled pattern
758: if the value is very large - it is worth consulting pcre documentation and possibly rewriting the pattern
759: ^pattern.study_size[]
760: size of the study-structure. if == 0 - the pattern cannot be "studied"
761: $pattern.pattern
762: the text of the pattern
763: $pattern.options
764: the string with the original text of the options
765:
1.273 moko 766: amqp
767: ^amqp::create[[
768: $.host[localhost] $.port(5672) $.user[guest] $.password[guest] $.vhost[/] $.locale[en_US]
769: $.heartbeat(30) $.auto_reconnect(seconds)
770: $.tls[ $.ca[file] $.cert[file] $.key[file] $.verify(true) ]
771: ]]
772: connects to a RabbitMQ broker
773: auto_reconnect(N): after a lost connection reconnect before the next operation, waiting N seconds
774: tls: the server certificate is verified only if ca is specified
775: ^amqp.publish[message][[
776: $.exchange[] $.routing_key[key]|$.queue[name] $.mandatory(false)
777: message properties: $.content_type[] $.content_encoding[] $.delivery_mode(1|2) $.priority(N) $.correlation_id[] $.reply_to[]
778: $.expiration[] $.message_id[] $.timestamp(N) $.type[] $.user_id[] $.app_id[] $.cluster_id[] $.headers[hash]
779: ]]
780: ^amqp.consume[ $.queue[name] $.ack(true) $.count(1) $.timeout(0) $.exclusive(false) $.consumer_tag[] ]
781: array of messages ready within timeout seconds (only the first one is waited for)
782: ^amqp.consume[ $.queue[name] $.callback[$method] ... ]
783: calls @method[message] for each message until ^amqp.stop_consume[], count messages or timeout seconds without messages
784: count and timeout are unlimited by default
785: message: hash with msg, delivery_tag, routing_key, exchange, redelivered, consumer_tag and the properties set
786: ^amqp.ack(delivery_tag)
787: with $.ack(true) (default) received messages must be acknowledged
788: ^amqp.nack(delivery_tag)[ $.requeue(false) ]
789: ^amqp.reject(delivery_tag)[ $.requeue(true) ]
790: ^amqp.qos[ $.prefetch_count(N) ]
791: ^amqp.declare[ $.queue[name] $.durable(false) $.exclusive(false) $.auto_delete(false) $.passive(false) $.arguments[hash] ]
792: for an empty name the server creates a queue with its own name, which is returned
793: ^amqp.declare[ $.exchange[name] $.type[direct] $.durable(false) $.auto_delete(false) $.internal(false) $.passive(false) $.arguments[hash] ]
794: ^amqp.delete[ $.queue[name]|$.exchange[name] $.if_unused(false) $.if_empty(false) ]
795: ^amqp.bind[ $.exchange[name] $.queue[name] $.routing_key[] ]
796: ^amqp.unbind[ $.exchange[name] $.queue[name] $.routing_key[] ]
797: ^amqp.purge[ $.queue[name] ]
798: number of deleted messages
799: ^amqp.info[ $.queue[name] ]
800: hash with queue, messages, consumers
801: ^amqp.release[]
802: closes the connection
803: arguments and headers values: [string], (number), (true|false)
804:
1.262 moko 805: console
806: $console:timeout
807: $console:line
808: read/write string
809:
810: cookie
811: $cookie:name read old or newly set cookie
812: $cookie:name[value] for 90 days
813: $cookie:name[$.value[value] $.expires[VALUE] $.secure(true) $.domain[domain name] $.httponly(true)]
1.272 moko 814: the expires field value can be 'session', a date, or a number of days (0days=session)
1.262 moko 815: if it's a date, it will be converted to "Sun, 25-Aug-2002 12:03:45 GMT"
816: $cookie:fields
817: hash with all cookies
818:
1.263 moko 819: curl
820: ^curl:load[[
821: $.url[http://URL]
822: $.timeout(N)
823: $.ssl_verifypeer(0)
824: $.mode[text|binary] type of the created file
825: ]]
826: downloads a file from a remote server, can be called multiple times within one session;
827: any libcurl option can be specified, option names in lowercase without the CURLOPT_ prefix
828: ^curl:options[[
829: $.library[libcurl.so.4]
830: $.charset[UTF-8]
831: ...
832: ]]
833: subsequent ^curl:load calls inherit the specified options, the path to libcurl must be set before using curl
834: ^curl:session{code}
835: creates a cURL session, common options can be set, multiple downloads performed
836: ^curl:info[name], ^curl:info[]
837: information about the last request (a value or a hash)
838: ^curl:version[]
839: the version of the cURL library in use
840:
1.262 moko 841: env
842: $env:variable
843: $env:fields hash with environment variables
844: $env:PARSER_VERSION parser version
845:
1.252 moko 846: form
1.260 moko 847: [the first element with the same name is taken from GET, then from POST]
848: $form:field
1.257 moko 849: string/file
850: $form:nameless
1.260 moko 851: field with a value from a nameless parameter "?value&...", "...&value&...", "...&value"
1.257 moko 852: $form:qtail
1.260 moko 853: string with the value after the second "?xxxxx" if there was no ',' [imap]
1.257 moko 854: $form:fields
1.260 moko 855: hash with all form fields
856: $form:elements.field
857: array with all values of the field - both string and file
858: $form:tables.field
859: table with one column "field" containing the values for multiple entries
860: $form:files.field
861: hash with file-type field values, keys - 0, 1, ..., value - file
1.257 moko 862: $form:imap
1.260 moko 863: a hash with keys 'x' and 'y' with ?1,2 suffixes when using server-side image map
1.1 paf 864:
1.262 moko 865: inet
866: ^inet:ntoa(long)
867: ^inet:aton[IP]
868: ^inet:name2ip[name][[ $.ipv[4|6|any] $.table(true) ]]
869: direct conversion of a name to an IP address
870: ^inet:ip2name[ip][ $.ipv[4|6|any] ]
871: reverse conversion from IP address to name
872: ^inet:hostname[]
873: host name
1.252 moko 874:
1.262 moko 875: json
876: ^json:parse[-json-string-[;
877: $.depth(maximum depth, default == 19)
878: $.double(false) disable built-in parsing of floating-point numbers (enabled by default)
879: in this case they will appear in the resulting object as strings
880: $.int(false) disable built-in parsing of integers (enabled by default)
881: in this case they will appear in the resulting object as strings
882: $.distinct[first|last|all] how duplicate keys in objects are handled
883: first - keep the first encountered element
884: last - keep the last encountered element
885: all - keep all elements. starting from the 2nd,
886: they get numeric suffixes (key_2 etc)
887: by default duplicate keys cause an exception
888: $.object[method-junction] user method[key;object], called for all parsed
889: objects and object keys; method returns a new object
890: $.array[method-junction] user method called for arrays
891: $.taint[taint language] sets the transformation language for all result strings
892: ]]
893: parses a json-string into a hash
1.252 moko 894:
1.262 moko 895: ^json:string[system or user object[;
896: $.skip-unknown(false) disable exception and output 'null' when serializing objects of types
897: other than void, bool, string, int, double, date, table, hash, and file
898: $.indent(true) format the resulting string with indentation according to nesting depth
899: $.date[sql-string|gmt-string|iso-string|unix-timestamp]
900: date output format, default = sql-string
901: $.table[object|array|compact]
902: format for tables, default=object
903: object: [{"c1":"v11","c2":"v12",...},{"c1":"v21","c2":"v22",...},...]
904: array: [["c1","c2",...] || null (for nameless),["v11","v12",...],...]
905: compact: ["v11" || ["v11","v12",...],...]
906: $.file[text|base64|stat] output file content in the specified mode (by default file content
907: is not included in output)
908: $.xdoc[hash] parameters for converting xdoc to string (as in ^xdoc.string[])
909: $.type[method-junction] any type can be output using a user method
910: that must take 3 parameters: key, object of that type, and options
911: of the ^json:string[] call
912: $._default[method] user method, called to output all user-class objects.
913: The method must take 3 parameters: key, object, and call options.
914: $._default[method name] method name of a user method, if present it will be called for serialization
915: $.void[null|string] undefined value will be output as null (default)
916: or as an empty string
917: ]]
918: serializes a system or user object into a json-string
1.220 misha 919:
1.252 moko 920: mail
921: $mail.received=MESSAGE:
1.51 paf 922: .from
923: .reply-to
924: .subject
1.260 moko 925: .date of class date
1.51 paf 926: .message-id
927: .raw[
1.260 moko 928: .RAW_USER_HEADER_FIELD
1.51 paf 929: ]
1.260 moko 930: $.{text|html|file#}[ << numbered as in mail:send (text, text2, ...) (file, file2, ...)
1.51 paf 931: $.content-type[
932: $.value[{text|...|x-unknown}/{plain|html|...|x-unknown}]
1.260 moko 933: [$.charset[windows-1251]] << in which it arrived, now already transcoded
934: $.USER_DEFINED_HEADER_FIELD
1.51 paf 935: ]
936: $.description
937: $.content-id
938: $.content-md5
939: $.content-location
940: .raw[
1.260 moko 941: .RAW_USER_HEADER_FIELD
1.51 paf 942: ]
1.260 moko 943: $.value[string|FILE]
1.51 paf 944: ]
1.52 paf 945: $.message#[MESSAGE] (message, message2, ...)
1.51 paf 946:
1.277 moko 947: ^mail:parse[string|file]
948: parses the letter and returns MESSAGE, the same as $mail.received for the incoming one
949:
1.252 moko 950: ^mail:send[
1.230 misha 951: $.options[-odd]
1.260 moko 952: unix: a string that will be added to the sendmail startup command
953: -odd means "quickly put in the queue without email checking"
954: win32: ignored
955: $.charset[the encoding of the headers and text blocks]
1.252 moko 956: $.any-header-field
1.51 paf 957: $.text[string]
958: $.text[
1.260 moko 959: $.any-header-field
960: $.value[string]
1.51 paf 961: ]
962: $.html{string}
963: $.html[
1.252 moko 964: $.any-header-field
1.51 paf 965: $.value{string}
966: ]
967: $.file#[FILE]
968: $.file#[
1.252 moko 969: $.any-header-field
1.51 paf 970: $value[FILE]
971: ]
972: ]
1.264 moko 973: if charset is specified, the email is transcoded to this charset
974: content-type.charset does not affect transcoding
975: after the part name a # number can follow
1.252 moko 976:
977: ^mail:send[
1.260 moko 978: # by default, matches the source encoding.
979: # sets the body encoding
1.252 moko 980: $.charset[windows-1251]
1.260 moko 981: # no default
1.252 moko 982: $.content-type[$.value[text/plain] $.charset[windows-1251]]
1.260 moko 983: $.from["vasya" <vasya@design.ru>]
984: $.to["petya" <petya@design.ru>]
985: $.subject[subject]
1.252 moko 986: $.body[
1.260 moko 987: text
1.51 paf 988: ]
1.252 moko 989: ]
990:
1.260 moko 991: ^mail:send[$.header-field[] $.charset[mail encoding] $.body[if body is not a string, but a hash, a multipart email is sent]]
992: if charset is specified, the email is transcoded to that charset
993: content-type.charset does not affect transcoding
994: after the part name, an integer can follow, parts go in numerical order.
995: if body is a string, then it's just the email text, no attachments.
996: if body is a hash, then these are parts, text blocks first, then attachments
997: this is the old format, supported for backward compatibility
998: if the part name begins with "text", it's a text block.
999: if the part name begins with "file", it's an attachment, format:
1.253 moko 1000: $file[$.format[uue|base64] $.value[DATA] $.name[user-file-name]]
1.260 moko 1001: important: for multipart do not specify content-type
1.252 moko 1002:
1.1 paf 1003: ^mail:send[
1.260 moko 1004: # by default, matches the source encoding
1005: # sets the body encoding
1.252 moko 1006: $.charset[windows-1251]
1.260 moko 1007: # no default
1.1 paf 1008: $.content-type[$.value[text/plain] $.charset[windows-1251]]
1.260 moko 1009: $.from["vasya" <vasya@design.ru>]
1010: $.to["petya" <petya@design.ru>]
1011: $.subject[subject]
1.1 paf 1012: $.body[
1.260 moko 1013: text
1.1 paf 1014: ]
1015: ]
1.252 moko 1016:
1.1 paf 1017: ^mail:send[
1.260 moko 1018: $.from["vasya" <vasya@design.ru>]
1019: $.to["petya" <petya@design.ru>]
1020: $.subject[subject]
1.1 paf 1021: $.body[
1022: $.text[
1.260 moko 1023: # sets the body encoding
1.1 paf 1024: $.charset[windows-1251]
1.260 moko 1025: # no default
1.1 paf 1026: $.content-type[$.value[text/plain] $.charset[windows-1251]]
1.260 moko 1027: $.body[words]
1.1 paf 1028: ]
1.260 moko 1029: # for convenience you can specify only one part, then it won't be multipart
1.189 misha 1030: $.file[
1.259 moko 1031: $.value[^file::load[my beloved.doc]]
1032: $.name[my beloved.doc]
1033: $.format[base64]
1.1 paf 1034: ]
1.189 misha 1035: $.file2[
1.259 moko 1036: $.value[^file::load[my beloved.doc]]
1037: $.name[my beloved.doc]
1038: ]
1.1 paf 1039: ]
1040: ]
1.260 moko 1041: under unix, the program with arguments is used, set by
1042: $MAIL.sendmail[command]
1043: if not specified, checks if /usr/sbin/sendmail or
1044: /usr/lib/sendmail is available and if so, runs with "-t".
1.252 moko 1045:
1.260 moko 1046: under Windows, SMTP protocol is used, server is set by
1.21 paf 1047: $MAIL.SMTP[smtp.domain.ru]
1.1 paf 1048:
1.253 moko 1049: math
1050: $math:PI
1051: ^math:round floor ceiling
1052: ^math:trunc frac
1053: ^math:abs sign
1.275 moko 1054: ^math:min(a;b[;c...]) max(a;b[;c...])
1.256 moko 1055: ^math:exp log log10
1056: ^math:sin asin cos acos tan atan atan2
1.253 moko 1057: ^math:degrees radians
1058: ^math:pow sqrt
1.260 moko 1059: ^math:random(range_width)
1060: ^math:convert[number|file](base-from;base-to)[[ $.format[string|file] ]]
1061: ^math:convert[number|file][alphabet](base-to)[[ $.format[string|file] ]]
1062: ^math:convert[number|file](base-from)[alphabet][[ $.format[string|file] ]]
1063: converts a string or file with a number from one numeral system to another
1064: the numeral system can be set by an alphabet, a number from 2 to 16 (equivalent to the alphabet 0123456789ABCDEF), or 256 (all ASCII characters)
1.270 moko 1065: ^math:eq(a;b[;max ULP])
1066: true if difference between doubles less or equal max ULPs (default 3)
1.254 moko 1067: ^math:uuid[ $.lower(bool) $.solid(bool) ]
1.113 paf 1068: 22C0983C-E26E-4169-BD07-77ECE9405BA5
1.260 moko 1069: win32: uses cryptapi
1070: unix: uses /dev/urandom,
1071: if not present, /dev/random,
1072: if not, rand
1.256 moko 1073: ^math:uuid7[ $.lower(bool) $.solid(bool) ]
1074: 0193CBF0-7898-7000-A391-AC513CC15658
1075: https://www.rfc-editor.org/rfc/rfc9562.html#name-uuid-version-7
1.254 moko 1076: ^math:uid64[ $.lower(bool) ]
1.253 moko 1077: BA39BAB6340BE370
1078: ^math:md5[string]
1.260 moko 1079: returns the digest of the string, 16 bytes as a string,
1080: bytes in hex, contiguous, lowercase
1.253 moko 1081: ^math:crypt[password;salt]
1.260 moko 1082: salt prefix $apr1$ triggers built-in MD5 algorithm,
1083: if salt body is empty, it is generated randomly
1084: $1$ calls the OS 'crypt' MD5 algorithm if supported.
1085: for other salts see OS 'crypt' documentation.
1.253 moko 1086: ^math:crc32[string]
1.260 moko 1087: calculates crc32 of the string
1.253 moko 1088: ^math:sha1[string]
1.260 moko 1089: ^math:digest[[md5|sha1|sha256|sha512];string or file][[ $.format[hex|base64|file] $.hmac[key string|key file] ]]
1090: combines the ability to use various cryptographic hashing algorithms.
1091: $.hmac[key] for verifying the integrity of transmitted data
1.276 moko 1092: ^math:xxhash[xxh32|32|xxh64|64;string or file][[ $.format[hex|base64|file] ]]
1093: fast non-cryptographic xxHash, 4 or 8 bytes, the most significant byte first
1.253 moko 1094:
1.260 moko 1095: memory
1096: ^memory:compact[]
1097: collect garbage, freeing space for new data (warning: process memory is never released)
1098: useful before XSL transform
1099: ^memory:auto-compact(frequency)
1100: sets automatic garbage collection frequency, from 0 (off) up to 5 (max)
1101:
1.262 moko 1102: reflection
1103: ^reflection:create[class;constructor[;pa[;ra[;ms]]]]
1104: calls the specified class constructor (no more than 100 parameters)
1105: ^reflection:create[ $.class[name] $.constructor[name] $.arguments[ $.1[pa] $.2[ra] $.3[ms] ] ]
1106: calls the specified class constructor
1107: ^reflection:classes[]
1108: a hash of all classes. key = class name, value can be methoded (a class with methods) or void
1109: ^reflection:class[object]
1110: the class of the given object
1111: ^reflection:class_name[object]
1112: the class name of the given object
1113: ^reflection:base[object]
1114: the parent class of the given object
1115: ^reflection:base_name[object]
1116: the parent class name of the given object
1117: ^reflection:class_by_name[class name]
1118: obtains the class by name
1119: ^reflection:class_alias[class name;new class name]
1120: sets an alias for the specified class
1121: ^reflection:def[class;class name]
1122: checks if the class exists
1123: ^reflection:methods[class]
1124: a hash with a list of methods of the specified class, values are strings 'native' or 'parser'
1125: ^reflection:method[class or object;method name]
1126: returns the junction-method of the class or object
1127: ^reflection:filename[object or class or method]
1128: returns the filename where the object, class or method is defined
1129: ^reflection:fields[class or object]
1130: a hash with the list of static fields of the specified class or dynamic fields of the specified object
1131: ^reflection:fields_reference[object]
1132: an editable hash of the dynamic fields of the specified object
1133: ^reflection:field[class or object;field name]
1134: returns the value of the specified field of the class or object. getters are ignored.
1135: ^reflection:copy[source;destination]
1136: copies fields from one object or class to another
1137: ^reflection:uid[class or object]
1138: returns the identifier of the object or class
1139: ^reflection:method_info[class;method]
1140: a hash with parameters of the specified class method
1141: $.inherited[class] name of the class where the method was defined (returned only if the method was defined in an ancestor)
1142: $.overridden[class] name of the class where the method was defined (returned only if the method was defined in an ancestor)
1143: for native classes a hash is returned:
1144: .min_params(minimum required number of parameters)
1145: .max_params(maximum possible number of parameters)
1146: .call_type[dynamic|static|any]
1147: for parser classes a hash is returned:
1148: key is parameter number (0, 1, ...), value is parameter name
1149: ^reflection:dynamical[[object or class, caller if absent]]
1150: returns true if the method was called from a dynamic context when passing
1151: a parameter returns true if a dynamic object was passed, false if a class
1152: ^reflection:delete[class or object;variable name]
1153: deletes the variable with the specified name in the specified class or object
1154: ^reflection:is[element name;class name][[context]]
1155: analogous to the 'is' operator, allowing to determine if the element is code.
1156: ^reflection:tainting[[language|tainted|optimized];string]
1157: a string in which each character of the original string corresponds to a character with a transformation code
1158: ^reflection:stack[ $.args(false/true) $.locals(false/true) $.limit(n) $.offset(o)]
1159: the current state of the method call stack in the parser
1160: ^reflection:mixin[source; $.to[target] $.name[name] $.methods(true/false) $.fields(true/false) $.overwrite(false/true)]
1161: copies methods and fields from one class to another
1.269 moko 1162: ^reflection:override[method[; $.to[target] $.name[new_name]]]
1163: overrides or defines a method
1.262 moko 1164:
1.273 moko 1165: redis
1166: ^redis::open[[
1167: $.host[localhost] $.port(6379)|$.unix_socket[path]
1168: $.user[] $.password[] $.db(0) $.timeout(2) $.protocol(3) $.auto_reconnect(seconds)
1169: $.tls[ $.ca[file] $.cert[file] $.key[file] $.verify(true) ]
1170: ]]
1171: connects to a redis server
1172: timeout in seconds for connecting and for each command, 0 - unlimited
1173: protocol(2) for servers before redis 6
1174: auto_reconnect(N): after a lost connection reconnect before the next command, waiting N seconds
1175: tls: the server certificate is verified only if ca is specified
1176: ^redis.command_name[arguments;...]
1177: any redis command, e.g. ^redis.set[key;value] ^redis.get[key] ^redis.hgetall[key]
1178: ^redis.call[command;arguments;...]
1179: ^redis.f-command_name[arguments;...], ^redis.f-call[command;arguments;...]
1180: the strings of the reply are files (binary data)
1181: arguments: string, number, bool as 1/0, file as its content; array - its elements, hash - key value pairs
1182: reply: string, int, double, bool, void (nil), array, hash (map); an error reply is an exception
1183: ^redis.release[]
1184: closes the connection
1185:
1.262 moko 1186: request
1.266 moko 1187: https://site.name/a%20b/?name=some%20value
1.262 moko 1188: $request:query
1.266 moko 1189: name=some%20value
1.262 moko 1190: $request:uri
1.266 moko 1191: /a%20b/?name=value
1192: $request:path
1193: /a b/
1.262 moko 1194: $request:document-root
1195: directory relative to which paths are considered in parser, default = $env:DOCUMENT_ROOT
1196: $request:argv
1197: hash with command-line parameters. keys 0, 1, ... [0 - name of the processed file]
1198: $request:charset
1199: the source document encoding
1200: used in upper/lower and match[][i]
1201: WARNING: you must set $request/response:charset before using form class fields
1202: $request:method
1203: request method (GET|POST|PUT)
1204: $request:body
1205: POST-request body as text
1206: $request:body-file
1207: POST-request body as a file
1208: $request:body-charset
1209: POST-request encoding
1210: $request:headers
1211: hash with request headers (without HTTP_ prefix)
1212:
1213: response
1214: $response:field[value] and can read old - $response:field
1215: the value can be string or hash:
1216: $value[abc] field: {abc}<<part
1217: $attribute[zzz] field: abc; {attribute=zzz}<<part
1218: field or attribute value can be string or date
1219: if date, it will be converted to "Sun, 25-Aug-2002 12:03:45 GMT"
1220: $response:headers
1221: accumulated fields
1222: $response:body[DATA]
1223: replaces the standard response
1224: $response:download[DATA]
1225: replaces the standard response, sets a flag causing the browser to suggest download
1226: $response:status
1227: ^response:clear[] forget all set response fields
1228: $response:charset
1229: client encoding, i.e.:
1230: 1) from which $form: fields will be transcoded after retrieval from browser
1231: 2) into which the document will be transcoded before sending to browser
1232: 3) into which URI language text will be transcoded
1233: does not add anything to content-type; if needed, do it manually
1234: WARNING: you must set $request/response:charset before using form class fields
1235:
1.260 moko 1236: status
1237: $status:sql
1238: cache table
1239: url time
1240: url time
1241: url time
1242: $status:stylesheet
1243: cache table
1244: file time
1245: file time
1246: file time
1247: $status:rusage hash
1248: utime user time used
1249: stime system time used
1250: maxrss max resident set size
1251: ixrss integral shared text memory size
1252: idrss integral unshared data size
1253: isrss integral unshared stack size
1254: tv_sec
1255: tv_usec
1256: $s[$status:rusage]
1257: ^s.tv_sec.format[%.0f].^s.tv_usec.format[%06.0f]
1258: $status:memory hash
1259: used
1260: includes some pages that were allocated but never written
1261: free
1262: ever_allocated_since_compact
1263: return the number of bytes allocated since the last collection
1264: ever_allocated_since_start
1265: return the total number of bytes [EVER(c)PAF] allocated in this process,
1266: never decreases
1267: $status:pid
1268: process id
1269: $status:tid
1270: thread id
1271: $status:mode
1272: working mode, cgi|console|mail|httpd|apache|isapi
1273: $status:log-filename
1274: path to parser3.log error log
1275:
1.1 paf 1276: xdoc(xnode)
1.253 moko 1277: $xdoc.search-namespaces hash, where keys=prefixes, values=urls
1278:
1.1 paf 1279: DOM1 attributes:
1.253 moko 1280: readonly attribute DocumentType doctype
1281: readonly attribute Element documentElement
1.1 paf 1282:
1283: DOM1 methods:
1.253 moko 1284: Element createElement(in DOMString tagName)
1285: DocumentFragment createDocumentFragment()
1286: Text createTextNode(in DOMString data)
1287: Comment createComment(in DOMString data)
1288: CDATASection createCDATASection(in DOMString data)
1289: ProcessingInstruction createProcessingInstruction(in DOMString target,in DOMString data)
1290: Attr createAttribute(in DOMString name)
1291: EntityReference createEntityReference(in DOMString name)
1292: NodeList getElementsByTagName(in DOMString tagname)
1.1 paf 1293:
1294: DOM2 some methods:
1.253 moko 1295: ^.getElementById[elementId] = xnode
1296: The DOM implementation must have information that says which attributes are of type ID.
1297: Attributes with the name "ID" are not of type ID unless so defined.
1298: Implementations that do not know whether attributes are of type ID or not
1.1 paf 1299: are expected to return null.
1300:
1.260 moko 1301: String encoding and default for $.encoding equals the current output page encoding, $response:charset
1.259 moko 1302:
1.1 paf 1303: ::sql{...}
1.260 moko 1304: ::create[[URI]]{<?xml?><string/>} old name 'set'
1.253 moko 1305: ::create[[URI]][qualifiedName]
1.260 moko 1306: URI default = disk path to requested document
1307: for directories a trailing / is mandatory
1.253 moko 1308: ::create[file] can be usable:
1309: $f[^file::load[binary;http://;some HTTP options here...]]
1310: $x[^xdoc::create[$f]]
1.260 moko 1311: ::load[file.xml[;options]]
1312: .transform[rules.xsl|xdoc][[params hash]] returns dom
1313: the template is cached, cache is updated if the template file date changes,
1314: or the date of "template_name.stamp" changes [stamp date check has priority]
1.1 paf 1315: <xsl:output
1.253 moko 1316: method = "xml" | "html" | "text"
1.259 moko 1317: version = nmtoken
1318: encoding = string
1.253 moko 1319: omit-xml-declaration = "yes" | "no"
1320: standalone = "yes" | "no"
1.259 moko 1321: cdata-section-elements = qnames
1.253 moko 1322: indent = "yes" | "no"
1.259 moko 1323: media-type = string />
1.260 moko 1324: parameters are passed as is, not xpath expressions
1.253 moko 1325:
1326: .string[[output options]]
1.260 moko 1327: .save[file.xml[;output options]] with header
1.253 moko 1328: .file[[output options]] = file
1.260 moko 1329: output options are identical to xsl:output attributes
1330: [exception: cdata-section-elements ignored]
1331: returns media-type when substituting $response:body[here]
1.1 paf 1332:
1.260 moko 1333: if the document is referenced as:
1.253 moko 1334: parser://method/param/to/that/method
1.260 moko 1335: then ^MAIN:method[/param/to/that/method] is used as the document
1336: [note: the parameter always comes with a leading /, even if there were no parameters]
1.144 paf 1337:
1.253 moko 1338: xnode
1.1 paf 1339: DOM1 attributes:
1.253 moko 1340: $node.nodeName
1341: $node.nodeValue
1342: read
1343: write
1344: $node.nodeType = int
1345: ELEMENT_NODE = 1
1346: ATTRIBUTE_NODE = 2
1347: TEXT_NODE = 3
1348: CDATA_SECTION_NODE = 4
1349: ENTITY_REFERENCE_NODE = 5
1350: ENTITY_NODE = 6
1351: PROCESSING_INSTRUCTION_NODE = 7
1352: COMMENT_NODE = 8
1353: DOCUMENT_NODE = 9
1354: DOCUMENT_TYPE_NODE = 10
1355: DOCUMENT_FRAGMENT_NODE = 11
1356: NOTATION_NODE = 12
1.1 paf 1357: $vasyaNode.type==$xnode:ELEMENT_NODE
1.253 moko 1358: $node.parentNode
1359: $node.childNodes = array of nodes
1360: $node.firstChild
1361: $node.lastChild
1362: $node.previousSibling
1363: $node.nextSibling
1364: $node.ownerDocument = xdoc
1365: $node.prefix
1366: $node.namespaceURI
1367: $element_node.attributes = hash of xnodes
1368: $element_node.tagName
1369: $attribute_node.specified = boolean
1370: true if the attribute received its value explicitly in the XML document,
1.259 moko 1371: or if a value was assigned programmatically with the setValue function.
1.253 moko 1372: false if the attribute value came from the default value declared in the document's DTD.
1373: $attribute_node.name
1374: $attribute_node.value
1.1 paf 1375: $text_node/cdata_node/comment_node.substringData
1.253 moko 1376: $pi_node.target = target of this processing instruction
1.259 moko 1377: XML defines this as the first token following the markup
1.1 paf 1378: that begins the processing instruction.
1.253 moko 1379: $pi_node.data = The content of this processing instruction
1.259 moko 1380: From the first non-whitespace character after the target
1.253 moko 1381: to the character immediately preceding the ?>.
1.1 paf 1382: document_node.
1383: readonly attribute DocumentType doctype
1.253 moko 1384: readonly attribute DOMImplementation implementation
1.1 paf 1385: readonly attribute Element documentElement
1386: document_type_node.
1.253 moko 1387: readonly attribute DOMString name
1.1 paf 1388: readonly attribute NamedNodeMap entities
1389: readonly attribute NamedNodeMap notations
1.253 moko 1390: notation_node.
1391: readonly attribute DOMString publicId
1392: readonly attribute DOMString systemId
1393:
1394: DOM1 node methods:
1395: Node insertBefore(in Node newChild,in Node refChild)
1396: Node replaceChild(in Node newChild,in Node oldChild)
1397: Node removeChild(in Node oldChild)
1398: Node appendChild(in Node newChild)
1399: boolean hasChildNodes()
1400: Node cloneNode(in boolean deep)
1401:
1402: DOM1 element methods:
1403: DOMString getAttribute(in DOMString name)
1404: void setAttribute(in DOMString name, in DOMString value) raises(DOMException)
1405: void removeAttribute(in DOMString name) raises(DOMException)
1406: Attr getAttributeNode(in DOMString name)
1407: Attr setAttributeNode(in Attr newAttr) raises(DOMException)
1408: Attr removeAttributeNode(in Attr oldAttr) raises(DOMException)
1409: NodeList getElementsByTagName(in DOMString name)
1410: void normalize()
1411:
1412: Introduced in DOM Level 2:
1413: Node importNode(in Node importedNode, in boolean deep) raises(DOMException)
1414: NodeList getElementsByTagNameNS(in DOMString namespaceURI, in DOMString localName)
1415: boolean hasAttributes()
1.1 paf 1416:
1.253 moko 1417: XPath:
1.260 moko 1418: ^node.select[xpath/query/expression] = array of nodes,
1.21 paf 1419: empty array if nothing found
1.253 moko 1420: ^node.selectSingle[xpath/query/expression] = first node if any
1421: ^node.selectBool[xpath/query/expression] = bool if any or die
1422: ^node.selectNumber[xpath/query/expression] = double if any or die
1423: ^node.selectString[xpath/query/expression] = string if any or die
1.1 paf 1424:
1.176 paf 1425: DATA::=string | file | hash
1.260 moko 1426: hash of the form
1.253 moko 1427: [
1.260 moko 1428: $.file[filename on disk]
1429: $.name[filename for user]
1.253 moko 1430: $.mdate[date]
1431: ]
1432:
1433: MAIN
1.260 moko 1434: this is the class automatically loaded from the configuration auto.p, a bunch of auto.p and the requested document:
1435: configuration auto.p
1.253 moko 1436: cgi:
1.260 moko 1437: 1. either full path from environment variable CGI_PARSER_SITE_CONFIG or next to parser binary
1.1 paf 1438: isapi: windows directory
1.253 moko 1439: apache module:
1.43 paf 1440: 1) ParserConfig [can be in .htaccess]
1.260 moko 1441: auto.p goes down from DOCUMENT_ROOT/ through the directory tree to the directory of the processed file, inclusive
1442: the class is assembled from all these files, subsequent ones become parents of the previous ones
1443: the name of the last loaded is MAIN, previous ones have no names
1444:
1445: after loading MAIN class, its @main[] is called
1446: the result is passed to its @postprocess[data] if($data is string) ...
1447: the result is then returned to the user
1.253 moko 1448:
1.260 moko 1449: if an error occurs and try is not specified, it can be nicely reported to the user by defining
1.253 moko 1450: @unhandled_exception[exception;stack]
1.260 moko 1451: $exception.type string "type of problem"
1452: $exception.file $exception.lineno $exception.colno file, line and position where the problem occurred [if not disabled at compile time]
1453: $exception.source line that caused the problem
1454: $exception.comment English comment
1455: stack table with columns file line name,
1456: in reverse order the names[name] and places[file line] of the operators/methods that caused the error.
1.253 moko 1457:
1.260 moko 1458: when loading a file (file::load, table::load, xdoc::load) you can specify such a filename:
1.253 moko 1459: http://domain/document[?params<<deprecated, use $.form[...]]
1.260 moko 1460: and possibly specify options:
1.253 moko 1461: $.method[GET|POST|HEAD]
1.260 moko 1462: $.timeout(3) << in seconds, default=2
1.253 moko 1463: $.cookies[
1.260 moko 1464: $.name[value]
1.253 moko 1465: ]
1466: $.headers[
1.260 moko 1467: $.field[value] << value format like $response:HEADER
1.253 moko 1468: ]
1.166 paf 1469: $.enctype[multipart/form-data]
1470: $.form[
1.253 moko 1471: $.field1[string]
1472: $.field2[^table::create{one_column_only^#0Avalue1^#0Avalue2}]
1.166 paf 1473: $.field3[file]
1474: ]
1.253 moko 1475: $.body[string|file]
1.260 moko 1476: default user-agent=parser3
1477: by default, getting http status != 200 >> creates http.status error, can be disabled by $.any-status(1)
1478: $.charset[default encoding of remote documents], if server returns content-type:charset - IT OVERRIDES
1479: $.response-charset[encoding of remote documents], not overridden by content-type:charset
1480: $.user[user]
1481: $.password[password]
1482: file::load writes additional fields
1483: FIELD:value (response field names in uppercase)
1484: tables << a hash of FIELD->table with a single column "value"
1485: in such tables you can get repeating headers, e.g. multiple set-cookies
1486: todo: make separate cookies
1487:
1488: system error types:
1489: parser.compile ^test[} compilation (unmatched bracket, ...)
1490: parser.runtime ^if(0). parameters (more/less than needed, wrong types, ...)
1.253 moko 1491: number.zerodivision ^eval(1/0) ^eval(1%0)
1492: number.format ^eval(abc*5)
1493: file.lock shared/exclusive lock error
1494: file.missing ^file:delete[delme] not found
1495: file.access ^table::load[.] no rights
1496: file.read ^file::load[...] error while reading file
1497: file.seek seek failed
1498: file.execute ^file::cgi[...] incorrect cgi header/can't execute
1499: image.format ^image::measure[index.html] not gif/jpg
1500: sql.connect ^connect[mysql://baduser:pass@host/db]{} not found/timeout
1501: sql.execute ^void:sql{select bad} syntax error
1.57 paf 1502: sql.duplicate
1503: sql.access
1504: sql.missing
1.253 moko 1505: xml ^xdoc::create{<forgot?>} any error in xml/xslt libs
1506: smtp.connect not found/timeout
1507: smtp.execute communication error
1.259 moko 1508: email.format hren tam@null.ru wrong email format (bad chars/empty)
1.253 moko 1509: email.send $MAIL.sendmail[/shit] sendmail not executable
1510: http.host ^file::load[http://notfound/there] host not found
1.259 moko 1511: http.connect ^file::load[http://not_accepting/there] host found, but does not accept connections
1512: http.timeout ^file::load[http://host/doc] load operation failed to complete in # seconds
1.253 moko 1513: http.response ^file::load[http://ok/there] host found, connection accepted, bad answer
1514: http.status ^file::load[http://ok/there] host found, connection accepted, status!=200
1515: date.range ^date::create(10000;1;1) date out of valid range
1.273 moko 1516: amqp ^amqp::create[$.port(1)] connection failed/error from the broker
1517: redis ^redis::open[$.port(1)] connection failed/error reply
1.213 misha 1518:
1.260 moko 1519: if the method description explicitly contains the local variable result (there is also an implicit variable),
1520: then the code for outputting whitespace literals does not get into the final bytecode
1.261 moko 1521:
1.279 ! moko 1522: $Id: operators.txt,v 1.278 2026/11/25 23:10:11 moko Exp $
E-mail: