Skip to content
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

Painless: Types Section Clean Up #30283

Merged
merged 42 commits into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
153d376
Separate identifiers into its own section. Clean up variables.
jdconrad Apr 17, 2018
6729d5f
More docs.
jdconrad Apr 18, 2018
84048e4
Merge branch 'master' into docs1
jdconrad Apr 18, 2018
10fca6c
Merge branch 'master' into docs1
jdconrad Apr 18, 2018
c2c3448
Modify language used to describe shallow copies.
jdconrad Apr 19, 2018
1cdf013
Move examples into lists to make sections flow better when multiple
jdconrad Apr 19, 2018
862962b
Update primitive types.
jdconrad Apr 20, 2018
73883ac
Cleaned up reference types.
jdconrad Apr 24, 2018
7dfb034
Clean up dynamic types.
jdconrad Apr 24, 2018
75f1498
String and void type clean up.
jdconrad Apr 25, 2018
f75d50e
Merge branch 'master' into docs2
jdconrad Apr 25, 2018
956a188
Merge branch 'master' into docs2
jdconrad Apr 27, 2018
bce78ed
Fixes.
jdconrad Apr 28, 2018
b034cff
Merge branch 'master' into docs2
jdconrad Apr 30, 2018
e82a1e0
Clean up types section.
jdconrad May 1, 2018
1da1704
Merge branch 'master' into docs2
jdconrad May 1, 2018
48b3aee
Merge branch 'master' into docs3
jdconrad May 2, 2018
8bc0c74
Some casting and example clean up.
jdconrad May 4, 2018
275c2e7
Merge branch 'master' into docs3
jdconrad May 4, 2018
00ba531
Updated examples.
jdconrad May 4, 2018
7bcd114
More changes.
jdconrad May 7, 2018
84ea43d
Merge branch 'master' into docs3
jdconrad May 8, 2018
1cf2f0b
Merge branch 'master' into docs3
jdconrad May 9, 2018
68059ae
More example clean up.
jdconrad May 9, 2018
73a24f0
More casting clean up.
jdconrad May 9, 2018
c3fcd67
More clean up.
jdconrad May 10, 2018
19abc56
More changes.
jdconrad May 14, 2018
00cf5df
Merge branch 'master' into docs3
jdconrad May 14, 2018
0cb3e66
More fixes.
jdconrad May 14, 2018
bc4509f
Merge branch 'master' into docs3
jdconrad May 14, 2018
507ac48
More example clean up.
jdconrad May 15, 2018
7ad4ebb
More changes.
jdconrad May 15, 2018
a9c941e
Finished promotion and boxing/unboxing.
jdconrad May 15, 2018
0007d26
Merge branch 'master' into docs2
jdconrad May 15, 2018
988fc23
Cleaned up casting basic on PR comments.
jdconrad May 19, 2018
b95ce25
More changes.
jdconrad May 21, 2018
a8ed00b
Merge branch 'master' into docs2
jdconrad May 21, 2018
7b73010
More fixes.
jdconrad May 21, 2018
8fc4566
Fixed casting and types based on PR feedback.
jdconrad May 22, 2018
ca2bb83
Cleaned up more.
jdconrad May 22, 2018
ae1ae75
Extra blank lines at end of docs.
jdconrad May 22, 2018
a5cc47a
Merge branch 'master' into docs2
jdconrad May 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
550 changes: 417 additions & 133 deletions docs/painless/painless-casting.asciidoc

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/painless/painless-comments.asciidoc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[[painless-comments]]
=== Comments

Use the `//` token anywhere on a line to specify a single-line comment. All
characters from the `//` token to the end of the line are ignored. Use an
opening `/*` token and a closing `*/` token to specify a multi-line comment.
Multi-line comments can start anywhere on a line, and all characters in between
the `/*` token and `*/` token are ignored. Comments can be included anywhere
within a script.
Use a comment to annotate or explain code within a script. Use the `//` token
anywhere on a line to specify a single-line comment. All characters from the
`//` token to the end of the line are ignored. Use an opening `/*` token and a
closing `*/` token to specify a multi-line comment. Multi-line comments can
start anywhere on a line, and all characters in between the `/*` token and `*/`
token are ignored. Comments can be included anywhere within a script.

*Grammar*
[source,ANTLR4]
Expand Down
8 changes: 4 additions & 4 deletions docs/painless/painless-identifiers.asciidoc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[[painless-identifiers]]
=== Identifiers

Specify identifiers to <<declaration, declare>>, <<assignment, assign>>, and
<<painless-operators, use>> variables, <<dot-operator, access fields>>, and
<<dot-operator, call methods>>. <<painless-keywords, Keywords>> and
<<painless-types, types>> cannot be used as identifiers.
Use an identifier as a named token to specify a
<<painless-variables, variable>>, <<painless-types, type>>,
<<dot-operator, field>>, <<dot-operator, method>>, or function.
<<painless-keywords, Keywords>> cannot be used as identifiers.

*Grammar*
[source,ANTLR4]
Expand Down
6 changes: 3 additions & 3 deletions docs/painless/painless-keywords.asciidoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[[painless-keywords]]
=== Keywords

The keywords in the table below are reserved for built-in language
features. These keywords cannot be used as
<<painless-identifiers, identifiers>> or <<painless-types, types>>.
Keywords are reserved tokens for built-in language features and cannot be used
as <<painless-identifiers, identifiers>> within a script. The following are
keywords:

[cols="^1,^1,^1,^1,^1"]
|====
Expand Down
2 changes: 1 addition & 1 deletion docs/painless/painless-lang-spec.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Painless syntax is similar to Java syntax along with some additional
features such as dynamic typing, Map and List accessor shortcuts, and array
initializers. As a direct comparison to Java, there are some important
differences, especially related to the casting model. For more detailed
conceptual information about the basic constructs that Java and Painless share,
conceptual information about the basic constructs that Painless and Java share,
refer to the corresponding topics in the
https://docs.oracle.com/javase/specs/jls/se8/html/index.html[Java Language
Specification].
Expand Down
52 changes: 16 additions & 36 deletions docs/painless/painless-literals.asciidoc
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
[[painless-literals]]
=== Literals

Use literals to specify different types of values directly in a script.
Use a literal to specify a value directly in an
<<painless-operators, operation>>.

[[integers]]
==== Integers

Use integer literals to specify an integer value in decimal, octal, or hex
notation of the <<primitive-types, primitive types>> `int`, `long`, `float`,
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`,
or `double`. Use the following single letter designations to specify the
<<primitive-types, 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.
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.

*Grammar*
[source,ANTLR4]
Expand Down Expand Up @@ -46,11 +47,10 @@ HEX: '-'? '0' [xX] [0-9a-fA-F]+ [lL]?;
[[floats]]
==== Floats

Use floating point literals to specify a floating point value of the
<<primitive-types, primitive types>> `float` or `double`. Use the following
single letter designations to specify the <<primitive-types, primitive type>>:
`f` or `F` for `float` and `d` or `D` for `double`. If not specified, the type defaults
to `double`.
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`.

*Grammar*
[source,ANTLR4]
Expand Down Expand Up @@ -81,7 +81,7 @@ EXPONENT: ( [eE] [+\-]? [0-9]+ );
[[strings]]
==== Strings

Use string literals to specify <<string-type, String>> values with
Use a string literal to specify a <<string-type, `String` type>> value with
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 `\\`
Expand Down Expand Up @@ -117,26 +117,6 @@ STRING: ( '"' ( '\\"' | '\\\\' | ~[\\"] )*? '"' )
[[characters]]
==== Characters

Use the <<painless-casting, casting operator>> to convert string literals or
<<string-type, String>> values into <<primitive-types, char>> values.
<<string-type, String>> values converted into
<<primitive-types, char>> values must be exactly one character in length
or an error will occur.

*Examples*

* Casting string literals into <<primitive-types, char>> values.
+
[source,Painless]
----
(char)"C"
(char)'c'
----
+
* Casting a <<string-type, String>> value into a <<primitive-types, char>> value.
+
[source,Painless]
----
String s = "s";
char c = (char)s;
----
A character literal cannot be specified directly. Instead, use the
<<string-character-casting, cast operator>> to convert a `String` type value
into a `char` type value.
47 changes: 45 additions & 2 deletions docs/painless/painless-operators.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ operator. See Function Calls [MARK] for more information.
The brackets operator `[]` is used to create and access arrays, lists, and maps.
The braces operator `{}` is used to intialize arrays.

[[array-initialization]]
===== Creating and Initializing Arrays

You create and initialize arrays using the brackets `[]` and braces `{}`
Expand All @@ -248,9 +249,49 @@ initialize each dimension with are specified as a comma-separated list enclosed
in braces. For example, `new int[] {1, 2, 3}` creates a one dimensional `int`
array with a size of 3 and the values 1, 2, and 3.

For more information about allocating and initializing arrays, see <<array-type,
Array Type>>.
To allocate an array, you use the `new` keyword followed by the type and a
set of brackets for each dimension. You can explicitly define the size of each dimension by specifying an expression within the brackets, or initialize each
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd drop the "you" and just use the imperative: "To allocate an array, use..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation was moved from another location to here, and I was hoping to address this as part of an operators clean up in the next PR if that's all right with you.

dimension with the desired number of values. The allocated size of each
dimension is its permanent size.

To initialize an array, specify the values you want to initialize
each dimension with as a comma-separated list of expressions enclosed in braces.
For example, `new int[] {1, 2, 3}` creates a one-dimensional `int` array with a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd cut "specify the values you want to initialize each dimension with as".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the comment above.

size of 3 and the values 1, 2, and 3.

When you initialize an array, the order of the expressions is maintained. Each expression used as part of the initialization is converted to the
array's type. An error occurs if the types do not match.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd cut "used as part of the initialization".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the comment above.


*Grammar:*
[source,ANTLR4]
----
declare_array: TYPE ('[' ']')+;
array_initialization: 'new' TYPE '[' ']' '{' expression (',' expression) '}'
| 'new' TYPE '[' ']' '{' '}';
----

*Examples:*
[source,Java]
----
int[] x = new int[5]; // Declare int array x and assign it a newly
// allocated int array with a size of 5
def[][] y = new def[5][5]; // Declare the 2-dimensional def array y and
// assign it a newly allocated 2-dimensional
// array where both dimensions have a size of 5
int[] x = new int[] {1, 2, 3}; // Declare int array x and set it to an int
// array with values 1, 2, 3 and a size of 3
int i = 1;
long l = 2L;
float f = 3.0F;
double d = 4.0;
String s = "5";
def[] da = new def[] {i, l, f*d, s}; // Declare def array da and set it to
// a def array with a size of 4 and the
// values i, l, f*d, and s
----

[[array-access]]
===== Accessing Array Elements

Elements in an array are stored and accessed using the brackets `[]` operator.
Expand Down Expand Up @@ -298,6 +339,7 @@ return d[z]; // Access the 1st element of array d using the
NOTE: The use of the `def` type in the second example means that the types
cannot be resolved until runtime.

[[array-length]]
===== Array Length

Arrays contain a special member known as 'length' that is a read-only value that contains the size of the array. This member can be accessed from an array using the dot operator.
Expand Down Expand Up @@ -727,6 +769,7 @@ def e; // declares the def variable e
e = new HashMap(m); // sets e to a newly allocated HashMap using the constructor with a single argument m
----

[[new-array]]
==== New Array

An array type instance can be allocated using the new operator. The format starts with the new operator followed by the type followed by a series of opening and closing braces each containing an expression for the size of the dimension.
Expand Down
Loading