Changes between Initial Version and Version 1 of Doc/panc/dml/literals


Ignore:
Timestamp:
Mar 3, 2007, 5:56:17 PM (19 years ago)
Author:
/O=GRID-FR/C=FR/O=CNRS/OU=LAL/CN=Charles Loomis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Doc/panc/dml/literals

    v1 v1  
     1= Literals =
     2[[TracNav]]
     3
     4Constant 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
     8There 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
     12Long 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{{{
     14123  # decimal long literal
     150755 # octal long literal
     160xFF # hexadecimal long literal
     17}}}
     18
     19Long 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
     24Double 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{{{
     260.01
     273.14159
     281e-8
     291.3E10
     30}}}
     31Note that '.2' is not a valid double literal; this value must be written as '0.2'.
     32
     33Double 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
     37The string literals can be expressed in three different forms. They can be of any length and can
     38contain any character, including the NULL byte.
     39
     40Single quoted strings are used to represent short and simple strings.  They cannot span several lines
     41and all the characters will appear verbatim in the string, except the doubled single quote which is used to
     42represent a single quote inside the string.  For instance:
     43{{{
     44’foo’
     45’it’’s a sentence’
     46’ˆ\d+\.\d+$’
     47}}}
     48This is the most efficient string representation and should be used when possible.
     49
     50Double quoted strings are more flexible and use the backslash to represent escape sequences.  For
     51instance:
     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\
     59does not contain a newline"
     60}}}
     61Invalid escape sequences will cause a syntax error to be thrown.
     62
     63Multi-line strings can be represented using the 'here-doc' syntax, like in shell or Perl.
     64{{{
     65"test" = "foo" + <<EOT + "bar";
     66this code will assign to the path "test" the string
     67made of ‘foo’, plus this text including the final newline,
     68plus ‘bar’...
     69EOT
     70}}}
     71The contents of the 'here-doc' are treated as a single-quoted string.  That is, no escape processing is done.
     72
     73The easiest solution to put binary data inside pan code is to base64 encode it and put it inside ”here-
     74doc” strings like in the following example:
     75{{{
     76"/system/binary/stuff" = base64_decode(<<EOT);
     77H4sIAOwLyDwAA02PQQ7DMAgE731FX9BT1f8QZ52iYhthEiW/r2SitCdmxCK0E3W8no+36n2G
     788UbOrYYWGROCgurBe4JeCexI2ahgWF5rulaLtImkDxbucS0tcc3t5GXMAqeZnIYo+TvAmsL8
     79GGLobbUUX7pT+pxkXJc/5Bx5p0ki7Cgq5KccGrCR8PzruUfP2xfJgVqHCgEAAA==
     80EOT
     81}}}
     82The base64_decode() function is one of the built-in pan functions.
     83
     84== Other Literals ==