painless-comments.asciidoc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. [[painless-comments]]
  2. === Comments
  3. Use a comment to annotate or explain code within a script. Use the `//` token
  4. anywhere on a line to specify a single-line comment. All characters from the
  5. `//` token to the end of the line are ignored. Use an opening `/*` token and a
  6. closing `*/` token to specify a multi-line comment. Multi-line comments can
  7. start anywhere on a line, and all characters in between the `/*` token and `*/`
  8. token are ignored. A comment is included anywhere within a script.
  9. *Grammar*
  10. [source,ANTLR4]
  11. ----
  12. SINGLE_LINE_COMMENT: '//' .*? [\n\r];
  13. MULTI_LINE_COMMENT: '/*' .*? '*/';
  14. ----
  15. *Examples*
  16. * Single-line comments.
  17. +
  18. [source,Painless]
  19. ----
  20. // single-line comment
  21. int value; // single-line comment
  22. ----
  23. +
  24. * Multi-line comments.
  25. +
  26. [source,Painless]
  27. ----
  28. /* multi-
  29. line
  30. comment */
  31. int value; /* multi-
  32. line
  33. comment */ value = 0;
  34. int value; /* multi-line
  35. comment */
  36. /* multi-line
  37. comment */ int value;
  38. int value; /* multi-line
  39. comment */ value = 0;
  40. int value; /* multi-line comment */ value = 0;
  41. ----