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