| | 1 | = Literals = |
| | 2 | [[TracNav]] |
| | 3 | |
| | 4 | Constant literal values of the primitive atomic types--boolean, long, double, string, undef, and null--may appear inside of a DML block. The following sections define the syntax for literal values of each type. |
| | 5 | |
| | 6 | == Boolean Literals == |
| | 7 | |
| | 8 | There are exactly two possible boolean values: '''true''' and '''false'''. They must appear as an unquoted word and completely in lowercase. |
| | 9 | |
| | 10 | == Long Literals == |
| | 11 | |
| | 12 | Long literals may be given in decimal, hexadecimal, or octal format. A decimal literal is a sequence of digits starting with a number other than zero. A hexadecimal literal starts with the '0x' or '0X' and is followed by a sequence of hexadecimal digits. An octal literal starts with a zero is followed by a sequence of octal digits. Examples: |
| | 13 | {{{ |
| | 14 | 123 # decimal long literal |
| | 15 | 0755 # octal long literal |
| | 16 | 0xFF # hexadecimal long literal |
| | 17 | }}} |
| | 18 | |
| | 19 | Long literals are represented internally as an 8-byte signed number. Long values that cannot be represented in 8 bytes will cause a syntax error to be thrown. |
| | 20 | |
| | 21 | |
| | 22 | == Double Literals == |
| | 23 | |
| | 24 | Double literals represent a floating point number. A double literal must start with a digit and must contain either a decimal point or an exponent. Examples: |
| | 25 | {{{ |
| | 26 | 0.01 |
| | 27 | 3.14159 |
| | 28 | 1e-8 |
| | 29 | 1.3E10 |
| | 30 | }}} |
| | 31 | Note that '.2' is not a valid double literal; this value must be written as '0.2'. |
| | 32 | |
| | 33 | Double literals are represented internally as an 8-byte value. Double values that cannot be represented in 8 bytes will cause a syntax error to be thrown. |
| | 34 | |
| | 35 | == String Literals == |
| | 36 | |
| | 37 | The string literals can be expressed in three different forms. They can be of any length and can |
| | 38 | contain any character, including the NULL byte. |
| | 39 | |
| | 40 | Single quoted strings are used to represent short and simple strings. They cannot span several lines |
| | 41 | and all the characters will appear verbatim in the string, except the doubled single quote which is used to |
| | 42 | represent a single quote inside the string. For instance: |
| | 43 | {{{ |
| | 44 | ’foo’ |
| | 45 | ’it’’s a sentence’ |
| | 46 | ’ˆ\d+\.\d+$’ |
| | 47 | }}} |
| | 48 | This is the most efficient string representation and should be used when possible. |
| | 49 | |
| | 50 | Double quoted strings are more flexible and use the backslash to represent escape sequences. For |
| | 51 | instance: |
| | 52 | {{{ |
| | 53 | "foo" |
| | 54 | "it’s a sentence" |
| | 55 | "Java-style escapes: \t (tab) \r (carriage return) \n (newline)" |
| | 56 | "Hexadecimal escapes: \x3d (=) \x00 (NULL byte) \x0A (newline)" |
| | 57 | "Miscellaneous escapes: \" (double quote) \\ (backslash)" |
| | 58 | "this string spans two lines and\ |
| | 59 | does not contain a newline" |
| | 60 | }}} |
| | 61 | Invalid escape sequences will cause a syntax error to be thrown. |
| | 62 | |
| | 63 | Multi-line strings can be represented using the 'here-doc' syntax, like in shell or Perl. |
| | 64 | {{{ |
| | 65 | "test" = "foo" + <<EOT + "bar"; |
| | 66 | this code will assign to the path "test" the string |
| | 67 | made of ‘foo’, plus this text including the final newline, |
| | 68 | plus ‘bar’... |
| | 69 | EOT |
| | 70 | }}} |
| | 71 | The contents of the 'here-doc' are treated as a single-quoted string. That is, no escape processing is done. |
| | 72 | |
| | 73 | The easiest solution to put binary data inside pan code is to base64 encode it and put it inside ”here- |
| | 74 | doc” strings like in the following example: |
| | 75 | {{{ |
| | 76 | "/system/binary/stuff" = base64_decode(<<EOT); |
| | 77 | H4sIAOwLyDwAA02PQQ7DMAgE731FX9BT1f8QZ52iYhthEiW/r2SitCdmxCK0E3W8no+36n2G |
| | 78 | 8UbOrYYWGROCgurBe4JeCexI2ahgWF5rulaLtImkDxbucS0tcc3t5GXMAqeZnIYo+TvAmsL8 |
| | 79 | GGLobbUUX7pT+pxkXJc/5Bx5p0ki7Cgq5KccGrCR8PzruUfP2xfJgVqHCgEAAA== |
| | 80 | EOT |
| | 81 | }}} |
| | 82 | The base64_decode() function is one of the built-in pan functions. |
| | 83 | |
| | 84 | == Other Literals == |