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