painless-lang-spec.asciidoc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. [[painless-specification]]
  2. == Painless Language Specification
  3. Painless uses a Java-style syntax that is similar to Groovy. In fact, most
  4. Painless scripts are also valid Groovy, and simple Groovy scripts are typically
  5. valid Painless. This specification assumes you have at least a passing
  6. familiarity with Java and related languages.
  7. Painless is essentially a subset of Java with some additional scripting
  8. language features that make scripts easier to write. However, there are some
  9. important differences, particularly with the casting model. For more detailed
  10. conceptual information about the basic constructs that Java and Painless share,
  11. refer to the corresponding topics in the
  12. https://docs.oracle.com/javase/specs/jls/se8/html/index.html[Java Language
  13. Specification].
  14. Painless scripts are parsed and compiled using the http://www.antlr.org/[ANTLR4]
  15. and http://asm.ow2.org/[ASM] libraries. Painless scripts are compiled directly
  16. into Java byte code and executed against a standard Java Virtual Machine. This
  17. specification uses ANTLR4 grammar notation to describe the allowed syntax.
  18. However, the actual Painless grammar is more compact than what is shown here.
  19. [float]
  20. [[comments]]
  21. ==== Comments
  22. Painless supports both single-line and multi-line comments. You can include
  23. comments anywhere within a script.
  24. Single-line comments are preceded by two slashes: `// comment`. They can be
  25. placed anywhere on a line. All characters from the two slashes to the end of
  26. the line are ignored.
  27. Multi-line comments are preceded by a slash-star `/*` and closed by
  28. star-slash `*/`. Multi-line comments can start anywhere on a line. All
  29. characters from the opening `/*` to the closing `*/` are ignored.
  30. *Examples:*
  31. [source,Java]
  32. ----
  33. // single-line comment
  34. <code> // single-line comment
  35. /* multi-
  36. line
  37. comment */
  38. <code> /* multi-line
  39. comment */ <code>
  40. <code> /* multi-line comment */ <code>
  41. ----
  42. [float]
  43. [[keywords]]
  44. ==== Keywords
  45. Painless reserves the following keywords for built-in language features.
  46. These keywords cannot be used used in other contexts, such as identifiers.
  47. [cols="^1,^1,^1,^1,^1"]
  48. |====
  49. | if | else | while | do | for
  50. | in | continue | break | return | new
  51. | try | catch | throw | this | instanceof
  52. |====
  53. include::painless-literals.asciidoc[]
  54. include::painless-variables.asciidoc[]
  55. include::painless-types.asciidoc[]
  56. include::painless-operators.asciidoc[]