Skip to content

Commit 0e697f4

Browse files
committed
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.
1 parent 5e1cef9 commit 0e697f4

20 files changed

+4777
-2152
lines changed

docs/painless/painless-casting.asciidoc

+147-79
Large diffs are not rendered by default.

docs/painless/painless-comments.asciidoc

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ anywhere on a line to specify a single-line comment. All characters from the
66
`//` token to the end of the line are ignored. Use an opening `/*` token and a
77
closing `*/` token to specify a multi-line comment. Multi-line comments can
88
start anywhere on a line, and all characters in between the `/*` token and `*/`
9-
token are ignored. Comments can be included anywhere within a script.
9+
token are ignored. A comment is included anywhere within a script.
1010

1111
*Grammar*
12+
1213
[source,ANTLR4]
1314
----
1415
SINGLE_LINE_COMMENT: '//' .*? [\n\r];
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[[painless-functions]]
2+
=== Functions
3+
4+
A function is a named piece of code comprised of one-to-many statements to
5+
perform a specific task. A function is called multiple times in a single script
6+
to repeat its specific task. A parameter is a named type value available as a
7+
<<painless-variables, variable>> within the statement(s) of a function. A
8+
function specifies zero-to-many parameters, and when a function is called a
9+
value is specified per parameter. An argument is a value passed into a function
10+
at the point of call. A function specifies a return type value, though if the
11+
type is <<void-type, void>> then no value is returned. Any non-void type return
12+
value is available for use within an <<painless-operators, operation>> or is
13+
discarded otherwise.
14+
15+
You can declare functions at the beginning of a Painless script, for example:
16+
17+
[source,painless]
18+
---------------------------------------------------------
19+
boolean isNegative(def x) { x < 0 }
20+
...
21+
if (isNegative(someVar)) {
22+
...
23+
}
24+
---------------------------------------------------------

docs/painless/painless-general-syntax.asciidoc

-81
This file was deleted.

docs/painless/painless-identifiers.asciidoc

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
Use an identifier as a named token to specify a
55
<<painless-variables, variable>>, <<painless-types, type>>,
6-
<<dot-operator, field>>, <<dot-operator, method>>, or function.
7-
<<painless-keywords, Keywords>> cannot be used as identifiers.
6+
<<field-access-operator, field>>, <<method-call-operator, method>>, or
7+
<<painless-functions, function>>.
8+
9+
*Errors*
10+
11+
If a <<painless-keywords, keyword>> is used as an identifier.
812

913
*Grammar*
1014
[source,ANTLR4]

docs/painless/painless-keywords.asciidoc

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
[[painless-keywords]]
22
=== Keywords
33

4-
Keywords are reserved tokens for built-in language features and cannot be used
5-
as <<painless-identifiers, identifiers>> within a script. The following are
6-
keywords:
4+
Keywords are reserved tokens for built-in language features.
5+
6+
*Errors*
7+
8+
If a keyword is used as an <<painless-identifiers, identifier>>.
9+
10+
*Keywords*
711

812
[cols="^1,^1,^1,^1,^1"]
913
|====
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[[painless-lambdas]]
2+
=== Lambdas
3+
Lambda expressions and method references work the same as in https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html[Java].
4+
5+
[source,painless]
6+
---------------------------------------------------------
7+
list.removeIf(item -> item == 2);
8+
list.removeIf((int item) -> item == 2);
9+
list.removeIf((int item) -> { item == 2 });
10+
list.sort((x, y) -> x - y);
11+
list.sort(Integer::compare);
12+
---------------------------------------------------------
13+
14+
You can make method references to functions within the script with `this`,
15+
for example `list.sort(this::mycompare)`.

docs/painless/painless-lang-spec.asciidoc

+19-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,22 @@ include::painless-casting.asciidoc[]
3333

3434
include::painless-operators.asciidoc[]
3535

36-
include::painless-general-syntax.asciidoc[]
36+
include::painless-operators-general.asciidoc[]
37+
38+
include::painless-operators-numeric.asciidoc[]
39+
40+
include::painless-operators-boolean.asciidoc[]
41+
42+
include::painless-operators-reference.asciidoc[]
43+
44+
include::painless-operators-array.asciidoc[]
45+
46+
include::painless-statements.asciidoc[]
47+
48+
include::painless-scripts.asciidoc[]
49+
50+
include::painless-functions.asciidoc[]
51+
52+
include::painless-lambdas.asciidoc[]
53+
54+
include::painless-regexes.asciidoc[]

docs/painless/painless-literals.asciidoc

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Use a literal to specify a value directly in an
55
<<painless-operators, operation>>.
66

7-
[[integers]]
7+
[[integer-literals]]
88
==== Integers
99

1010
Use an integer literal to specify an integer type value in decimal, octal, or
@@ -16,6 +16,7 @@ to specify an integer literal as octal, and use `0x` or `0X` as a prefix to
1616
specify an integer literal as hex.
1717

1818
*Grammar*
19+
1920
[source,ANTLR4]
2021
----
2122
INTEGER: '-'? ( '0' | [1-9] [0-9]* ) [lLfFdD]?;
@@ -44,7 +45,7 @@ HEX: '-'? '0' [xX] [0-9a-fA-F]+ [lL]?;
4445
<5> `int -18` in octal
4546
<6> `int 3882` in hex
4647

47-
[[floats]]
48+
[[float-literals]]
4849
==== Floats
4950

5051
Use a floating point literal to specify a floating point type value of a
@@ -53,6 +54,7 @@ single letter designations to specify the primitive type: `f` or `F` for `float`
5354
and `d` or `D` for `double`. If not specified, the type defaults to `double`.
5455

5556
*Grammar*
57+
5658
[source,ANTLR4]
5759
----
5860
DECIMAL: '-'? ( '0' | [1-9] [0-9]* ) (DOT [0-9]+)? EXPONENT? [fFdD]?;
@@ -78,7 +80,7 @@ EXPONENT: ( [eE] [+\-]? [0-9]+ );
7880
<4> `double -126.34`
7981
<5> `float 89.9`
8082

81-
[[strings]]
83+
[[string-literals]]
8284
==== Strings
8385

8486
Use a string literal to specify a <<string-type, `String` type>> value with
@@ -88,6 +90,7 @@ include a single-quote as part of a single-quoted string literal. Use a `\\`
8890
token to include a backslash as part of any string literal.
8991

9092
*Grammar*
93+
9194
[source,ANTLR4]
9295
----
9396
STRING: ( '"' ( '\\"' | '\\\\' | ~[\\"] )*? '"' )
@@ -114,9 +117,9 @@ STRING: ( '"' ( '\\"' | '\\\\' | ~[\\"] )*? '"' )
114117
"double-quoted with non-escaped 'single-quotes'"
115118
----
116119

117-
[[characters]]
120+
[[character-literals]]
118121
==== Characters
119122

120-
A character literal cannot be specified directly. Instead, use the
123+
Character literals are not specified directly. Instead, use the
121124
<<string-character-casting, cast operator>> to convert a `String` type value
122125
into a `char` type value.

0 commit comments

Comments
 (0)