2018-04-17 15:16:08 -04:00
|
|
|
[[painless-literals]]
|
2017-05-12 19:17:06 -04:00
|
|
|
=== Literals
|
|
|
|
|
2018-05-23 16:36:58 -04:00
|
|
|
Use a literal to specify a value directly in an
|
|
|
|
<<painless-operators, operation>>.
|
2017-05-12 19:17:06 -04:00
|
|
|
|
Painless: Restructure/Clean Up of Spec Documentation (#31013)
Full restructure of the spec into new sections for operators, statements, scripts, functions, lambdas, and regexes. Split of operators into 6 sections, a table, reference, array, numeric, boolean, and general. Clean up of all operators sections. Sporadic clean up else where.
2018-06-07 20:11:56 -04:00
|
|
|
[[integer-literals]]
|
2017-05-12 19:17:06 -04:00
|
|
|
==== Integers
|
|
|
|
|
2018-05-23 16:36:58 -04:00
|
|
|
Use an integer literal to specify an integer type value in decimal, octal, or
|
|
|
|
hex notation of a <<primitive-types, primitive type>> `int`, `long`, `float`,
|
2018-04-17 15:16:08 -04:00
|
|
|
or `double`. Use the following single letter designations to specify the
|
2018-05-23 16:36:58 -04:00
|
|
|
primitive type: `l` or `L` for `long`, `f` or `F` for `float`, and `d` or `D`
|
|
|
|
for `double`. If not specified, the type defaults to `int`. Use `0` as a prefix
|
|
|
|
to specify an integer literal as octal, and use `0x` or `0X` as a prefix to
|
|
|
|
specify an integer literal as hex.
|
2017-05-12 19:17:06 -04:00
|
|
|
|
2018-04-17 15:16:08 -04:00
|
|
|
*Grammar*
|
Painless: Restructure/Clean Up of Spec Documentation (#31013)
Full restructure of the spec into new sections for operators, statements, scripts, functions, lambdas, and regexes. Split of operators into 6 sections, a table, reference, array, numeric, boolean, and general. Clean up of all operators sections. Sporadic clean up else where.
2018-06-07 20:11:56 -04:00
|
|
|
|
2017-05-12 19:17:06 -04:00
|
|
|
[source,ANTLR4]
|
|
|
|
----
|
|
|
|
INTEGER: '-'? ( '0' | [1-9] [0-9]* ) [lLfFdD]?;
|
2018-04-17 15:16:08 -04:00
|
|
|
OCTAL: '-'? '0' [0-7]+ [lL]?;
|
|
|
|
HEX: '-'? '0' [xX] [0-9a-fA-F]+ [lL]?;
|
2017-05-12 19:17:06 -04:00
|
|
|
----
|
|
|
|
|
2018-04-17 15:16:08 -04:00
|
|
|
*Examples*
|
|
|
|
|
2018-04-25 12:38:41 -04:00
|
|
|
* Integer literals.
|
|
|
|
+
|
2018-04-17 15:16:08 -04:00
|
|
|
[source,Painless]
|
2017-05-12 19:17:06 -04:00
|
|
|
----
|
2019-04-04 08:41:30 -04:00
|
|
|
0 <1>
|
|
|
|
0D <2>
|
|
|
|
1234L <3>
|
|
|
|
-90f <4>
|
|
|
|
-022 <5>
|
|
|
|
0xF2A <6>
|
2017-05-12 19:17:06 -04:00
|
|
|
----
|
2018-04-25 12:38:41 -04:00
|
|
|
+
|
2018-04-17 15:16:08 -04:00
|
|
|
<1> `int 0`
|
|
|
|
<2> `double 0.0`
|
|
|
|
<3> `long 1234`
|
|
|
|
<4> `float -90.0`
|
|
|
|
<5> `int -18` in octal
|
|
|
|
<6> `int 3882` in hex
|
|
|
|
|
Painless: Restructure/Clean Up of Spec Documentation (#31013)
Full restructure of the spec into new sections for operators, statements, scripts, functions, lambdas, and regexes. Split of operators into 6 sections, a table, reference, array, numeric, boolean, and general. Clean up of all operators sections. Sporadic clean up else where.
2018-06-07 20:11:56 -04:00
|
|
|
[[float-literals]]
|
2018-04-17 15:16:08 -04:00
|
|
|
==== Floats
|
2017-05-12 19:17:06 -04:00
|
|
|
|
2018-05-23 16:36:58 -04:00
|
|
|
Use a floating point literal to specify a floating point type value of a
|
|
|
|
<<primitive-types, primitive type>> `float` or `double`. Use the following
|
|
|
|
single letter designations to specify the primitive type: `f` or `F` for `float`
|
|
|
|
and `d` or `D` for `double`. If not specified, the type defaults to `double`.
|
2017-05-12 19:17:06 -04:00
|
|
|
|
2018-04-17 15:16:08 -04:00
|
|
|
*Grammar*
|
Painless: Restructure/Clean Up of Spec Documentation (#31013)
Full restructure of the spec into new sections for operators, statements, scripts, functions, lambdas, and regexes. Split of operators into 6 sections, a table, reference, array, numeric, boolean, and general. Clean up of all operators sections. Sporadic clean up else where.
2018-06-07 20:11:56 -04:00
|
|
|
|
2017-05-12 19:17:06 -04:00
|
|
|
[source,ANTLR4]
|
|
|
|
----
|
2018-04-17 15:16:08 -04:00
|
|
|
DECIMAL: '-'? ( '0' | [1-9] [0-9]* ) (DOT [0-9]+)? EXPONENT? [fFdD]?;
|
|
|
|
EXPONENT: ( [eE] [+\-]? [0-9]+ );
|
2017-05-12 19:17:06 -04:00
|
|
|
----
|
|
|
|
|
2018-04-17 15:16:08 -04:00
|
|
|
*Examples*
|
|
|
|
|
2018-04-25 12:38:41 -04:00
|
|
|
* Floating point literals.
|
|
|
|
+
|
2018-04-17 15:16:08 -04:00
|
|
|
[source,Painless]
|
2017-05-12 19:17:06 -04:00
|
|
|
----
|
2019-04-04 08:41:30 -04:00
|
|
|
0.0 <1>
|
|
|
|
1E6 <2>
|
|
|
|
0.977777 <3>
|
|
|
|
-126.34 <4>
|
|
|
|
89.9F <5>
|
2017-05-12 19:17:06 -04:00
|
|
|
----
|
2018-04-25 12:38:41 -04:00
|
|
|
+
|
2018-04-17 15:16:08 -04:00
|
|
|
<1> `double 0.0`
|
|
|
|
<2> `double 1000000.0` in exponent notation
|
|
|
|
<3> `double 0.977777`
|
|
|
|
<4> `double -126.34`
|
|
|
|
<5> `float 89.9`
|
|
|
|
|
Painless: Restructure/Clean Up of Spec Documentation (#31013)
Full restructure of the spec into new sections for operators, statements, scripts, functions, lambdas, and regexes. Split of operators into 6 sections, a table, reference, array, numeric, boolean, and general. Clean up of all operators sections. Sporadic clean up else where.
2018-06-07 20:11:56 -04:00
|
|
|
[[string-literals]]
|
2017-05-12 19:17:06 -04:00
|
|
|
==== Strings
|
|
|
|
|
2018-05-23 16:36:58 -04:00
|
|
|
Use a string literal to specify a <<string-type, `String` type>> value with
|
2018-04-25 12:38:41 -04:00
|
|
|
either single-quotes or double-quotes. Use a `\"` token to include a
|
|
|
|
double-quote as part of a double-quoted string literal. Use a `\'` token to
|
|
|
|
include a single-quote as part of a single-quoted string literal. Use a `\\`
|
|
|
|
token to include a backslash as part of any string literal.
|
2017-05-12 19:17:06 -04:00
|
|
|
|
2018-04-17 15:16:08 -04:00
|
|
|
*Grammar*
|
Painless: Restructure/Clean Up of Spec Documentation (#31013)
Full restructure of the spec into new sections for operators, statements, scripts, functions, lambdas, and regexes. Split of operators into 6 sections, a table, reference, array, numeric, boolean, and general. Clean up of all operators sections. Sporadic clean up else where.
2018-06-07 20:11:56 -04:00
|
|
|
|
2017-05-12 19:17:06 -04:00
|
|
|
[source,ANTLR4]
|
|
|
|
----
|
2018-04-17 15:16:08 -04:00
|
|
|
STRING: ( '"' ( '\\"' | '\\\\' | ~[\\"] )*? '"' )
|
|
|
|
| ( '\'' ( '\\\'' | '\\\\' | ~[\\'] )*? '\'' );
|
2017-05-12 19:17:06 -04:00
|
|
|
----
|
|
|
|
|
2018-04-17 15:16:08 -04:00
|
|
|
*Examples*
|
|
|
|
|
2018-04-25 12:38:41 -04:00
|
|
|
* String literals using single-quotes.
|
|
|
|
+
|
2018-04-17 15:16:08 -04:00
|
|
|
[source,Painless]
|
2017-05-12 19:17:06 -04:00
|
|
|
----
|
2018-04-17 15:16:08 -04:00
|
|
|
'single-quoted string literal'
|
2018-04-25 12:38:41 -04:00
|
|
|
'\'single-quoted with escaped single-quotes\' and backslash \\'
|
|
|
|
'single-quoted with non-escaped "double-quotes"'
|
2017-05-12 19:17:06 -04:00
|
|
|
----
|
2018-04-25 12:38:41 -04:00
|
|
|
+
|
|
|
|
* String literals using double-quotes.
|
|
|
|
+
|
2018-04-17 15:16:08 -04:00
|
|
|
[source,Painless]
|
|
|
|
----
|
|
|
|
"double-quoted string literal"
|
2018-04-25 12:38:41 -04:00
|
|
|
"\"double-quoted with escaped double-quotes\" and backslash: \\"
|
|
|
|
"double-quoted with non-escaped 'single-quotes'"
|
2018-04-17 15:16:08 -04:00
|
|
|
----
|
2017-05-12 19:17:06 -04:00
|
|
|
|
Painless: Restructure/Clean Up of Spec Documentation (#31013)
Full restructure of the spec into new sections for operators, statements, scripts, functions, lambdas, and regexes. Split of operators into 6 sections, a table, reference, array, numeric, boolean, and general. Clean up of all operators sections. Sporadic clean up else where.
2018-06-07 20:11:56 -04:00
|
|
|
[[character-literals]]
|
2018-04-17 15:16:08 -04:00
|
|
|
==== Characters
|
|
|
|
|
Painless: Restructure/Clean Up of Spec Documentation (#31013)
Full restructure of the spec into new sections for operators, statements, scripts, functions, lambdas, and regexes. Split of operators into 6 sections, a table, reference, array, numeric, boolean, and general. Clean up of all operators sections. Sporadic clean up else where.
2018-06-07 20:11:56 -04:00
|
|
|
Character literals are not specified directly. Instead, use the
|
2018-05-23 16:36:58 -04:00
|
|
|
<<string-character-casting, cast operator>> to convert a `String` type value
|
|
|
|
into a `char` type value.
|