| 1 | #charset "us-ascii" |
| 2 | #pragma once |
| 3 | |
| 4 | /* |
| 5 | * Copyright 2000, 2006 Michael J. Roberts. |
| 6 | * |
| 7 | * This file is part of TADS 3. |
| 8 | * |
| 9 | * This module defines the fundamental intrinsic classes, including Object, |
| 10 | * String, Collection, List, and Iterator. |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | /* ------------------------------------------------------------------------ */ |
| 15 | /* |
| 16 | * TADS datatype codes. These values are returned by propType(), etc. |
| 17 | */ |
| 18 | #define TypeNil 1 |
| 19 | #define TypeTrue 2 |
| 20 | #define TypeObject 5 |
| 21 | #define TypeProp 6 |
| 22 | #define TypeInt 7 |
| 23 | #define TypeSString 8 |
| 24 | #define TypeDString 9 |
| 25 | #define TypeList 10 |
| 26 | #define TypeCode 11 |
| 27 | #define TypeFuncPtr 12 |
| 28 | #define TypeNativeCode 14 |
| 29 | #define TypeEnum 15 |
| 30 | #define TypeBifPtr 16 |
| 31 | |
| 32 | |
| 33 | /* ------------------------------------------------------------------------ */ |
| 34 | /* |
| 35 | * The root object class. All objects descend from this class. |
| 36 | */ |
| 37 | intrinsic class Object 'root-object/030004' |
| 38 | { |
| 39 | /* |
| 40 | * Determine if I'm an instance or subclass of the given class 'cls'. |
| 41 | * Note that x.ofKind(x) returns true - an object is of its own kind. |
| 42 | */ |
| 43 | ofKind(cls); |
| 44 | |
| 45 | /* get the list of direct superclasses of this object */ |
| 46 | getSuperclassList(); |
| 47 | |
| 48 | /* determine if a property is defined or inherited by this object */ |
| 49 | propDefined(prop, flags?); |
| 50 | |
| 51 | /* get the type of a property defined for this object */ |
| 52 | propType(prop); |
| 53 | |
| 54 | /* |
| 55 | * Get a list of my directly-defined properties. When called on |
| 56 | * intrinsic class objects, this returns a list of properties defined |
| 57 | * for instances of the class, as well as static properties of the |
| 58 | * class. |
| 59 | */ |
| 60 | getPropList(); |
| 61 | |
| 62 | /* |
| 63 | * get parameter list information for the given method - returns a |
| 64 | * list: [minimumArgc, optionalArgc, varargs], where minimumArgc is |
| 65 | * the minimum number of arguments, optionalArgc is the number of |
| 66 | * additional optional arguments, and varargs is true if the function |
| 67 | * takes a varying number of arguments greater than or equal to the |
| 68 | * minimum, nil if not. |
| 69 | */ |
| 70 | getPropParams(prop); |
| 71 | |
| 72 | /* |
| 73 | * determine if I'm a "class" object - returns true if the object was |
| 74 | * defined with the "class" keyword, nil otherwise |
| 75 | */ |
| 76 | isClass(); |
| 77 | |
| 78 | /* |
| 79 | * Determine if a property is inherited further from the given object. |
| 80 | * definingObj is usually the value of the 'definingobj' |
| 81 | * pseudo-variable, and origTargetObj is usually the value of the |
| 82 | * 'targetobj' pseudo-variable. |
| 83 | */ |
| 84 | propInherited(prop, origTargetObj, definingObj, flags?); |
| 85 | |
| 86 | /* determine if this instance is transient */ |
| 87 | isTransient(); |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * propDefined() flags |
| 92 | */ |
| 93 | #define PropDefAny 1 |
| 94 | #define PropDefDirectly 2 |
| 95 | #define PropDefInherits 3 |
| 96 | #define PropDefGetClass 4 |
| 97 | |
| 98 | /* export the objToString method */ |
| 99 | property objToString; |
| 100 | export objToString 'objToString'; |
| 101 | |
| 102 | |
| 103 | /* ------------------------------------------------------------------------ */ |
| 104 | /* |
| 105 | * The IntrinsicClass intrinsic class. Objects of this type represent the |
| 106 | * intrinsic classes themselves. |
| 107 | */ |
| 108 | intrinsic class IntrinsicClass 'intrinsic-class/030001': Object |
| 109 | { |
| 110 | /* |
| 111 | * Class method: is the given value an IntrinsicClass object? This |
| 112 | * returns true if so, nil if not. |
| 113 | * |
| 114 | * It's not possible to determine if an object is an IntrinsicClass |
| 115 | * object using x.ofKind(IntrinsicClass) or via x.getSuperclassList(). |
| 116 | * This is because those methods traverse the nominal class tree: |
| 117 | * [1,2,3] is a List, and List is an Object. However, List and Object |
| 118 | * themselves are represented by IntrinsicClass instances, and it's |
| 119 | * occasionally useful to know if you're dealing with such an object. |
| 120 | * That's where this method comes in. |
| 121 | * |
| 122 | * This method returns nil for instances of an intrinsic class. For |
| 123 | * example, isIntrinsicClass([1,2,3]) returns nil, because [1,2,3] is a |
| 124 | * List instance. If you get the superclass list for [1,2,3], though, |
| 125 | * that will be [List], and isIntrinsicClass(List) returns true. |
| 126 | */ |
| 127 | isIntrinsicClass(obj); |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Intrinsic class modifier object (for internal compiler use only) |
| 132 | */ |
| 133 | intrinsic class IntrinsicClassModifier 'int-class-mod/030000' |
| 134 | { |
| 135 | } |
| 136 | |
| 137 | /* ------------------------------------------------------------------------ */ |
| 138 | /* |
| 139 | * The native collection type - this is the base class for lists, vectors, |
| 140 | * and other objects that represent collections of values. |
| 141 | */ |
| 142 | intrinsic class Collection 'collection/030000': Object |
| 143 | { |
| 144 | /* |
| 145 | * Create an iterator for the collection. This returns a new Iterator |
| 146 | * object that can be used to iterate over the values in the |
| 147 | * collection. The Iterator will use a snapshot of the collection that |
| 148 | * will never change, even if the collection is changed after the |
| 149 | * iterator is created. |
| 150 | */ |
| 151 | createIterator(); |
| 152 | |
| 153 | /* |
| 154 | * Create a "live iterator" for the collection. This returns a new |
| 155 | * Iterator object that refers directly to the original collection; if |
| 156 | * the original collection changes, the iterator will reflect the |
| 157 | * changes in its iteration. As a result, the iterator is not |
| 158 | * guaranteed to visit all of the elements in the collection if the |
| 159 | * collection changes during the course of the iteration. If |
| 160 | * consistent results are required, use createIterator() instead. |
| 161 | */ |
| 162 | createLiveIterator(); |
| 163 | } |
| 164 | |
| 165 | /* ------------------------------------------------------------------------ */ |
| 166 | /* |
| 167 | * The native iterator type - this is the base class for all iterators. |
| 168 | * This class is abstract and is thus never directly instantiated. |
| 169 | * |
| 170 | * Note that iterators can never be created directly with the 'new' |
| 171 | * operator. Instead, iterators must be obtained from a collection via the |
| 172 | * collection's createIterator() method. |
| 173 | */ |
| 174 | intrinsic class Iterator 'iterator/030001': Object |
| 175 | { |
| 176 | /* |
| 177 | * Get the next item in the collection. This returns the next item's |
| 178 | * value, and advances the internal state in the iterator so that a |
| 179 | * subsequent call to getNext() returns the next item after this one. |
| 180 | * When the iterator is first created, or after calling |
| 181 | * resetIterator(), this returns the first item in the collection. |
| 182 | */ |
| 183 | getNext(); |
| 184 | |
| 185 | /* |
| 186 | * Determine if the collection is out of items. Returns true if |
| 187 | * getNext() will return a valid item, nil if no more items are |
| 188 | * available. |
| 189 | */ |
| 190 | isNextAvailable(); |
| 191 | |
| 192 | /* |
| 193 | * Reset to the first item. After calling this routine, the next call |
| 194 | * to getNext() will return the first item in the collection. |
| 195 | */ |
| 196 | resetIterator(); |
| 197 | |
| 198 | /* |
| 199 | * Get the current key. This returns the value of the key for the |
| 200 | * current item in the collection. For an indexed collection, this |
| 201 | * returns the index value; for a keyed collection, this returns the |
| 202 | * current key value. |
| 203 | */ |
| 204 | getCurKey(); |
| 205 | |
| 206 | /* |
| 207 | * Get the current value. This returns the value of the current item |
| 208 | * in the collection. |
| 209 | */ |
| 210 | getCurVal(); |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * Indexed object iterator - this type of iterator is used for lists, |
| 215 | * vectors, and other indexed collection objects. |
| 216 | */ |
| 217 | intrinsic class IndexedIterator 'indexed-iterator/030000': Iterator |
| 218 | { |
| 219 | } |
| 220 | |
| 221 | |
| 222 | /* ------------------------------------------------------------------------ */ |
| 223 | /* |
| 224 | * AnonFuncPtr depends on Vector |
| 225 | */ |
| 226 | #include "vector.h" |
| 227 | |
| 228 | /* |
| 229 | * Anonymous function pointer intrinsic class |
| 230 | */ |
| 231 | intrinsic class AnonFuncPtr 'anon-func-ptr': Vector |
| 232 | { |
| 233 | } |
| 234 | |
| 235 | |
| 236 | /* ------------------------------------------------------------------------ */ |
| 237 | /* |
| 238 | * The "TADS Object" intrinsic class. All objects that the program |
| 239 | * defines with the "class" or "object" statements descend from this |
| 240 | * class. |
| 241 | */ |
| 242 | intrinsic class TadsObject 'tads-object/030005': Object |
| 243 | { |
| 244 | /* |
| 245 | * Create an instance of this object: in other words, create a new |
| 246 | * object whose superclass is this object. The arguments provided are |
| 247 | * passed to the new object's constructor. This method returns a |
| 248 | * reference to the new object. |
| 249 | */ |
| 250 | createInstance(...); |
| 251 | |
| 252 | /* |
| 253 | * Create a clone of this object. This creates an exact copy, with |
| 254 | * the same property values, as the original. This does not call any |
| 255 | * constructors; it merely instantiates an exact copy of the original. |
| 256 | * |
| 257 | * Note that the clone is a "shallow" copy, which means that any |
| 258 | * objects it references are not themselves cloned. |
| 259 | */ |
| 260 | createClone(); |
| 261 | |
| 262 | /* |
| 263 | * Create a transient instance of this object. This works just like |
| 264 | * createInstance(), but creates a transient instance instead of an |
| 265 | * ordinary (persistent) instance. |
| 266 | */ |
| 267 | createTransientInstance(...); |
| 268 | |
| 269 | /* |
| 270 | * Create an instance of an object based on multiple superclasses. |
| 271 | * Each argument gives a superclass, and optionally arguments for |
| 272 | * invoking the superclass constructor. If an argument is given as |
| 273 | * simply a class, then we don't invoke that superclass's constructor; |
| 274 | * if the argument is given as a list, the first element of the list is |
| 275 | * the class, and the remaining elements of the list are arguments for |
| 276 | * that superclass's constructor. The arguments are specified in the |
| 277 | * same order they would be to define the object, so the first argument |
| 278 | * is the dominant superclass. |
| 279 | * |
| 280 | * For example, suppose we created a class definition like this: |
| 281 | * |
| 282 | * class D: A, B, C |
| 283 | *. construct(x, y) |
| 284 | *. { |
| 285 | *. inherited A(x); |
| 286 | *. inherited C(y); |
| 287 | *. } |
| 288 | *. ; |
| 289 | * |
| 290 | * We could obtain the same effect dynamically like so: |
| 291 | * |
| 292 | * local d = TadsObject.createInstanceOf([A, x], B, [C, y]); |
| 293 | * |
| 294 | * Note that only *actual* lists are interpreted as constructor |
| 295 | * invokers here. A list-like object (with operator[] and length() |
| 296 | * methods) will be treated as a simple superclass, since otherwise it |
| 297 | * wouldn't be possible to specify the no-constructor format for such a |
| 298 | * superclass. |
| 299 | */ |
| 300 | static createInstanceOf(...); |
| 301 | |
| 302 | /* |
| 303 | * Create a transient instance based on multiple superclasses. This |
| 304 | * works just like createInstanceOf(), but creates a transient |
| 305 | * instance. |
| 306 | */ |
| 307 | static createTransientInstanceOf(...); |
| 308 | |
| 309 | /* |
| 310 | * Set the superclass list. scList is a list giving the new |
| 311 | * superclasses. The superclasses must all be TadsObject objects, with |
| 312 | * one exception: the list [TadsObject] may be passed to create an |
| 313 | * object based directly on TadsObject. No other intrinsic classes can |
| 314 | * be used in the list, and objects of other types cannot be used in |
| 315 | * the list. |
| 316 | */ |
| 317 | setSuperclassList(scList); |
| 318 | |
| 319 | /* |
| 320 | * Get a method value. If the property is a method, this returns a |
| 321 | * function pointer to the method; this does NOT evaluate the method. |
| 322 | * If the property is not a method, this returns nil. |
| 323 | * |
| 324 | * The returned function pointer can be called like an ordinary |
| 325 | * function, but such a call will have no 'self' value, so the |
| 326 | * disembodied method won't be able to refer to properties or methods |
| 327 | * of 'self'. The main use of this method is to get a method of one |
| 328 | * object to assign as a method of another object using setMethod(). |
| 329 | */ |
| 330 | getMethod(prop); |
| 331 | |
| 332 | /* |
| 333 | * Set a method value. Assigns the given function (which must be a |
| 334 | * function pointer value) to the given property of 'self'. This |
| 335 | * effectively adds a new method to the object. |
| 336 | * |
| 337 | * The function can be an ordinary named function, or a method pointer |
| 338 | * retrieved from this object or from another object with getMethod(). |
| 339 | * Anonymous functions are NOT allowed here. |
| 340 | */ |
| 341 | setMethod(prop, func); |
| 342 | } |
| 343 | |
| 344 | |
| 345 | /* ------------------------------------------------------------------------ */ |
| 346 | /* |
| 347 | * We need CharacterSet and ByteArray (for String.mapToByteArray). (But |
| 348 | * wait to include these until after we've defined Object, since everything |
| 349 | * depends on Object.) |
| 350 | */ |
| 351 | #include "charset.h" |
| 352 | #include "bytearr.h" |
| 353 | |
| 354 | /* ------------------------------------------------------------------------ */ |
| 355 | /* |
| 356 | * The native string type. |
| 357 | */ |
| 358 | intrinsic class String 'string/030008': Object |
| 359 | { |
| 360 | /* get the length of the string */ |
| 361 | length(); |
| 362 | |
| 363 | /* extract a substring */ |
| 364 | substr(start, len?); |
| 365 | |
| 366 | /* convert to upper case */ |
| 367 | toUpper(); |
| 368 | |
| 369 | /* convert to lower case */ |
| 370 | toLower(); |
| 371 | |
| 372 | /* |
| 373 | * Find a substring or pattern within the subject string (self), |
| 374 | * searching the string from left to right returning the index of the |
| 375 | * first match found. If 'str' is a string, this searches for an exact |
| 376 | * match to the substring. If 'str' is a RexPattern object, this |
| 377 | * searches for a match to the pattern. Returns the character index of |
| 378 | * the start of the match if found (the first character is at index 1), |
| 379 | * or nil if no match is found. |
| 380 | * |
| 381 | * 'index' is the optional starting index for the search. the first |
| 382 | * character is at index 1; a negative index specifies an offset from |
| 383 | * the end of the string, with -1 indicating the last character, -2 the |
| 384 | * second to last, and so on. If 'index' is omitted, the search starts |
| 385 | * at the first character. Note that the search proceeds from left to |
| 386 | * right even if 'index' is negative - a negative starting index is |
| 387 | * just a convenience to specify an offset from the end of the string, |
| 388 | * but the search still proceeds in the same direction. |
| 389 | * |
| 390 | * (Note: "left to right" in this context simply means from lower to |
| 391 | * higher character index in the string. We're using the term loosely, |
| 392 | * in particular ignoring anything related to the reading order or |
| 393 | * display direction for different languages or scripts.) |
| 394 | */ |
| 395 | find(str, index?); |
| 396 | |
| 397 | /* |
| 398 | * convert to a list of Unicode character codes, or get the Unicode |
| 399 | * character code for the single character at the given index |
| 400 | */ |
| 401 | toUnicode(idx?); |
| 402 | |
| 403 | /* htmlify a string */ |
| 404 | htmlify(flags?); |
| 405 | |
| 406 | /* determine if we start with the given string */ |
| 407 | startsWith(str); |
| 408 | |
| 409 | /* determine if we end with the given string */ |
| 410 | endsWith(str); |
| 411 | |
| 412 | /* |
| 413 | * Map to a byte array, converting to the given character set. If |
| 414 | * 'charset' is provided, it must be an object of intrinsic class |
| 415 | * CharacterSet, or a string giving the name of a character set. The |
| 416 | * characters in the string are mapped from the internal Unicode |
| 417 | * representation to the appropriate byte representation in the given |
| 418 | * character set. Any unmappable characters are replaced with the |
| 419 | * usual default/missing character for the set, as defined by the |
| 420 | * mapping. |
| 421 | * |
| 422 | * If 'charset' is omitted or nil, the byte array is created simply by |
| 423 | * treating the Unicode character code of each character in the string |
| 424 | * as a byte value. A byte can only hold values from 0 to 255, so a |
| 425 | * numeric overflow error is thrown if any character code in the source |
| 426 | * string is outside this range. |
| 427 | * |
| 428 | */ |
| 429 | mapToByteArray(charset?); |
| 430 | |
| 431 | /* |
| 432 | * Replace one occurrence or all occurrences of the given substring |
| 433 | * with the given new string. |
| 434 | * |
| 435 | * 'self' is the subject string, which we search for instances of the |
| 436 | * replacement. |
| 437 | * |
| 438 | * 'origStr' is the string to search for within 'self'. This is |
| 439 | * treated as a literal text substring to find within 'self'. |
| 440 | * 'origStr' can alternatively be a RexPattern object, in which case |
| 441 | * the regular expression is matched. |
| 442 | * |
| 443 | * 'newStr' is the replacement text, as a string. 'newStr' can |
| 444 | * alternatively be a function (regular or anonymous) instead of a |
| 445 | * string. In this case, it's invoked as 'newStr(match, index, orig)' |
| 446 | * for each match where 'match' is the matching text, 'index' is the |
| 447 | * index within the original subject string of the match, and 'orig' is |
| 448 | * the full original subject string. This function must return a |
| 449 | * string value, which is used as the replacement text. Using a |
| 450 | * function allows greater flexibility in specifying the replacement, |
| 451 | * since it can vary the replacement according to the actual text |
| 452 | * matched and its position in the subject string. |
| 453 | * |
| 454 | * 'flags' is a combination of ReplaceXxx flags specifying the search |
| 455 | * options. It's optional; if omitted, the default is ReplaceAll. |
| 456 | * |
| 457 | * ReplaceOnce and ReplaceAll are mutually exclusive; they mean, |
| 458 | * respectively, that only the first occurrence of the match should be |
| 459 | * replaced, or that every occurrence should be replaced. ReplaceOnce |
| 460 | * and ReplaceAll are ignored if a 'limit' value is specified (this is |
| 461 | * true even if 'limit' is nil, which means that all occurrences are |
| 462 | * replaced). |
| 463 | * |
| 464 | * 'index' is the starting index within 'self' for the search. If this |
| 465 | * is given, we'll ignore any matches that start before the starting |
| 466 | * index. If 'index' is omitted, we start the search at the beginning |
| 467 | * of the string. If 'index' is negative, it's an index from the end |
| 468 | * of the string: -1 is the last character, -2 the second to last, etc. |
| 469 | * |
| 470 | * 'origStr' can be given as a list of search strings, rather than a |
| 471 | * single string. In this case, we'll search for each of the strings |
| 472 | * in the list, and replace each one with 'newStr'. If 'newStr' is |
| 473 | * also a list, each match to an element of the 'origStr' list is |
| 474 | * replaced with the corresponding element (at the same index) of the |
| 475 | * 'newStr' list. If there are more 'origStr' elements than 'newStr' |
| 476 | * elements, each match to an excess 'origStr' element is replaced with |
| 477 | * an empty string. This allows you to perform several replacements |
| 478 | * with a single call. |
| 479 | * |
| 480 | * 'limit', if specified, is an integer indicating the maximum number |
| 481 | * of matches to replace, or nil to replace all matches. If the limit |
| 482 | * is reached before all matches have been replaced, no further |
| 483 | * replacements are performed. If this parameter is specified, it |
| 484 | * overrides any ReplaceOnce or ReplaceAll flag. |
| 485 | * |
| 486 | * There are two search modes when 'origStr' is a list. The default is |
| 487 | * "parallel" mode. In this mode, we search for all of the 'origStr' |
| 488 | * elements, and replace the leftmost match. We then search the |
| 489 | * remainder of the string, after this first match, again searching for |
| 490 | * all of the 'origStr' elements. Again we replace the leftmost match. |
| 491 | * We repeat this until we run out of matches. |
| 492 | * |
| 493 | * The other option is "serial" mode, which you select by including |
| 494 | * ReplaceSerial in the flags argument. In serial mode, we start by |
| 495 | * searching only for the first 'origStr' element. We replace each |
| 496 | * occurrence throughout the string (unless we're in ReplaceOnce mode, |
| 497 | * in which case we stop after the first replacement). If we're in |
| 498 | * ReplaceOnce mode and we did a replacement, we're done. Otherwise, |
| 499 | * we start over with the updated string, containing the replacements |
| 500 | * so far, and search it for the second 'origStr' element, replacing |
| 501 | * each occurrence (or just the first, in ReplaceOnce mode). We repeat |
| 502 | * this for each 'origStr' element. |
| 503 | * |
| 504 | * The key difference between the serial and parallel modes is that the |
| 505 | * serial mode re-scans the updated string after replacing each |
| 506 | * 'origStr' element, so replacement text could itself be further |
| 507 | * modified. Parallel mode, in contrast, never re-scans replacement |
| 508 | * text. |
| 509 | */ |
| 510 | findReplace(origStr, newStr, flags?, index?, limit?); |
| 511 | |
| 512 | /* |
| 513 | * Splice: delete 'del' characters starting at 'idx', and insert the |
| 514 | * string 'ins' in their place. 'ins' is optional; if omitted, this |
| 515 | * simply does the deletion without inserting anything. |
| 516 | */ |
| 517 | splice(idx, del, ins?); |
| 518 | |
| 519 | /* |
| 520 | * Split the string into substrings at the given delimiter, or of a |
| 521 | * given fixed length. |
| 522 | * |
| 523 | * 'delim' is the delimiter. It can be one of the following: |
| 524 | * |
| 525 | * - A string or RexPattern, giving the delimiter where we split the |
| 526 | * string. We search 'self' for matches to this string or pattern, and |
| 527 | * split it at each instance we find, returning a list of the resulting |
| 528 | * substrings. For example, 'one,two,three'.split(',') returns the |
| 529 | * list ['one', 'two', 'three']. The delimiter separates parts, so |
| 530 | * it's not part of the returned substrings. |
| 531 | * |
| 532 | * - An integer, giving a substring length. We split the string into |
| 533 | * substrings of this exact length (except that the last element will |
| 534 | * have whatever's left over). For example, 'abcdefg'.split(2) returns |
| 535 | * ['ab', 'cd', 'ef', 'g']. |
| 536 | * |
| 537 | * If 'delim' is omitted or nil, the default is 1, so we'll split the |
| 538 | * string into one-character substrings. |
| 539 | * |
| 540 | * If 'limit' is included, it's an integer giving the maximum number of |
| 541 | * elements to return in the result list. If we reach the limit, we'll |
| 542 | * stop the search and return the entire rest of the string as the last |
| 543 | * element of the result list. If 'limit' is 1, we simply return a |
| 544 | * list consisting of the source string, since a limit of one element |
| 545 | * means that we can't make any splits at all. |
| 546 | */ |
| 547 | split(delim?, limit?); |
| 548 | |
| 549 | /* |
| 550 | * Convert special characters and TADS markups to standard HTML |
| 551 | * markups. Returns a new string with the contents of the 'self' |
| 552 | * string processed as described below. |
| 553 | * |
| 554 | * 'stateobj' is an object containing the state of the output stream. |
| 555 | * This allows an output stream to process its contents a bit at a |
| 556 | * time, by maintaining the state of the stream from one call to the |
| 557 | * next. This object gives the prior state of the stream on entry, and |
| 558 | * is updated on return to contain the new state after processing this |
| 559 | * string. If this is omitted or nil, a default initial starting state |
| 560 | * is used. The function uses the following properties of the object: |
| 561 | * |
| 562 | * stateobj.flags_ is an integer with a collection of flag bits giving |
| 563 | * the current line state |
| 564 | * |
| 565 | * stateobj.tag_ is a string containing the text of the tag currently |
| 566 | * in progress. If the string ends in the middle of a tag, this will |
| 567 | * be set on return to the text of the tag up to the end of the string, |
| 568 | * so that the next call can resume processing the tag where the last |
| 569 | * call left off. |
| 570 | * |
| 571 | * |
| 572 | * The function makes the following conversions: |
| 573 | * |
| 574 | * \n -> <BR>, or nothing at the start of a line |
| 575 | * |
| 576 | * \b -> <BR> at the start of a line, or <BR><BR> within a line |
| 577 | * |
| 578 | * \ (quoted space) -> if followed by a space or another quoted |
| 579 | * space, or an ordinary space if followed by a non-space character |
| 580 | * |
| 581 | * \t -> a sequence of characters followed by a space, padding |
| 582 | * to the next 8-character tab stop. This can't take into account the |
| 583 | * font metrics, since that's determined by the browser, so it should |
| 584 | * only be used with a monospaced font. |
| 585 | * |
| 586 | * \^ -> sets an internal flag to capitalize the next character |
| 587 | * |
| 588 | * \v -> sets an internal flag to lower-case the next character |
| 589 | * |
| 590 | * <Q> ... </Q> -> “ ... ” or ‘ ... ’, |
| 591 | * depending on the nesting level |
| 592 | * |
| 593 | * <BR HEIGHT=N> -> N <BR> tags if at the start of a line, N+1 <BR> |
| 594 | * tags if within a line |
| 595 | * |
| 596 | * |
| 597 | * Note that this isn't a general-purpose HTML corrector: it doesn't |
| 598 | * correct ill-formed markups or standardize deprecated syntax or |
| 599 | * browser-specific syntax. This function is specifically for |
| 600 | * standardizing TADS-specific syntax, so that games can use the |
| 601 | * traditional TADS syntax with the Web UI. |
| 602 | */ |
| 603 | specialsToHtml(stateobj?); |
| 604 | |
| 605 | /* |
| 606 | * Convert special characters and HTML markups to plain text, as it |
| 607 | * would appear if written out through the regular console output |
| 608 | * writer and displayed on a plain text terminal. Returns a new string |
| 609 | * with the contents of the 'self' string processed as described below. |
| 610 | * This works very much like specialsToHtml(), but rather than |
| 611 | * generating standard HTML output, we generate plain text output. |
| 612 | * |
| 613 | * 'stateobj' has the same meaning asin specialsToHtml(). |
| 614 | * |
| 615 | * The function makes the following conversions: |
| 616 | * |
| 617 | * \n -> \n, or nothing at the start of a line |
| 618 | * |
| 619 | * \b -> \n at the start of a line, or \n\n within a line |
| 620 | * |
| 621 | * \ (quoted space) -> regular space |
| 622 | * |
| 623 | * \^ -> sets an internal flag to capitalize the next character |
| 624 | * |
| 625 | * \v -> sets an internal flag to lower-case the next character |
| 626 | * |
| 627 | * <Q> ... </Q> -> "..." or '...' depending on the quote nesting level |
| 628 | * |
| 629 | * <BR HEIGHT=n> -> N \n characters at the start of a line, N+1 \n |
| 630 | * characters within a line |
| 631 | * |
| 632 | * <P> -> \n at the start of a line, \n\n within a line |
| 633 | * |
| 634 | * <TAG> -> nothing for all other tags |
| 635 | * |
| 636 | * & -> & |
| 637 | * |
| 638 | * < -> < |
| 639 | * |
| 640 | * > -> > |
| 641 | * |
| 642 | * " -> " |
| 643 | * |
| 644 | * “ and ” -> " |
| 645 | * |
| 646 | * ‘ and ’ -> ' |
| 647 | * |
| 648 | * &#dddd; -> Unicode character dddd |
| 649 | */ |
| 650 | specialsToText(stateobj?); |
| 651 | |
| 652 | /* |
| 653 | * Encode a URL parameter string. Spaces are encoded as "+", and all |
| 654 | * other non-alphanumeric characters except - and _ are encoded as |
| 655 | * "%xx" sequences. |
| 656 | */ |
| 657 | urlEncode(); |
| 658 | |
| 659 | /* |
| 660 | * Decode a URL parameter string. This reverses the effect of |
| 661 | * urlEncode(), returning a string with the encodings translated back |
| 662 | * into ordinary characters. Any sequences that do not form valid |
| 663 | * UTF-8 characters are converted to '?'. |
| 664 | */ |
| 665 | urlDecode(); |
| 666 | |
| 667 | /* |
| 668 | * Get the SHA-256 hash of the string. This calculates the 256-bit |
| 669 | * Secure Hash Algorithm 2 hash value, returning the hash as a |
| 670 | * 64-character string of hex digits. The hash value is computed on |
| 671 | * the UTF-8 representation of the string. |
| 672 | */ |
| 673 | sha256(); |
| 674 | |
| 675 | /* |
| 676 | * Get the MD5 digest of the string. This calculates the 128-bit RSA |
| 677 | * MD5 digest value, returning the digest as a 32-character string of |
| 678 | * hex digits. The hash value is computed on the UTF-8 representation |
| 679 | * of the string. |
| 680 | */ |
| 681 | digestMD5(); |
| 682 | |
| 683 | /* |
| 684 | * Pack the arguments into bytes, and create a new string from the byte |
| 685 | * values. The characters of the new string correspond to the packed |
| 686 | * byte values, so each character will have a Unicode character number |
| 687 | * from 0 to 255. |
| 688 | * |
| 689 | * 'format' is a format string describing the packed formats for the |
| 690 | * values, and the rest of the arguments are the values to pack into |
| 691 | * the string. Returns a string containing the packed bytes. |
| 692 | * |
| 693 | * See Byte Packing in the System Manual for more details. |
| 694 | */ |
| 695 | static packBytes(format, ...); |
| 696 | |
| 697 | /* |
| 698 | * Unpack this string, interpreting the characters in the string as |
| 699 | * byte values, and unpacking the bytes according to the format string. |
| 700 | * Each character in the string must have a Unicode character number |
| 701 | * from 0 to 255; if any characters are outside this range, an error is |
| 702 | * thrown. |
| 703 | * |
| 704 | * This method can be used to unpack a string created with |
| 705 | * String.packBytes(). In most cases, using the same format string |
| 706 | * that was used to pack the bytes will re-create the original values. |
| 707 | * This method can also be convenient for parsing plain text that's |
| 708 | * arranged into fixed-width fields. |
| 709 | * |
| 710 | * 'format' is the format string describing the packed byte format. |
| 711 | * Returns a list consisting of the unpacked values. |
| 712 | * |
| 713 | * See Byte Packing in the System Manual for more details. |
| 714 | */ |
| 715 | unpackBytes(format); |
| 716 | |
| 717 | /* |
| 718 | * Convert each character in the string to title case, according to the |
| 719 | * Unicode character database definitions. Returns a new string with |
| 720 | * the title-case version of this string. |
| 721 | * |
| 722 | * For most characters, title case is the same as upper case. It |
| 723 | * differs from upper case when a single Unicode character represents |
| 724 | * more than one printed letter, such as the German sharp S U+00DF, or |
| 725 | * the various "ff" and "fi" ligatures. In these cases, the title-case |
| 726 | * conversion consists of the upper-case version of the first letter of |
| 727 | * the ligature followed by the lower-case versions of the remaining |
| 728 | * characters. Unicode doesn't define single-character title-case |
| 729 | * equivalents of most of the ligatures, so the result is usually a |
| 730 | * sequence of the individual characters making up the ligature. For |
| 731 | * example, title-casing the 'ffi' ligature character (U+FB03) produces |
| 732 | * the three-character sequence 'F', 'f', 'i'. |
| 733 | * |
| 734 | * Note that this routine converts every character in the string to |
| 735 | * title case, so it's not by itself a full title formatter - it's |
| 736 | * simply a character case converter. |
| 737 | */ |
| 738 | toTitleCase(); |
| 739 | |
| 740 | /* |
| 741 | * Convert the string to "folded" case. Returns a new string with the |
| 742 | * case-folded version of this string. |
| 743 | * |
| 744 | * Folded case is used for eliminating case distinctions in sets of |
| 745 | * strings, to allow for case-insensitive comparisons, sorting, etc. |
| 746 | * This routine produces the case folding defined in the Unicode |
| 747 | * character database; in most cases, the result is the same as |
| 748 | * converting each original character to upper case and then converting |
| 749 | * the result to lower case. This process not only removes case |
| 750 | * differences but also normalizes some variations in the ways certain |
| 751 | * character sequences are rendered, such as converting the German |
| 752 | * ess-zed U+00DF to "ss", and converting lower-case accented letters |
| 753 | * that don't have single character upper-case equivalents to the |
| 754 | * corresponding series of composition characters (e.g., U+01F0, a |
| 755 | * small 'j' with a caron, turns into U+006A + U+030C, a regular small |
| 756 | * 'j' followed by a combining caron character). Without this |
| 757 | * normalization, the upper- and lower-case renderings of such |
| 758 | * characters wouldn't match. |
| 759 | */ |
| 760 | toFoldedCase(); |
| 761 | |
| 762 | /* |
| 763 | * Compare this string to another string, using Unicode character code |
| 764 | * points as the collation order. Returns an integer less than zero if |
| 765 | * this string sorts before the other string, zero if they're |
| 766 | * identical, or greater than zero if this string sorts after the |
| 767 | * other. This makes the result suitable for use in a sort() callback, |
| 768 | * for example. |
| 769 | * |
| 770 | * Note that if you use the result for sorting text that includes |
| 771 | * accented Roman letters, the result order probably won't match the |
| 772 | * dictionary order for your language. Different languages (and even |
| 773 | * different countries/cultures sharing a language) have different |
| 774 | * rules for dictionary ordering, so collation is inherently language- |
| 775 | * specific. This routine doesn't take language differences into |
| 776 | * account; it simply uses the fixed Unicode code point ordering. The |
| 777 | * Unicode ordering for accented characters is somewhat arbitrary, |
| 778 | * because the accented Roman characters are arranged into multiple |
| 779 | * disjoint blocks that are all separate from the unaccented |
| 780 | * characters. For example, A-caron sorts after Z-caron, which sorts |
| 781 | * after A-breve, which sorts after Y-acute, which sorts after A-acute, |
| 782 | * which sorts after plain Z. |
| 783 | */ |
| 784 | compareTo(str); |
| 785 | |
| 786 | /* |
| 787 | * Compare this string to another string, ignoring case. The two |
| 788 | * strings are compared on the basis of the "case folded" versions of |
| 789 | * their characters, using the case folding rules from the Unicode |
| 790 | * standard (the case folded version of a string is the value returned |
| 791 | * by toFoldedCase()). The return alue is an integer less than zero if |
| 792 | * this string sorts before the other string, zero if they're |
| 793 | * identical, or greater than zero if this string sorts after the |
| 794 | * other. |
| 795 | * |
| 796 | * As with compareTo(), this only produces alphabetically correct |
| 797 | * sorting order when comparing ASCII strings. |
| 798 | */ |
| 799 | compareIgnoreCase(str); |
| 800 | |
| 801 | /* |
| 802 | * Find the last instance of a substring or pattern within the string, |
| 803 | * searching the subject string (self) from right to left (that is, |
| 804 | * from the end of the string towards the beginning). This works like |
| 805 | * find(), but searches in the reverse direction. Returns the index of |
| 806 | * the match, or nil if no match is found. |
| 807 | * |
| 808 | * 'str' can be a string or a RexPattern. If it's a string, we look |
| 809 | * for an exact match to the substring. If it's a RexPattern, we |
| 810 | * search for a match to the pattern. |
| 811 | * |
| 812 | * The optional 'index' specifies the starting index for the search. |
| 813 | * This is the index of the character AFTER the last character that's |
| 814 | * allowed to be included in the match. The first character of the |
| 815 | * string is at index 1; a negative index indicates an offset from the |
| 816 | * end of the string, so -1 is the last character. 0 has the special |
| 817 | * meaning of the end of the string, just past the last character in |
| 818 | * the string, so you can use 0 (or, equivalently, self.length()+1) to |
| 819 | * search the entire string from the end. For a repeated search, pass |
| 820 | * the index of the previous match, since this will find the next |
| 821 | * earlier matching substring that doesn't overlap with the previous |
| 822 | * match. |
| 823 | * |
| 824 | * (Note: "right to left" in this context simply means that the search |
| 825 | * runs from higher to lower character index in the string. We're |
| 826 | * using the term loosely, in particular ignoring anything related to |
| 827 | * the reading order or display direction for different languages or |
| 828 | * scripts.) |
| 829 | */ |
| 830 | findLast(str, index?); |
| 831 | |
| 832 | /* |
| 833 | * Find all occurrences of substring or pattern within a string, |
| 834 | * returning a list of the results. |
| 835 | * |
| 836 | * 'str' can be a string or RexPattern object. If it's a string, we |
| 837 | * look for exact matches to the substring. If it's a RexPattern, we |
| 838 | * search for matches to the pattern. |
| 839 | * |
| 840 | * 'func' is an optional function used to process the results. If this |
| 841 | * is provided, the function is called once for each match found in the |
| 842 | * string. The function's return value is then placed into the result |
| 843 | * list for the overall findAll() result. The function is called for |
| 844 | * each match found as follows: func(match, idx, g1, g2, ...), where |
| 845 | * 'match' is a string giving the text of the match, 'idx' is an |
| 846 | * integer giving the index in the string (self) of the first character |
| 847 | * of the match, and the 'gN' arguments are strings giving the text of |
| 848 | * the correspondingly numbered capture groups (the parenthesized |
| 849 | * groups in a regular expression match). All of the 'func' arguments |
| 850 | * except 'match' are optional: the function can omit them, in which |
| 851 | * case the caller doesn't pass them. If 'func' specifies more 'gN' |
| 852 | * capture group parameters than were actually found in the match, nil |
| 853 | * is passed for each extra parameter. |
| 854 | * |
| 855 | * The return value is a list of the results. If no occurrences of |
| 856 | * 'str' are found, the result is an empty list. If 'func' is |
| 857 | * specified, each element in the return list is the return value from |
| 858 | * calling 'func' for the corresponding match; if 'func' is omitted, |
| 859 | * each element in the return list is a string with the text of that |
| 860 | * match. |
| 861 | */ |
| 862 | findAll(str, func?); |
| 863 | |
| 864 | /* |
| 865 | * Match the given string or RexPattern object to this string value, |
| 866 | * starting at the start of the string or at the given index, if |
| 867 | * specified. If 'str' is a string, we check for a match to the |
| 868 | * literal text of the string; if 'str' is a RexPattern, we try to |
| 869 | * match the regular expression. 'idx' is the optional starting |
| 870 | * position (1 is the first character; negative values are from the end |
| 871 | * of the string, with -1 as the last character, -2 as the second to |
| 872 | * last, etc). If 'idx' is omitted, the default is the start of the |
| 873 | * string. |
| 874 | * |
| 875 | * Returns an integer giving the length of the match found if the |
| 876 | * string matches 'str', or nil if there's no match. |
| 877 | * |
| 878 | * The difference between this method and find() is that this method |
| 879 | * only checks for a match at the given starting position, without |
| 880 | * searching any further in the string, whereas find() searches for a |
| 881 | * match at each subsequent character of the string until a match is |
| 882 | * found or the string is exhausted. |
| 883 | */ |
| 884 | match(str, idx?); |
| 885 | } |
| 886 | |
| 887 | /* |
| 888 | * Flags for String.htmlify |
| 889 | */ |
| 890 | |
| 891 | /* |
| 892 | * translate spaces - each space in a run of multiple spaces is converted |
| 893 | * to an sequence |
| 894 | */ |
| 895 | #define HtmlifyTranslateSpaces 0x0001 |
| 896 | |
| 897 | /* translate newlines - converts each \n character to a <br> tag */ |
| 898 | #define HtmlifyTranslateNewlines 0x0002 |
| 899 | |
| 900 | /* translate tabs - converts each \t character to a <tab> tag */ |
| 901 | #define HtmlifyTranslateTabs 0x0004 |
| 902 | |
| 903 | /* |
| 904 | * Translate all whitespace characters - translate all spaces, tabs, and |
| 905 | * newlines into their HTML equivalents: each space character becomes an |
| 906 | * '  sequence;', each '\n' character becomes a <br> tag; and each |
| 907 | * '\t' character becomes a <tab> tag. |
| 908 | */ |
| 909 | #define HtmlifyTranslateWhitespace \ |
| 910 | (HtmlifyTranslateSpaces | HtmlifyTranslateNewlines | HtmlifyTranslateTabs) |
| 911 | |
| 912 | |
| 913 | /* |
| 914 | * Flags for String.findReplace |
| 915 | */ |
| 916 | #define ReplaceAll 0x0001 |
| 917 | #define ReplaceIgnoreCase 0x0002 |
| 918 | #define ReplaceFollowCase 0x0004 |
| 919 | #define ReplaceSerial 0x0008 |
| 920 | #define ReplaceOnce 0x0010 |
| 921 | |
| 922 | /* property exports for specialsToHtml's state object */ |
| 923 | property flags_, tag_; |
| 924 | export flags_ 'String.specialsToHtml.flags'; |
| 925 | export tag_ 'String.specialsToHtml.tag'; |
| 926 | |
| 927 | |
| 928 | /* ------------------------------------------------------------------------ */ |
| 929 | /* |
| 930 | * The native list type |
| 931 | */ |
| 932 | intrinsic class List 'list/030008': Collection |
| 933 | { |
| 934 | /* |
| 935 | * Select a subset of the list: returns a new list consisting only |
| 936 | * of the elements for which the callback function 'func' returns |
| 937 | * true. |
| 938 | */ |
| 939 | subset(func); |
| 940 | |
| 941 | /* |
| 942 | * Apply the callback function to each element of this list, and |
| 943 | * return a new list consisting of the results. Effectively maps |
| 944 | * the list to a new list using the given function. Suppose the |
| 945 | * original list is |
| 946 | * |
| 947 | * [x, y, z] |
| 948 | * |
| 949 | * Then the result list is |
| 950 | * |
| 951 | * [func(x), func(y), func(z)] |
| 952 | */ |
| 953 | mapAll(func); |
| 954 | |
| 955 | /* get the number of elements in the list */ |
| 956 | length(); |
| 957 | |
| 958 | /* extract a sublist */ |
| 959 | sublist(start, len?); |
| 960 | |
| 961 | /* intersect with another list */ |
| 962 | intersect(other); |
| 963 | |
| 964 | /* get the index of the first match for the given value */ |
| 965 | indexOf(val); |
| 966 | |
| 967 | /* car/cdr - head/tail of list */ |
| 968 | car(); |
| 969 | cdr(); |
| 970 | |
| 971 | /* |
| 972 | * Find the first element for which the given condition is true, and |
| 973 | * return the index of the element. Applies the callback function |
| 974 | * (which encodes the condition to evaluate) to each element in |
| 975 | * turn, starting with the first. For each element, if the callback |
| 976 | * returns nil, proceeds to the next element; otherwise, stops and |
| 977 | * returns the index of the element. If the callback never returns |
| 978 | * true for any element, we'll return nil. |
| 979 | */ |
| 980 | indexWhich(cond); |
| 981 | |
| 982 | /* |
| 983 | * Invoke the callback func(val) on each element, in order from first |
| 984 | * to last. No return value. |
| 985 | */ |
| 986 | forEach(func); |
| 987 | |
| 988 | /* |
| 989 | * Find the first element for which the given condition is true, and |
| 990 | * return the value of the element. Returns nil if no item |
| 991 | * satisfies the condition. |
| 992 | */ |
| 993 | valWhich(cond); |
| 994 | |
| 995 | /* find the last element with the given value, and return its index */ |
| 996 | lastIndexOf(val); |
| 997 | |
| 998 | /* |
| 999 | * Find the last element for which the condition is true, and return |
| 1000 | * the index of the element. Applies the callback to each element |
| 1001 | * in turn, starting with the last element and working backwards. |
| 1002 | * For each element, if the callback returns nil, proceeds to the |
| 1003 | * previous element; otherwise, stops and returns the index of the |
| 1004 | * element. If the callback never returns true for any element, |
| 1005 | * we'll return nil. |
| 1006 | */ |
| 1007 | lastIndexWhich(cond); |
| 1008 | |
| 1009 | /* |
| 1010 | * Find the last element for which the condition is true, and return |
| 1011 | * the value of the element |
| 1012 | */ |
| 1013 | lastValWhich(cond); |
| 1014 | |
| 1015 | /* count the number of elements with the given value */ |
| 1016 | countOf(val); |
| 1017 | |
| 1018 | /* count the number of elements for which the callback returns true */ |
| 1019 | countWhich(cond); |
| 1020 | |
| 1021 | /* get a new list consisting of the unique elements of this list */ |
| 1022 | getUnique(); |
| 1023 | |
| 1024 | /* |
| 1025 | * append the elements of the list 'lst' to the elements of this |
| 1026 | * list, then remove repeated elements in the result; returns a new |
| 1027 | * list with the unique elements of the combination of the two lists |
| 1028 | */ |
| 1029 | appendUnique(lst); |
| 1030 | |
| 1031 | /* |
| 1032 | * append an element - this works almost exactly like the |
| 1033 | * concatation operator ('+'), but if the argument is a list, this |
| 1034 | * simply adds the list as a new element, rather than adding each |
| 1035 | * element of the list as a separate element |
| 1036 | */ |
| 1037 | append(val); |
| 1038 | |
| 1039 | /* |
| 1040 | * Sort the list, returning a new list. If the 'descending' flag is |
| 1041 | * provided and is not nil, we'll sort the list in descending order |
| 1042 | * rather than ascending order. |
| 1043 | * |
| 1044 | * If the 'comparisonFunction' argument is provided, it must be a |
| 1045 | * callback function; the callback takes two arguments, and returns |
| 1046 | * an integer less than zero if the first argument value is less |
| 1047 | * than the second, zero if they're equal, and an integer greater |
| 1048 | * than zero if the first is greater than the second. If no |
| 1049 | * 'comparisonFunction' argument is provided, or it's provided and |
| 1050 | * its value is nil, we'll simply compare the list elements as |
| 1051 | * ordinary values. The comparison function can be provided for |
| 1052 | * caller-defined orderings, such as ordering a set of objects. |
| 1053 | */ |
| 1054 | sort(descending?, comparisonFunction?); |
| 1055 | |
| 1056 | /* |
| 1057 | * Prepend an element - this inserts the value before the first |
| 1058 | * existing element. |
| 1059 | */ |
| 1060 | prepend(val); |
| 1061 | |
| 1062 | /* |
| 1063 | * Insert one or more elements at the given index. If the starting |
| 1064 | * index is 1, the elements will be inserted before the first existing |
| 1065 | * element. If the index is one higher than the number of elements, |
| 1066 | * the elements will be inserted after all existing elements. If the |
| 1067 | * index is negative, it counts backwards from the end of the list: -1 |
| 1068 | * inserts before the last element, -2 inserts before the second to |
| 1069 | * last, and so on. If the index is zero, the new elements are |
| 1070 | * inserted after the last element. |
| 1071 | * |
| 1072 | * Note that a list value argument will simply be inserted as a single |
| 1073 | * element. |
| 1074 | * |
| 1075 | * Returns a new list with the value(s) inserted. |
| 1076 | */ |
| 1077 | insertAt(startingIndex, val, ...); |
| 1078 | |
| 1079 | /* |
| 1080 | * Delete the element at the given index, reducing the length of the |
| 1081 | * list by one element. If the index is negative, it counts from the |
| 1082 | * end of the list: -1 is the last element, -2 is the second to last, |
| 1083 | * etc. Returns a new list with the given element removed. |
| 1084 | */ |
| 1085 | removeElementAt(index); |
| 1086 | |
| 1087 | /* |
| 1088 | * Delete the range of elements starting at startingIndex and ending at |
| 1089 | * endingIndex. The elements at the ends of the range are included in |
| 1090 | * the deletion. If startingIndex == endingIndex, only one element is |
| 1091 | * removed. If either index is negative, it counts from the end of the |
| 1092 | * list: -1 is the last element, -2 is the second to last, etc. |
| 1093 | * Returns a new list with the given element range removed. |
| 1094 | */ |
| 1095 | removeRange(startingIndex, endingIndex); |
| 1096 | |
| 1097 | /* |
| 1098 | * Invoke the callback func(index, val) on each element, in order from |
| 1099 | * first to last. No return value. |
| 1100 | */ |
| 1101 | forEachAssoc(func); |
| 1102 | |
| 1103 | /* |
| 1104 | * Class method: Generate a new list. 'func' is a callback function, |
| 1105 | * which can take zero or one argument. 'n' is the number of elements |
| 1106 | * for the new list. For each element, 'func' is invoked as func() if |
| 1107 | * it takes no arguments, or func(idx) if it takes one argument, where |
| 1108 | * 'idx' is the index of the element being generated. The return value |
| 1109 | * of the call to 'func' is stored as the list element. The method |
| 1110 | * returns the resulting list. For example, a list of the first ten |
| 1111 | * even positive integers: List.generate({i: i*2}, 10). |
| 1112 | */ |
| 1113 | static generate(func, n); |
| 1114 | |
| 1115 | /* |
| 1116 | * Splice new values into the list. Deletes the 'del' list items |
| 1117 | * starting at 'idx', then inserts the extra arguments in their place. |
| 1118 | * Returns a new list reflecting the spliced values. To insert items |
| 1119 | * without deleting anything, pass 0 for 'del'. To delete items |
| 1120 | * without inserting anything, omit any additional arguments. |
| 1121 | */ |
| 1122 | splice(idx, del, ...); |
| 1123 | |
| 1124 | /* |
| 1125 | * Combine the list elements into a string. This converts each element |
| 1126 | * into a string value using the usual default conversions (or throws |
| 1127 | * an error if string conversion isn't possible), then concatenates the |
| 1128 | * values together and returns the result. If 'separator' is provided, |
| 1129 | * it's a string that's interposed between elements; if this is |
| 1130 | * omitted, the elements are concatenated together with no extra |
| 1131 | * characters in between. |
| 1132 | */ |
| 1133 | join(sep?); |
| 1134 | |
| 1135 | /* |
| 1136 | * Get the index of the list item with the minimum value. If 'func' is |
| 1137 | * missing, this simply returns the index of the list element with the |
| 1138 | * smallest value, comparing the element values as though using the '>' |
| 1139 | * and '<' operators. If 'func' is specified, it must be a function; |
| 1140 | * it's called as func(x) for each value in the list, and the result of |
| 1141 | * the overall call is the index of the element for which func(x) |
| 1142 | * returns the smallest value. For example, if you have a list of |
| 1143 | * strings l, l.indexOfMin({x: x.length()}) returns the index of the |
| 1144 | * shortest string in the list. |
| 1145 | */ |
| 1146 | indexOfMin(func?); |
| 1147 | |
| 1148 | /* |
| 1149 | * Get the minimum value in the list. If 'func' is missing, this |
| 1150 | * returns the minimum element value. If 'func' is specified, it must |
| 1151 | * be a function; it's called as func(x) for each value in the list, |
| 1152 | * and the result of the overall method call is the element value x |
| 1153 | * that minimizes func(x). For example, if l is a list of strings, |
| 1154 | * l.minVal({x: x.length()}) returns the shortest string. |
| 1155 | */ |
| 1156 | minVal(func?); |
| 1157 | |
| 1158 | /* |
| 1159 | * Get the index of the list item with the maximum value. If 'func' is |
| 1160 | * missing, this simply returns the index of the list element with the |
| 1161 | * largest value, comparing the element values as though using the '>' |
| 1162 | * and '<' operators. If 'func' is specified, it must be a function; |
| 1163 | * it's called as func(x) for each value in the list, and the result of |
| 1164 | * the overall call is the index of the element for which func(x) |
| 1165 | * returns the greatest value. For example, if you have a list of |
| 1166 | * strings l, l.indexOfMax({x: x.length()}) returns the index of the |
| 1167 | * longest string in the list. |
| 1168 | */ |
| 1169 | indexOfMax(func?); |
| 1170 | |
| 1171 | /* |
| 1172 | * Get the maximum value in the list. If 'func' is missing, this |
| 1173 | * returns the largest element value. If 'func' is specified, it must |
| 1174 | * be a function; it's called as func(x) for each value in the list, |
| 1175 | * and the result of the overall method call is the element value x |
| 1176 | * that maximizes func(x). For example, if l is a list of strings, |
| 1177 | * l.maxVal({x: x.length()}) returns the longest string. |
| 1178 | */ |
| 1179 | maxVal(func?); |
| 1180 | } |
| 1181 | |
| 1182 | /* |
| 1183 | * Sorting order flags. These can be passed in as the first argument to |
| 1184 | * List.sort() (and Vector.sort() as well) to make the meaning of the |
| 1185 | * argument clearer. |
| 1186 | */ |
| 1187 | #define SortAsc nil |
| 1188 | #define SortDesc true |
| 1189 | |
| 1190 | /* |
| 1191 | * Export length() as the element counter method for list-like objects in |
| 1192 | * general. |
| 1193 | */ |
| 1194 | export length 'length'; |
| 1195 | |
| 1196 | |
| 1197 | /* ------------------------------------------------------------------------ */ |
| 1198 | /* |
| 1199 | * 'RexPattern' intrinsic class. This class encapsulates a compiled |
| 1200 | * regular expression pattern. |
| 1201 | * |
| 1202 | * A RexPattern object can be passed to the regular expression functions |
| 1203 | * (rexMatch, rexSearch, rexReplace) in place of a string pattern. Since |
| 1204 | * compiling a regular expression takes a non-trivial amount of time, it's |
| 1205 | * more efficient to compile a pattern to a RexPattern object if the same |
| 1206 | * pattern will be used in multiple searches. |
| 1207 | */ |
| 1208 | intrinsic class RexPattern 'regex-pattern/030000': Object |
| 1209 | { |
| 1210 | /* |
| 1211 | * Constructor: |
| 1212 | * |
| 1213 | * new RexPattern(patternString) - returns a RexPattern representing |
| 1214 | * the compiled pattern string. |
| 1215 | */ |
| 1216 | |
| 1217 | /* retrieve the original pattern string used to construct the object */ |
| 1218 | getPatternString(); |
| 1219 | } |
| 1220 | |
| 1221 | /* ------------------------------------------------------------------------ */ |
| 1222 | /* |
| 1223 | * StackFrameDesc intrinsic class. This class provides access to a stack |
| 1224 | * frame. It lets us retrieve the values of local variables and method |
| 1225 | * context variables (self, definingobj, targetobj, targetprop). It also |
| 1226 | * allows us to assign new values to local variables. |
| 1227 | * |
| 1228 | * To get the value of a local variable in the frame, simply use |
| 1229 | * frame[name], where 'frame' is the StackFrameDesc object for the frame, |
| 1230 | * and 'name' is a string giving the name of the local variable to |
| 1231 | * retrieve. If the frame is active, this retrieves the live value of the |
| 1232 | * variable from the frame; otherwise it retrieves the value from a |
| 1233 | * snapshot containing the last value before the routine returned to its |
| 1234 | * caller. |
| 1235 | * |
| 1236 | * To assign a new value to a local in the frame, assign a value to |
| 1237 | * frame[name] for the desired variable name. If the frame is active, this |
| 1238 | * updates the live variable in the stack frame, so when execution returns |
| 1239 | * to the caller the variable will have the new value. If the frame is |
| 1240 | * inactive, it updates the snapshot we made when the routine returned to |
| 1241 | * its caller. |
| 1242 | * |
| 1243 | * This object can't be created with 'new'. Instead, you obtain these |
| 1244 | * objects via the t3GetStackTrace() function. That function retrieves |
| 1245 | * information on an active stack frame in the current call stack, |
| 1246 | * including the frame object. |
| 1247 | */ |
| 1248 | intrinsic class StackFrameDesc 'stack-frame-desc/030000' |
| 1249 | { |
| 1250 | /* |
| 1251 | * Is the stack frame active? A stack frame is active until the |
| 1252 | * function or method it represents returns to its caller. When the |
| 1253 | * routine returns, the frame becomes inactive. |
| 1254 | * |
| 1255 | * When the routine is about to return (so the frame is about to become |
| 1256 | * inacive), the StackFrameDesc object makes a private snapshot of the |
| 1257 | * variables in the frame. Subsequent access to the locals will |
| 1258 | * automatically use the snapshot copy, so you can continue to access |
| 1259 | * the locals as normal without worrying about whether or not the |
| 1260 | * actual stack frame still exists. This allows you to continue to |
| 1261 | * access and modify the values of the variables after the routine has |
| 1262 | * exited. |
| 1263 | */ |
| 1264 | isActive(); |
| 1265 | |
| 1266 | /* |
| 1267 | * Get a LookupTable consisting of all of the variables (local |
| 1268 | * variables and parameters) in the frame. Each element in the table |
| 1269 | * is keyed by the name of a variable, and contains the current value |
| 1270 | * of the variable. |
| 1271 | * |
| 1272 | * The returned lookup table is a snapshot copy of the current values |
| 1273 | * of the variables. If the underlying variable values in the frame |
| 1274 | * change, the lookup table won't be affected, since it's just a |
| 1275 | * separate copy made at the moment this routine is called. Similarly, |
| 1276 | * changing the value of an entry in the returned lookup table won't |
| 1277 | * affect the actual variable in the stack frame. |
| 1278 | * |
| 1279 | * To retrieve the current live value of a variable in the actual stack |
| 1280 | * frame, use frame[name], where 'frame' is the StackFrameDesc object |
| 1281 | * for the frame, and 'name' is a string giving the variable name. |
| 1282 | */ |
| 1283 | getVars(); |
| 1284 | |
| 1285 | /* |
| 1286 | * Get the value of 'self' in this frame. |
| 1287 | */ |
| 1288 | getSelf(); |
| 1289 | |
| 1290 | /* |
| 1291 | * Get the value of 'definingobj' in this frame. |
| 1292 | */ |
| 1293 | getDefiningObj(); |
| 1294 | |
| 1295 | /* |
| 1296 | * Get the value of 'targetobj' in this frame. |
| 1297 | */ |
| 1298 | getTargetObj(); |
| 1299 | |
| 1300 | /* |
| 1301 | * Get the value of 'targetprop' in this frame. |
| 1302 | */ |
| 1303 | getTargetProp(); |
| 1304 | |
| 1305 | /* |
| 1306 | * Get the value of 'invokee' in this frame. |
| 1307 | */ |
| 1308 | getInvokee(); |
| 1309 | } |
| 1310 | |
| 1311 | /* |
| 1312 | * A StackFrameRef is an internal object used with StackFrameDesc. This |
| 1313 | * type is used internally by the VM; user code can't create an instance of |
| 1314 | * this class directly with 'new', and the class has no public methods. |
| 1315 | */ |
| 1316 | intrinsic class StackFrameRef 'stack-frame-ref/030000' |
| 1317 | { |
| 1318 | } |
| 1319 |