-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Painless: Restructure Spec Documentation #31013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 96 commits
153d376
6729d5f
84048e4
10fca6c
c2c3448
1cdf013
862962b
73883ac
7dfb034
75f1498
f75d50e
956a188
bce78ed
b034cff
e82a1e0
1da1704
48b3aee
8bc0c74
275c2e7
00ba531
7bcd114
84ea43d
1cf2f0b
68059ae
73a24f0
c3fcd67
19abc56
00cf5df
0cb3e66
bc4509f
507ac48
7ad4ebb
a9c941e
0007d26
988fc23
b95ce25
a8ed00b
7b73010
8fc4566
ca2bb83
ae1ae75
a5cc47a
7b70e15
093a10f
bb4dc1c
8f9b09e
a122212
2665835
aeb879b
7165b0f
ba4b7c1
b0c2512
b1d31d1
246c824
4e2b89d
8b5316b
8302de3
7ad8379
1d64edd
0696c83
46a868e
15aac91
f85e235
6f16058
775cfff
610d67c
3b8da65
33b7357
d17c365
a2afc62
8c87bf9
5b19038
46f737f
9439b92
5aaa88a
86591c3
d54e4a0
23c2320
fba0246
73ff8a2
2b55029
bdb8eb1
4e2994a
a570d37
2e38982
c688199
542f52e
e0e7dce
603e5e5
afdc961
12fb54d
c83ecaf
be37bf1
f0bd472
c35e977
0760a41
c361792
038dd80
d20d5d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| [[painless-functions]] | ||
| === Functions | ||
|
|
||
| A function is a named piece of code comprised of one-to-many statements to | ||
| perform a specific task. A function is called multiple times in a single script | ||
| to repeat its specific task. A parameter is a named type value available as a | ||
| <<painless-variables, variable>> within the statement(s) of a function. A | ||
| function specifies zero-to-many parameters, and when a function is called a | ||
| value is specified per parameter. An argument is a value passed into a function | ||
| at the point of call. A function specifies a return type value, though if the | ||
| type is <<void-type, void>> then no value is returned. Any non-void type return | ||
| value is available for use within an <<painless-operators, operation>> or is | ||
| discarded otherwise. | ||
|
|
||
| You can declare functions at the beginning of a Painless script, for example: | ||
|
|
||
| [source,painless] | ||
| --------------------------------------------------------- | ||
| boolean isNegative(def x) { x < 0 } | ||
| ... | ||
| if (isNegative(someVar)) { | ||
| ... | ||
| } | ||
| --------------------------------------------------------- |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [[painless-lambdas]] | ||
| === Lambdas | ||
| Lambda expressions and method references work the same as in https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html[Java]. | ||
|
|
||
| [source,painless] | ||
| --------------------------------------------------------- | ||
| list.removeIf(item -> item == 2); | ||
| list.removeIf((int item) -> item == 2); | ||
| list.removeIf((int item) -> { item == 2 }); | ||
| list.sort((x, y) -> x - y); | ||
| list.sort(Integer::compare); | ||
| --------------------------------------------------------- | ||
|
|
||
| You can make method references to functions within the script with `this`, | ||
| for example `list.sort(this::mycompare)`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| Use a literal to specify a value directly in an | ||
| <<painless-operators, operation>>. | ||
|
|
||
| [[integers]] | ||
| [[integer-literals]] | ||
| ==== Integers | ||
|
|
||
| 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 | |
| specify an integer literal as hex. | ||
|
|
||
| *Grammar* | ||
|
|
||
| [source,ANTLR4] | ||
| ---- | ||
| INTEGER: '-'? ( '0' | [1-9] [0-9]* ) [lLfFdD]?; | ||
|
|
@@ -44,7 +45,7 @@ HEX: '-'? '0' [xX] [0-9a-fA-F]+ [lL]?; | |
| <5> `int -18` in octal | ||
| <6> `int 3882` in hex | ||
|
|
||
| [[floats]] | ||
| [[float-literals]] | ||
| ==== Floats | ||
|
|
||
| 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` | |
| and `d` or `D` for `double`. If not specified, the type defaults to `double`. | ||
|
|
||
| *Grammar* | ||
|
|
||
| [source,ANTLR4] | ||
| ---- | ||
| DECIMAL: '-'? ( '0' | [1-9] [0-9]* ) (DOT [0-9]+)? EXPONENT? [fFdD]?; | ||
|
|
@@ -78,7 +80,7 @@ EXPONENT: ( [eE] [+\-]? [0-9]+ ); | |
| <4> `double -126.34` | ||
| <5> `float 89.9` | ||
|
|
||
| [[strings]] | ||
| [[string-literals]] | ||
| ==== Strings | ||
|
|
||
| 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 `\\` | |
| token to include a backslash as part of any string literal. | ||
|
|
||
| *Grammar* | ||
|
|
||
| [source,ANTLR4] | ||
| ---- | ||
| STRING: ( '"' ( '\\"' | '\\\\' | ~[\\"] )*? '"' ) | ||
|
|
@@ -114,9 +117,9 @@ STRING: ( '"' ( '\\"' | '\\\\' | ~[\\"] )*? '"' ) | |
| "double-quoted with non-escaped 'single-quotes'" | ||
| ---- | ||
|
|
||
| [[characters]] | ||
| [[character-literals]] | ||
| ==== Characters | ||
|
|
||
| A character literal cannot be specified directly. Instead, use the | ||
| A character literal is not specified directly. Instead, use the | ||
| <<string-character-casting, cast operator>> to convert a `String` type value | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would change this to "Character literals are not..." It just reads strange to me in the singular. :-)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed and changed. |
||
| into a `char` type value. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beware that changing the anchors affects any cross-refs to these sections.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the head up. I've been pretty good about compiling the docs and looking at the format each time I change something significant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I'm fairly confident nothing is referring to the headers outside the book since I've added the majority of them recently.