{"id":307950,"date":"2020-08-04T09:01:01","date_gmt":"2020-08-04T09:01:01","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=307950"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=307950","title":{"rendered":"\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 ANTLR: \u043f\u0438\u0448\u0435\u043c \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0443 Ruby"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/solarsecurity\/blog\/512974\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/go\/yh\/gm\/goyhgmx__zahdygauwq6psi3uvw.png\" alt=\"image\" align=\"left\"> \u0412 \u00ab\u0420\u043e\u0441\u0442\u0435\u043b\u0435\u043a\u043e\u043c-\u0421\u043e\u043b\u0430\u0440\u00bb \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043a\u043e\u0434\u0430 \u043d\u0430 \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u041d\u0414\u0412, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043d\u0430 \u0434\u0435\u0440\u0435\u0432\u044c\u044f\u0445 \u0440\u0430\u0437\u0431\u043e\u0440\u0430. \u0414\u043b\u044f \u0438\u0445 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043c\u044b \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f <a href=\"https:\/\/github.com\/tunnelvisionlabs\/antlr4\">\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439<\/a> <a href=\"https:\/\/www.antlr.org\/\">ANTLR4<\/a> \u2013 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u0432, \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u0432 \u0438 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0442\u043e\u0440\u043e\u0432.<\/p>\n<p>  \u0412 <a href=\"https:\/\/github.com\/antlr\/grammars-v4\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a> \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u044f\u0437\u044b\u043a\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u043d\u0435\u043c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0430 Ruby, \u043a\u043e\u0442\u043e\u0440\u0443\u044e, \u043f\u043e \u0432\u0441\u0435\u0439 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u043d\u0438\u043a\u0442\u043e \u0442\u0430\u043a \u0438 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b. <a href=\"https:\/\/github.com\/antlr\/grammars-v4\/tree\/master\/ruby\">\u0415\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0430 \u043f\u043e\u0445\u043e\u0436\u0435\u0433\u043e \u0441\u0430\u043c\u043e\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430<\/a>, \u043f\u0430\u0440\u0441\u044f\u0449\u0430\u044f \u043b\u0438\u0448\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0435 \u0441\u043b\u0443\u0447\u0430\u0438. \u042d\u0442\u043e \u043d\u0435\u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u0435\u0434\u044c \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0443 Ruby \u0441\u043b\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u044f\u0437\u044b\u043a \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u043e\u043c. \u041d\u043e \u043e\u043d\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u043b\u0430\u0441\u044c \u0431\u044b \u0442\u0435\u043c, \u043a\u0442\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u0445\u043e\u0447\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u044f\u0437\u044b\u043a \u0438 \u0437\u0430\u0434\u0443\u043c\u0430\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0418\u043b\u0438 \u0442\u0435\u043c, \u043a\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0435 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435. \u041d\u0443 \u0447\u0442\u043e \u0436\u0435 \u2013 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0443, \u0447\u0435\u043c \u043f\u0440\u044f\u043c\u043e \u0437\u0434\u0435\u0441\u044c \u0438 \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f.<\/p>\n<p>  <a name=\"habracut\"><\/a><br \/>  \u0412 ANTLR \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0437 \u044f\u0437\u044b\u043a\u0430 \u043d\u0430 \u043b\u0435\u043a\u0441\u0435\u0440 \u0438 \u043f\u0430\u0440\u0441\u0435\u0440.<\/p>\n<p>  \u041b\u0435\u043a\u0441\u0435\u0440 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0442\u043e\u043a\u0435\u043d\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438\u0437 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430 \u044f\u0437\u044b\u043a\u0430. \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0438\u0434\u043b\u0438\u043d\u043d\u0435\u0439\u0448\u0438\u0439, \u0430 \u0441\u0440\u0435\u0434\u0438 \u0442\u0430\u043a\u0438\u0445 \u2013 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u0443 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u043c \u0437\u0430\u043f\u0438\u0441\u0438).<\/p>\n<p>  \u041f\u0430\u0440\u0441\u0435\u0440 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b) \u044f\u0437\u044b\u043a\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u043e\u043a\u0435\u043d\u043e\u0432 (\u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438), \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u044b\u0445 \u0438\u0437 \u043b\u0435\u043a\u0441\u0435\u0440\u0430.<\/p>\n<p>  \u0412 \u0446\u0435\u043b\u043e\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0438 \u043d\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432. \u041d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/pragprog.com\/titles\/tpantlr2\/\">\u0430\u0432\u0442\u043e\u0440\u0441\u043a\u043e\u0439 \u043a\u043d\u0438\u0433\u0438<\/a>, <a href=\"https:\/\/github.com\/antlr\/antlr4\/blob\/master\/doc\/index.md\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> \u0438\u043b\u0438 \u043f\u043e \u043c\u043d\u043e\u0433\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430\u043c \u0432\u0440\u043e\u0434\u0435 <a href=\"https:\/\/tomassetti.me\/antlr-mega-tutorial\/\">\u044d\u0442\u043e\u0433\u043e<\/a>.<\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0443\u0449\u0435\u043d\u0430 \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u043b\u0438\u0448\u044c \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f.<\/p>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043b\u0435\u043a\u0441\u0435\u0440\u0430<\/h2>\n<p>  \u0412 \u043e\u0431\u0449\u0435\u043c \u0438 \u0446\u0435\u043b\u043e\u043c, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0430\u044f \u0432 \u043b\u0435\u043a\u0441\u0435\u0440\u0435, \u2013 \u044d\u0442\u043e \u0432\u044b\u0434\u0430\u0447\u0430 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u043f\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438 \u0441\u043e\u043f\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u044f.<\/p>\n<h4>\u0418\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u044f<\/h4>\n<p>  \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 Ruby \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u044e \u2013 \u0432\u0441\u0442\u0430\u0432\u043a\u0443 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432\u043d\u0443\u0442\u0440\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 <code>#{code}<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"ruby\">a = 3 &quot;Hello #{if a%2==1 then &quot;Habr!&quot; else &quot;World!&quot; end}&quot; <\/code><\/pre>\n<p>  \u0421\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0431\u0443\u0434\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0440\u0435\u0436\u0438\u043c\u043e\u0432 \u2013 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0445 \u00ab\u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445 \u043b\u0435\u043a\u0441\u0435\u0440\u043e\u0432\u00bb, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u0432\u0440\u043e\u0434\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"java\">DoubleQuote: '&quot;' {++nestedStringLevel;}    -&gt; pushMode(InterpolationString); <\/code><\/pre>\n<p>  \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0441\u043a\u043e\u0431\u043e\u043a \u0438\u0437-\u0437\u0430 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439 \u0432\u0438\u0434\u0430 (\u0432\u044b\u0439\u0442\u0438 \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u043d\u0430 2-\u0439 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u0444\u0438\u0433\u0443\u0440\u043d\u043e\u0439 \u0441\u043a\u043e\u0431\u043a\u0435):<\/p>\n<pre><code class=\"ruby\">&quot;Kappa #{     buf = ''     [1, 2, 3].each { |x| buf += x.to_s }     buf }&quot; <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0434\u0435\u043c \u0441\u0442\u0435\u043a <code>openedCurlyBracesInsideString<\/code>. \u0418\u0442\u043e\u0433\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u043e\u0434\u0430 \u0438\u043c\u0435\u0435\u043c \u0442\u043e\u043a\u0435\u043d:<\/p>\n<pre><code class=\"java\">StartInterpolation: '#{' {openedCurlyBracesInsideString.push(0);}    -&gt; pushMode(DEFAULT_MODE); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u043e\u0432\u0440\u0435\u043c\u044f \u0432\u044b\u0439\u0442\u0438 \u0438\u0437 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u0440\u0435\u0436\u0438\u043c\u0430 (DEFAULT_MODE), \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u0434 \u0432 \u0442\u043e\u043a\u0435\u043d\u044b:<\/p>\n<pre><code class=\"java\">OpenCurlyBracket:             '{' {     if (nestedStringLevel &gt; 0 &amp;&amp; !openedCurlyBracesInsideString.empty()) {         final int buf = openedCurlyBracesInsideString.pop();         openedCurlyBracesInsideString.push(buf + 1);     } }; CloseCurlyBracket:            '}' {     if (nestedStringLevel &gt; 0 &amp;&amp; openedCurlyBracesInsideString.peek() &lt;= 0) {        popMode();        openedCurlyBracesInsideString.pop();     } else {         if (!openedCurlyBracesInsideString.empty()) {             final int buf = openedCurlyBracesInsideString.pop();             openedCurlyBracesInsideString.push(buf - 1);         }     } }; <\/code><\/pre>\n<p>  <\/p>\n<h4>%-\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <\/h4>\n<p>  <a href=\"http:\/\/www.chrisrolle.com\/en\/blog\/ruby-percentage-notations\">\u0412 Ruby \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 Perl \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f<\/a> \u0441\u0442\u0440\u043e\u043a, \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0441\u0442\u0440\u043e\u043a \u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 Ruby \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u043c \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438), \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438 \u0448\u0435\u043b\u043b-\u043a\u043e\u043c\u0430\u043d\u0434. \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0442\u0430\u043a\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u0442\u0430\u043a\u043e\u0432: %, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430 \u043d\u0438\u043c \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0442\u0438\u043f\u0430 \u0438 \u0441\u0438\u043c\u0432\u043e\u043b-\u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <code>%w|a b c|<\/code> \u2014 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 \u0442\u0440\u0435\u0445 \u0441\u0442\u0440\u043e\u043a. \u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f \u043f\u0430\u0440\u043d\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438: <code>{} [] () &lt;&gt;<\/code>. \u041f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u043d\u0435 \u0432\u044b\u0439\u0434\u0435\u0442 \u2013 \u0442\u043e\u0433\u0434\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/p>\n<pre><code class=\"ruby\">q = 3 5%q <\/code><\/pre>\n<p>  \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e. \u041b\u0435\u043a\u0441\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u044a\u0435\u0441\u0442 \u0441\u0430\u043c\u0443\u044e \u0434\u043b\u0438\u043d\u043d\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0441\u043e\u0437\u0434\u0430\u0432 \u0442\u043e\u043a\u0435\u043d <code>%q<\/code>.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0432 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u044f\u0432\u043d\u043e \u043d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f \u0432\u0440\u043e\u0434\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430, \u0446\u0438\u0444\u0440\u044b \u0438 \u0431\u0443\u043a\u0432\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0435\u0451 \u0432 \u0442\u043e\u043a\u0435\u043d \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430 (\u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0431\u044f\u0437\u0430\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0430),<\/p>\n<pre><code class=\"java\">StringArrayConstructorwToken: '%w' {canBeDelimiter()}?; <\/code><\/pre>\n<p>  \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u0430\u0449\u0438\u0442\u0443, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0443\u044e <b>\u043f\u043e\u0447\u0442\u0438<\/b> \u0432\u0441\u0435\u0433\u0434\u0430 (\u043e\u0431 \u044d\u0442\u043e\u043c \u0434\u0430\u043b\u0435\u0435). \u0422\u0430\u043a \u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b.<\/p>\n<pre><code class=\"java\">StartArrayConstructorNotInterpolated     : StringArrayConstructorwToken ( Brackets {setPairDelimiter();} | ~[(&lt;{[] {setCharDelimiter();} ) {startStringMode(ArrayConstructorw);}  fragment Brackets: '(' | '[' | '{' | '&lt;'; <\/code><\/pre>\n<p>  \u0433\u0434\u0435 <code>startStringMode<\/code> \u2014 utility-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0436\u0438\u043c\u0430 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"java\">public void startStringMode(final int mode) {     pushMode(mode);     ++nestedStringLevel; } <\/code><\/pre>\n<p>  <b>\u041a\u043e\u043d\u0442\u0440\u043f\u0440\u0438\u043c\u0435\u0440:<\/b> <code>5%q|1<\/code> \u2014 \u043f\u0430\u0440\u0441\u044f\u0449\u0438\u0439\u0441\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043b\u0438\u0448\u044c \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043f\u0430\u0440\u0441\u0435\u0440\u0430, \u043a\u043e\u0433\u0434\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 5-\u0442\u0438 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0431\u044b\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043f\u0430\u0440\u043d\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0437\u0430\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u043d\u0438\u044f \u0432\u043f\u0435\u0440\u0435\u0434, \u043e\u0434\u043d\u0430\u043a\u043e \u0438 \u043d\u0430 \u0442\u0430\u043a\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u2014 <code>5%q|1|1<\/code>. \u041e\u0442\u043a\u0443\u0434\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u044f\u0441\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043d\u0430 \u043b\u0435\u043a\u0441\u0435\u0440 \u0438 \u043f\u0430\u0440\u0441\u0435\u0440 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u0440\u0435\u0434\u043a\u043e, \u0442\u0430\u043a \u0447\u0442\u043e \u0441\u043e\u0439\u0434\u0435\u0442 \u00af\\_(\u30c4)_\/\u00af. \u0412\u043d\u0443\u0442\u0440\u0438 \u0440\u0435\u0436\u0438\u043c\u0430 \u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0436\u0434\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c.<\/p>\n<pre><code class=\"java\">ArraywWhitespace: WhitespaceAll                           -&gt; skip; ArraywText:       ({!isDelimiter()}? ArraywTextFragment)+ -&gt; type(StringPart); ArraywEnd:        . {nestedStringLevel--;}                -&gt; type(HereDocEnd), popMode; <\/code><\/pre>\n<p>  \u0433\u0434\u0435 <code>type<\/code> \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0442\u0438\u043f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430.<\/p>\n<h4>\u0414\u0435\u043b\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043d\u0430\u0447\u0430\u043b\u043e \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/h4>\n<p>  \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0432 <code>\/regexp\/<\/code> (\u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u0430\u044f \u043d\u043e\u0442\u0430\u0446\u0438\u044f \u0441 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u043c). \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0442\u0430\u043a\u0430\u044f \u0436\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u0430\u0440\u0441\u0435\u0440\u0430, \u043a\u0430\u043a \u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0443\u043d\u043a\u0442\u0435, \u0434\u043b\u044f \u0435\u0451 \u0441\u043c\u044f\u0433\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443<\/p>\n<pre><code class=\"java\">public boolean canBeRegex() {     return isPrevWS &amp;&amp; &quot; \\t\\r\\u000B\\f\\b\\n&quot;.indexOf((char) _input.LA(1)) == -1 || isPrevNL || isOp || prevNonWsType == StartInterpolation; } <\/code><\/pre>\n<p>  \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0442\u043e\u043a\u0435\u043d<\/p>\n<pre><code class=\"java\">Divide:                       '\/' {     if (canBeRegex()) {         startHereDoc(RegExp);     } }; <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043f\u0435\u0440\u0435\u0441\u0447\u0435\u0442\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 <code>isOp<\/code>, <code>isPrevNL<\/code>, <code>isPrevWS<\/code> \u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c <code>emit<\/code>-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0430<\/p>\n<pre><code class=\"java\">@Override public void emit(final Token token) {     final String txt = token.getText();     final int type = token.getType();     isPrevNL = type == NL;     isPrevWS = type == WS;     if (!isPrevWS &amp;&amp; !isPrevNL &amp;&amp; type != SingleLineComment &amp;&amp; type != MultiLineComment) {         isOp = OPERATORS.contains(type);         prevNonWsChar = txt.charAt(txt.length() - 1);         prevNonWsType = type;     }     super.emit(token); } <\/code><\/pre>\n<p>  \u0433\u0434\u0435 <code>OPERATORS<\/code> \u2013 hashmap \u0432\u0441\u0435\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432.<\/p>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0430\u0440\u0441\u0435\u0440\u0430 <\/h2>\n<p>  <\/p>\n<h4>\u041f\u0440\u043e\u0431\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b <\/h4>\n<p>  \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u043c \u0441\u044e\u0440\u043f\u0440\u0438\u0437\u043e\u043c \u0441\u0442\u0430\u043b\u043e \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432 \u043d\u0430 \u043f\u0430\u0440\u0441\u0438\u043d\u0433. \u041e\u0431\u044b\u0447\u043d\u043e \u043e\u043d\u0438 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0435 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e-\u043d\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>-&gt; skip<\/code> \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u0430\u043d\u0430\u043b. \u041e\u0434\u043d\u0430\u043a\u043e \u0440\u044f\u0434 \u044f\u0437\u044b\u043a\u043e\u0432 \u0432\u0441\u0435 \u0436\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0441 \u0438\u0445 \u043f\u043e\u043c\u043e\u0449\u044c\u044e.<\/p>\n<p>  \u0422\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>a+3<\/code> \u0438 <code>a + 3<\/code> \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0435\u0437 \u0441\u043a\u043e\u0431\u043e\u043a, \u0430 <code>\u0430 +3<\/code> \u043c\u043e\u0436\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u0430\u0440\u0441\u0435\u0440\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0442\u0430\u043a (NL \u2014 newline, WS \u2014 whitespace):<\/p>\n<pre><code class=\"java\">    | expression WS* op=('+' | '-') (NL | WS)* expression <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0441\u043c\u044f\u0433\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043d\u0430\u043f\u0438\u0448\u0435\u043c <a href=\"https:\/\/github.com\/antlr\/antlr4\/blob\/master\/doc\/listeners.md\">listener <\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0447\u0438\u0441\u0442\u0438\u0442\u044c \u043d\u0430\u043c \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u043e\u0442 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u043c\u0443\u0441\u043e\u0440\u0430.<\/p>\n<pre><code class=\"java\">public class RemovingTokensListener implements ParseTreeListener {         private List&lt;Integer&gt; unwantedTokens;          ...          @Override         public void visitTerminal(final TerminalNode node) {             if (this.unwantedTokens.contains(node.getSymbol().getType())) {                 ((ParserRuleContext) node.getParent().getRuleContext()).removeLastChild();             }         } } <\/code><\/pre>\n<p>  <\/p>\n<h4>Heredoc \u2014 \u041b\u0435\u043a\u0441\u0435\u0440 \u0438 \u043f\u0430\u0440\u0441\u0435\u0440<\/h4>\n<p>  \u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0438\u043c<\/p>\n<pre><code class=\"ruby\">&lt;&lt;STR content line 1 content line 2 STR <\/code><\/pre>\n<p>  \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0442\u0430\u043a\u0438\u043c (\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e markdown \u043d\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0435\u0442 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e).<\/p>\n<pre><code class=\"ruby\">value = 123 print &lt;&lt;STR_WITH_INTERPOLATION, &lt;&lt;'STR_WITHOUT_INTERPOLATION'.strip content 1 and #{value} STR_WITH_INTERPOLATION      content 2 and #{value} STR_WITHOUT_INTERPOLATION <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0433\u0434\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u0443\u0434\u043e\u0431\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043a\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043b\u0438\u0441\u0442 \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u0445 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 heredoc-\u043e\u0432 (\u043f\u0430\u0440\u0441\u0435\u0440 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u0440\u0435\u0436\u0438\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0432\u043f\u0435\u0440\u0435\u0434)<\/p>\n<pre><code class=\"java\">public final HeredocsHolder HEREDOCS = new HeredocsHolder();  public static final class HereDocEntry {     public final String name;     public final HereDocType type;     public final boolean isInterpolated;     public int partsNumber;      public HereDocEntry(final String name, final HereDocType type, final boolean isInterpolated) {         this.name = name;         this.type = type;         this.isInterpolated = isInterpolated;         this.partsNumber = 0;     } }  public static final class HeredocsHolder {     public final List&lt;HereDocEntry&gt; entries;     public int toProcess;      HeredocsHolder() {         this.entries = new ArrayList&lt;&gt;();         this.toProcess = 0;     } } <\/code><\/pre>\n<p>  \u0438 \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0445 \u043f\u043e \u043c\u0435\u0440\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044f<\/p>\n<pre><code class=\"java\">StartHereDoc     : HereDocToken HereDocName {         heredocIdentifier = getHeredocIdentifier('\\'');         setText(getText().trim());         keepHereDoc(HereDoc, false);     }     ;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">public void keepHereDoc(final int mode, final boolean isInterpolated) {     HEREDOCS.entries.add(new HereDocEntry(heredocIdentifier, getHereDocType(), isInterpolated));     ++HEREDOCS.toProcess;     isFirstNL = true; }<\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435, \u0443\u0432\u0438\u0434\u0435\u0432 \u043a\u043e\u043d\u0435\u0446 \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u0440\u0438 \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 heredoc-\u0430\u0445, \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<pre><code class=\"java\">NL:                           '\\n' {     final int next = _input.LA(1);     if (HEREDOCS.toProcess &gt; 0 &amp;&amp; isFirstNL) {         startHereDocRoutine();         isFirstNL = false;         insideHeredoc = true;     } }; <\/code><\/pre>\n<p>  \u0421\u0430\u043c\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0430 \u043d\u0438\u0436\u0435: \u0437\u0434\u0435\u0441\u044c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043b\u0438\u0448\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 heredoc-\u0438 (\u043b\u0435\u043a\u0441\u0435\u0440 \u043c\u043e\u0433 \u0443\u0439\u0442\u0438 \u0432\u043f\u0435\u0440\u0435\u0434, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0430\u0440\u0441\u0435\u0440 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0449\u0435 \u043d\u0435 \u043f\u043e\u0433\u043b\u043e\u0442\u0438\u043b \u0442\u043e\u043a\u0435\u043d\u044b, \u0442\u0430\u043a \u0447\u0442\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e)<\/p>\n<pre><code class=\"java\">public void startHereDocRoutine() {     final int stopIdx = HEREDOCS.entries.size() - HEREDOCS.toProcess;     for (int i = HEREDOCS.entries.size() - 1; i &gt;= stopIdx; --i) {         if (HEREDOCS.entries.get(i).isInterpolated) {             pushMode(HereDocInterpolated);         } else {             pushMode(HereDoc);         }     }     nestedStringLevel += HEREDOCS.toProcess;     currentHeredocIt = HEREDOCS.entries.listIterator(HEREDOCS.entries.size() - HEREDOCS.toProcess);     currentHeredoc = currentHeredocIt.next(); } <\/code><\/pre>\n<p>  \u041d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c <code>nextToken<\/code> \u0434\u043b\u044f \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u0440\u0435\u0436\u0438\u043c\u0430 \u0438 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0447\u0438\u0441\u043b\u0430 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043a\u0430\u0436\u0434\u043e\u0433\u043e heredoc-\u0430<\/p>\n<pre><code class=\"java\">@Override public Token nextToken() {     final CommonToken token = (CommonToken)super.nextToken();     final int ttype = token.getType();     if (insideHeredoc &amp;&amp; ttype == StartInterpolation) {         ++heredocTokensCount;     }     if (_mode == HereDoc || _mode == HereDocInterpolated) {         if (ttype == VarName) {             ++heredocTokensCount;         } else if (ttype == StringPart) {             ++heredocTokensCount;             final String txt = token.getText();             if (CheckHeredocEnd(txt)) {                 token.setText(txt.trim());                 token.setType(HereDocEnd);                 nestedStringLevel--;                 popMode();                 currentHeredoc.partsNumber = heredocTokensCount;                 if (currentHeredocIt.hasNext()) {                     currentHeredoc = currentHeredocIt.next();                 }                 heredocTokensCount = 0;                 --HEREDOCS.toProcess;                 if (_mode == DEFAULT_MODE) {                     insideHeredoc = false;                 }             }         }     }     return token; } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u043c.<\/p>\n<p>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>@parser::members<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043f\u0430\u0440\u0441\u0435\u0440: \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043b\u0435\u043a\u0441\u0435\u0440, \u0443\u0437\u043b\u044b \u0441\u0442\u0440\u043e\u043a, \u043a\u0443\u0434\u0430 \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u044c \u0438\u0445 \u043a\u043e\u043d\u0442\u0435\u043d\u0442, \u0447\u0438\u0441\u043b\u043e \u0443\u0437\u043b\u043e\u0432 \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 (\u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 <code>heredocTokensCount<\/code> \u043b\u0435\u043a\u0441\u0435\u0440\u0430), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0442\u0435\u043a statement-\u043e\u0432 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<pre><code class=\"java\">    private final RubyLexer lexer = (RubyLexer)_input.getTokenSource();     private final List&lt;ParserRuleContext&gt; CONTEXTS = new ArrayList&lt;&gt;();     private final List&lt;Integer&gt; heredocRulesCount = new ArrayList&lt;&gt;();     private final Stack&lt;StatementEntry&gt; statements = new Stack&lt;&gt;();      private static final class StatementEntry {         public boolean needProcess;         public int currentHeredoc;          StatementEntry() {             this.needProcess = false;             this.currentHeredoc = 0;         }     } <\/code><\/pre>\n<p>  \u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"java\">statement @init {     statements.push(new StatementEntry()); } @after {     if (statements.peek().needProcess) {         processHeredocs($ctx);     }     statements.pop(); }     : statementWithoutHeredocTail ({statements.peek().needProcess}? interpolatedStringPart* HereDocEnd {++statements.peek().currentHeredoc;})*     ; <\/code><\/pre>\n<p>  <code>@init<\/code> \u2014 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0432\u0445\u043e\u0434\u0435 \u043f\u0430\u0440\u0441\u0435\u0440\u0430 \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u043e, <code>@after<\/code> \u2014 \u043f\u0440\u0438 \u0432\u044b\u0445\u043e\u0434\u0435.<\/p>\n<p>  \u0421\u0442\u0435\u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u043e\u0442\u043d\u0435\u0441\u0435\u043d\u0438\u044f heredoc-\u043e\u0432 \u043a \u043d\u0443\u0436\u043d\u043e\u043c\u0443 statement-\u0443, \u0442.\u043a. \u0432\u043d\u0443\u0442\u0440\u0438 \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u043e\u0432\u044b\u0435.<\/p>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0438, \u0433\u0434\u0435 heredoc \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u043c expression \u0438 \u0433\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438 \u043f\u043e\u0434\u0440\u044f\u0434, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043a\u0435\u0439\u0441\u044b, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043d\u0435\u0446 \u0441\u0442\u0440\u043e\u043a\u0438 \u0431\u0443\u0434\u0435\u0442 \u043b\u0435\u0436\u0430\u0442\u044c \u0437\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c, \u043f\u0438\u0448\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u043a\u043e\u0434 \u043f\u0430\u0440\u0441\u0435\u0440\u0430:<\/p>\n<pre><code class=\"java\">string: ...     | StartInterpolatedHereDoc (memberAccess* WS* NL interpolatedStringPart* HereDocEnd)? {         if ($ctx.HereDocEnd() == null) {             CONTEXTS.add($ctx);             heredocRulesCount.add(0);             statements.peek().needProcess = true;         } else {              lexer.HEREDOCS.entries.remove(0);         }     } ... <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u0436\u0435 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0443\u0437\u043b\u043e\u0432 \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u0434 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0441 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u043e\u043c \u0441\u0442\u0440\u043e\u043a\u0438 (<code>+ 2<\/code> \u0437\u0434\u0435\u0441\u044c \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u044e)<\/p>\n<pre><code class=\"plaintext\">interpolatedStringPart locals[int nodesCount = 0]     : StringPart     | VarName     | StartInterpolation (WS* statement {++$nodesCount;})* (WS* rawStatement {++$nodesCount;})? WS* '}' {         final int cur = statements.peek().currentHeredoc;         if (cur &lt; heredocRulesCount.size()) {             heredocRulesCount.set(cur, heredocRulesCount.get(cur) + $nodesCount + 2);         }     }     ; <\/code><\/pre>\n<p>  \u0433\u0434\u0435 <code>locals<\/code> \u2014 \u0441\u043f\u0438\u0441\u043e\u043a \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 (\u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0447\u0435\u0440\u0435\u0437 <code>$<\/code>), \u0430 \u043f\u0440\u043e\u0431\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u043d\u0435 \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f, \u0442.\u043a. \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u043d\u0430\u0448\u0438\u043c listener-\u043e\u043c.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0430\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>processHeredocs<\/code>. \u041f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0437\u043b\u043e\u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0431\u0440\u0430\u0442\u044c<\/p>\n<pre><code class=\"java\">int heredocNodesCount = 0; for (int i = 0; i &lt; CONTEXTS.size(); ++i) {     heredocNodesCount += lexer.HEREDOCS.entries.get(i).partsNumber;     heredocNodesCount += heredocRulesCount.get(i); } <\/code><\/pre>\n<p>  \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u043a\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0431\u0435\u043d\u043a\u0430, \u043d\u0430\u0447\u043d\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0441\u0442\u0440\u043e\u043a \u043f\u043e \u0441\u0432\u043e\u0438\u043c \u043c\u0435\u0441\u0442\u0430\u043c<\/p>\n<pre><code class=\"java\">int currentChild = ctx.getChildCount() - heredocNodesCount; <\/code><\/pre>\n<p>  \u041f\u043e\u0434\u0432\u0435\u0441\u0438\u043c \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u0443\u0437\u043b\u0443<\/p>\n<pre><code class=\"java\">for (int i = 0; i &lt; CONTEXTS.size(); ++i) {     final RubyLexer.HereDocEntry entry = lexer.HEREDOCS.entries.remove(0);     final ParserRuleContext currentContext = CONTEXTS.get(i);     final int currentNodesCount = entry.partsNumber + heredocRulesCount.get(i);     for (int j = 0; j &lt; currentNodesCount; ++j, ++currentChild) {         final ParseTree child = ctx.getChild(currentChild);         if (child instanceof TerminalNode) {             ((TerminalNodeImpl) child).setParent(currentContext);             currentContext.addChild((TerminalNodeImpl) child);         } else if (child instanceof ParserRuleContext) {             ((ParserRuleContext) child).setParent(currentContext);             currentContext.addChild((ParserRuleContext) child);         } else {             \/\/ parser failed             clear();             return;         }     } } <\/code><\/pre>\n<p>  \u041e\u0447\u0438\u0449\u0430\u0435\u043c \u0441\u0430\u043c \u0443\u0437\u0435\u043b, \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b heredoc-\u043e\u0432 \u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0447\u0438\u0441\u043b\u0430 \u0443\u0437\u043b\u043e\u0432 \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438<\/p>\n<pre><code class=\"java\">for (int i = 0; i &lt; heredocNodesCount; ++i) {     ctx.removeLastChild(); } clear(); <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">private void clear() {     CONTEXTS.clear();     heredocRulesCount.clear(); } <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0448\u0442\u0440\u0438\u0445\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u043e\u0435 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 heredoc-\u043e\u0432 \u2014 <code>statementWithoutHeredocTail<\/code>, \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u0432\u0435\u0448\u0438\u0432\u0430\u044f \u0434\u0435\u0442\u0435\u0439 \u0443\u0437\u043b\u0430 \u043a \u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043a\u0443, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u043e\u0433\u043e \u0436\u0435 listener-\u0430<\/p>\n<pre><code class=\"java\">public class RemovingRulesListener implements ParseTreeListener {     private List&lt;Integer&gt; unwantedRules;      ...      @Override     public void exitEveryRule(final ParserRuleContext ctx) {         if (this.unwantedRules.contains(ctx.getRuleIndex())) {             final ParserRuleContext parentCtx =                     (ParserRuleContext) ctx.getParent().getRuleContext();             parentCtx.children.remove(ctx);             ctx.children.forEach(                     child -&gt; {                         if (child instanceof RuleContext) {                             ((RuleContext) child).setParent(parentCtx);                             parentCtx.addChild((RuleContext) child);                         } else if (child instanceof TerminalNode) {                             ((TerminalNodeImpl) child).setParent(parentCtx);                             parentCtx.addChild((TerminalNodeImpl) child);                         }                     }             );         }     } } <\/code><\/pre>\n<p>  <\/p>\n<h4>Ambiguity <\/h4>\n<p>  \u041d\u0435\u0440\u0435\u0448\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u0441\u0442\u0430\u043b\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u043b\u044e\u0431\u043e\u0439 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0443\u043d\u0430\u0440\u043d\u043e\u0439 \u0438 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438), \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u043e \u043b\u0438\u0448\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435.<\/p>\n<p>  \u0421\u0443\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0432\u0445\u043e\u0434\u0435 <code>a +a +a +a...<\/code> \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0442\u0430\u043a \u0438 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0435\u0437 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 (\u0445\u043e\u0442\u044f \u0438 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 Ruby \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u043f\u0440\u043e\u0431\u0435\u043b\u0430 \u043f\u043e\u0441\u043b\u0435 \u0437\u043d\u0430\u043a\u0430 \u0443 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430), \u043e\u0442\u0447\u0435\u0433\u043e \u043f\u043e \u0432\u0441\u0435\u0439 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u043e\u0441\u0442 \u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439 \u043f\u043e \u0433\u0440\u0430\u0444\u0443 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u043e-\u043d\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c ANTLR \u043f\u0440\u043e\u0431\u0435\u043b \u043f\u043e\u0441\u043b\u0435 \u0443\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043d\u0435 \u0432\u044b\u0439\u0434\u0435\u0442 \u2014 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043b\u0435\u0432\u043e\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 expression, \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f \u0431\u0435\u0437 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u041f\u043e\u043b\u0430\u0433\u0430\u044f\u0441\u044c \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u201c\u043d\u0438\u043a\u0442\u043e\u201d \u043d\u0435 \u043f\u0438\u0448\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0442\u0440\u0438\u0434\u0446\u0430\u0442\u0438 \u0441\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0445 \u0431\u0435\u0437 \u043f\u0440\u0438\u0447\u0438\u043d\u044b, \u0434\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043e\u0442\u043f\u0430\u0434\u0430\u0435\u0442.<\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u042d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c 99% \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<p>  \u0422\u0430\u043a, <a href=\"https:\/\/github.com\/aws\/aws-sdk-ruby\">aws-sdk-ruby<\/a>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 3024 ruby-\u0444\u0430\u0439\u043b\u0430, \u043f\u0430\u0434\u0430\u0435\u0442 \u043b\u0438\u0448\u044c \u043d\u0430 \u0441\u0435\u043c\u0438, <a href=\"https:\/\/github.com\/fastlane\/fastlane\">fastlane<\/a>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 1028, \u043d\u0430 2-x, \u0430 <a href=\"https:\/\/github.com\/rails\/rails\">Ruby on Rails<\/a> c 2081, \u043d\u0430 19-\u0442\u0438.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0432\u0441\u0435 \u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e \u0431\u041e\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u043e\u0434\u0435 heredoc-\u043e\u0432, \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432 expression<\/p>\n<pre><code class=\"ruby\">option(:sts_regional_endpoints,   default: 'legacy',   doc_type: String,   docstring: &lt;&lt;-DOCS) do |cfg| Passing in 'regional' to enable regional endpoint for STS for all supported regions (except 'aws-global'), defaults to 'legacy' mode, using global endpoint for legacy regions.   DOCS   resolve_sts_regional_endpoints(cfg) end <\/code><\/pre>\n<p>  \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043a\u0430\u043a \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043b\u044e\u0431\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0431\u043b\u043e\u043a\u043e\u0432<\/p>\n<pre><code class=\"ruby\">def test_group_by_with_order_by_virtual_count_attribute     expected = { &quot;SpecialPost&quot; =&gt; 1, &quot;StiPost&quot; =&gt; 2 }     actual = Post.group(:type).order(:count).limit(2).maximum(:comments_count)     assert_equal expected, actual end if current_adapter?(:PostgreSQLAdapter) <\/code><\/pre>\n<p>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043f\u0440\u0438\u0435\u043c\u044b, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0441 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0432\u0430\u0448\u0435\u0439 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0438. \u0415\u0441\u043b\u0438 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0438\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u043b\u0443\u0447\u0448\u0435 \u2013 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438.<\/p>\n<p>  <i>\u0410\u0432\u0442\u043e\u0440: \u0424\u0435\u0434\u043e\u0440 \u0423\u0441\u043e\u0432, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a Solar appScreener<\/i><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/solarsecurity\/blog\/512974\/\"> https:\/\/habr.com\/ru\/company\/solarsecurity\/blog\/512974\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/solarsecurity\/blog\/512974\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/go\/yh\/gm\/goyhgmx__zahdygauwq6psi3uvw.png\" alt=\"image\" align=\"left\"> \u0412 \u00ab\u0420\u043e\u0441\u0442\u0435\u043b\u0435\u043a\u043e\u043c-\u0421\u043e\u043b\u0430\u0440\u00bb \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043a\u043e\u0434\u0430 \u043d\u0430 \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u041d\u0414\u0412, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043d\u0430 \u0434\u0435\u0440\u0435\u0432\u044c\u044f\u0445 \u0440\u0430\u0437\u0431\u043e\u0440\u0430. \u0414\u043b\u044f \u0438\u0445 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043c\u044b \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f <a href=\"https:\/\/github.com\/tunnelvisionlabs\/antlr4\">\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439<\/a> <a href=\"https:\/\/www.antlr.org\/\">ANTLR4<\/a> \u2013 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u0432, \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u0432 \u0438 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0442\u043e\u0440\u043e\u0432.<\/p>\n<p>  \u0412 <a href=\"https:\/\/github.com\/antlr\/grammars-v4\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a> \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u044f\u0437\u044b\u043a\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u043d\u0435\u043c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0430 Ruby, \u043a\u043e\u0442\u043e\u0440\u0443\u044e, \u043f\u043e \u0432\u0441\u0435\u0439 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u043d\u0438\u043a\u0442\u043e \u0442\u0430\u043a \u0438 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b. <a href=\"https:\/\/github.com\/antlr\/grammars-v4\/tree\/master\/ruby\">\u0415\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0430 \u043f\u043e\u0445\u043e\u0436\u0435\u0433\u043e \u0441\u0430\u043c\u043e\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430<\/a>, \u043f\u0430\u0440\u0441\u044f\u0449\u0430\u044f \u043b\u0438\u0448\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0435 \u0441\u043b\u0443\u0447\u0430\u0438. \u042d\u0442\u043e \u043d\u0435\u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u0435\u0434\u044c \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0443 Ruby \u0441\u043b\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u044f\u0437\u044b\u043a \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u043e\u043c. \u041d\u043e \u043e\u043d\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u043b\u0430\u0441\u044c \u0431\u044b \u0442\u0435\u043c, \u043a\u0442\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u0445\u043e\u0447\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u044f\u0437\u044b\u043a \u0438 \u0437\u0430\u0434\u0443\u043c\u0430\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0418\u043b\u0438 \u0442\u0435\u043c, \u043a\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0435 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435. \u041d\u0443 \u0447\u0442\u043e \u0436\u0435 \u2013 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0443, \u0447\u0435\u043c \u043f\u0440\u044f\u043c\u043e \u0437\u0434\u0435\u0441\u044c \u0438 \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-307950","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/307950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=307950"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/307950\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=307950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=307950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=307950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}