{"id":341158,"date":"2022-11-12T21:00:05","date_gmt":"2022-11-12T21:00:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=341158"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=341158","title":{"rendered":"<span>\u042f\u041f \u0441 \u043d\u0443\u043b\u044f \u0434\u043e \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430 (\u041b\u0435\u043a\u0441\u0435\u0440) #1<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0445\u0430\u0431\u0440\u0435. \u041f\u043e\u043f\u0440\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0435\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0442\u0430\u043a.<\/p>\n<p><strong>UPD: <\/strong>\u0411\u044b\u043b\u0430 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043d\u0430 \u043f\u043e\u043a\u0430 \u043b\u0435\u0436\u0430\u043b\u0430 \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435<br \/><strong>UPD<\/strong>: \u0418 \u0435\u0449\u0451 \u0440\u0430\u0437\u043e\u043a<\/p>\n<h2>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h2>\n<p>\u0418\u0434\u0435\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u042f\u041f \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0430\u0432\u043d\u043e, \u043d\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u043b\u043e \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044e. \u041e\u0442\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u043e \u0442\u043e, \u0447\u0442\u043e \u043a\u0440\u0443\u043f\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0433\u043e\u0434\u0430\u043c\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u0441\u0432\u043e\u0438 \u044f\u0437\u044b\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b, \u0430 \u0442\u0443\u0442 \u044f \u0445\u043e\u0447\u0443 \u043e\u0431\u043e\u0439\u0442\u0438 \u0438\u0445 \u0432\u0441\u0435\u0445 \u0440\u0430\u0437\u043e\u043c \u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u042f\u041f. \u041d\u043e \u0441 \u0447\u0435\u0433\u043e&#8212;\u0442\u043e \u0432\u0441\u0451 \u0442\u0430\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c. \u0425\u043e\u0442\u044f \u0431\u044b \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440 \u0443\u0436\u0435 \u0431\u044b \u0431\u044b\u043b \u043f\u043e\u0431\u0435\u0434\u043e\u0439. \u0414\u0430\u043b\u0435\u0435 \u044f \u0431\u0443\u0434\u0443 \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u044f\u0437\u044b\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f &#8212; <strong>Lize<\/strong>(\u0447\u0438\u0442\u0430\u0439 <em>&#171;\u041b\u0430\u0439\u0437&#187;<\/em>).<\/p>\n<p><strong>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/strong>: \u042f \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u044e \u043f\u0440\u043e \u0442\u043e \u043a\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u042f\u041f, \u044f \u0431\u0443\u0434\u0443 \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u0432\u0441\u0451 \u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e<\/p>\n<h2>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c?<\/h2>\n<p>\u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438\u0437 Lize \u0432 Typescript, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 &#8230; Typescript. \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0431\u0443\u0434\u0443\u0449\u0435\u0433\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430, \u0442\u043e \u043f\u043e\u043a\u0430 \u044d\u0442\u043e \u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u043d\u0438\u0439. \u0412 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u044f \u0431\u0443\u0434\u0443 \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u043d\u0430 <a href=\"https:\/\/github.com\/LIMPIX31\/lize\/tree\/HabrLexer\" rel=\"noopener noreferrer nofollow\">github<\/a>.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u0436\u0435 \u0433\u0443\u0433\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043b\u043e \u043c\u043d\u0435 \u0437\u043d\u0430\u043d\u0438\u0435 \u043e \u0442\u0430\u043a\u0438\u0445 \u0432\u0435\u0449\u0430\u0445 \u043a\u0430\u043a <strong>\u041b\u0435\u043a\u0441\u0435\u0440, \u041f\u0430\u0440\u0441\u0435\u0440, AST (\u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0435 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e)<\/strong>. \u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u044e \u043f\u0440\u043e \u0434\u0432\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445, \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043a\u0430 \u043f\u0440\u043e \u043d\u0438\u0445 \u0438 \u043d\u0430\u0447\u043d\u0451\u043c \u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043b\u0435\u043a\u0441\u0435\u0440?<\/h2>\n<p><strong>\u041b\u0435\u043a\u0441\u0435\u0440 <\/strong>&#8212; \u043e\u043d \u0436\u0435 \u0441\u043a\u0430\u043d\u0435\u0440, \u043e\u043d \u0436\u0435 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440. \u041f\u0435\u0440\u0432\u044b\u0439 \u044d\u0442\u0430\u043f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0437\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u044f\u0437\u044b\u043a\u0435 (<strong>Lize<\/strong>) \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u0439\u043c\u0451\u0442 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 (\u043d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043e\u0431\u043e\u0439\u0434\u0451\u043c\u0441\u044f \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u044f\u0446\u0438\u0435\u0439\/\u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u042f\u041f \u0432 TypeScript)<\/p>\n<p>\u0412 \u043c\u043e\u0435\u0439 \u0433\u043e\u043b\u043e\u0432\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a\u0430\u044f \u0432\u0435\u0449\u044c \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \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 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 <strong>id<\/strong> \u0438 <strong>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/strong>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4d4\/d64\/a94\/4d4d64a9465dd91121d6724252347b7a.png\" width=\"1322\" height=\"140\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4d4\/d64\/a94\/4d4d64a9465dd91121d6724252347b7a.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0435\u0433\u043e \u0442\u0430\u043a:<code>[\u0438\u043c\u044f: \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435] <\/code>\u0438\u043b\u0438 \u0442\u0430\u043a:<code>(\u0441\u0442\u0440\u043e\u043a\u0430:\u0441\u0442\u043e\u043b\u0431\u0435\u0446;\u0448\u0438\u0440\u0438\u043d\u0430) [\u0438\u043c\u044f: \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435]<\/code>.<\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0443\u0442\u043e\u0447\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b \u0437\u0432\u0451\u0437\u0434\u043e\u0447\u043a\u0438 \u0438\u043b\u0438 \u0441\u043b\u044d\u0448 \u043d\u0438 \u0432 \u043a\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u0437\u043d\u0430\u043a\u043e\u043c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u042d\u0442\u0430\u043f \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a \u043d\u0430 \u0442\u043e\u043a\u0435\u043d\u044b, \u0430 \u043f\u043e\u0442\u043e\u043c \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c, \u044d\u0442\u043e \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<pre><code class=\"javascript\">\/\/ \u274c \u041d\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e tokenize(`4 * 3 \/ 2`) \/\/ [number: 4], [multiply], [number: 3], [divide], [number: 2] \/\/ \u2705 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e tokenize(`4 * 3 \/ 2`) \/\/ [number: 4], [asterisk], [number: 3], [slash], [number: 2]<\/code><\/pre>\n<p>\u042f \u043b\u044e\u0431\u043b\u044e \u043f\u0438\u0441\u0430\u0442\u044c \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0451 <s>\u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c<\/s> \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u0435\u0435. \u0422\u0430\u043a \u0447\u0442\u043e \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u044b\u043c \u0438\u043b\u0438 \u0441\u0442\u0440\u0430\u0448\u043d\u044b\u043c, \u043d\u043e \u043c\u043d\u0435 \u043e\u0442 \u043d\u0435\u0433\u043e \u043d\u0430 \u0434\u0443\u0448\u0435 \u043b\u0435\u0433\u0447\u0435.<\/p>\n<h2>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/h2>\n<p>\u041c\u044b \u0436\u0435 \u043b\u044e\u0431\u0438\u043c \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0448 \u043b\u044e\u0431\u0438\u043c\u044b\u0439 \u042f\u041f \u0442\u044b\u043a\u0430\u0435\u0442 \u043d\u0430\u043c \u043d\u043e\u0441\u043e\u043c \u0442\u0443\u0434\u0430 \u0433\u0434\u0435 \u043c\u044b \u043e\u0431\u043b\u0430\u0436\u0430\u043b\u0438\u0441\u044c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u0440\u0430\u0437 \u0438 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>error<\/code> \u044d\u0442\u043e \u043c\u0430\u0433\u0438\u044f JS \u0438 TS, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443. \u042f \u043e\u043f\u0443\u0441\u0442\u0438\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u0434\u0430\u0431\u044b \u043d\u0435 \u043d\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e, \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/LIMPIX31\/lize\/blob\/HabrLexer\/packages\/common\/utils\/error.ts#L4-L10\" rel=\"noopener noreferrer nofollow\">github<\/a>.<\/p>\n<pre><code class=\"typescript\">\/\/ \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043e\u0448\u0438\u0431\u043e\u043a export namespace LexerErrors {   export const SampleError =        error('SampleError', 'Sample error message')   export const ErrorWithArgument =        error&lt;[string]>('ErrorWithArgument', 'Argument: {}')   export const UnexpectedCharacter =        error&lt;[line: number, column: number]>('UnexpectedCharacter', 'Unexpected character at {}:{}') }  \/\/ \u041f\u0440\u0438\u043c\u0435\u0440 throw new SampleError throw new ErrorWithArgument('hey') throw new UnexpectedCharacter(1, 2)<\/code><\/pre>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043b\u0435\u043a\u0441\u0435\u0440\u0430<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0442\u043e\u043a\u0435\u043d\u0430 \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0423 \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u044f\/\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0435\u0433\u043e \u043e\u043f\u043e\u0437\u043d\u0430\u0442\u044c, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0430, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0447\u0438\u0441\u043b\u043e \u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0438 \u0435\u0433\u043e \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 <code>Span<\/code>, \u0423 \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u0440\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u044d\u0442\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043d\u0430\u0447\u0430\u043b\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0438 \u0435\u0433\u043e \u043a\u043e\u043d\u0435\u0446, \u043c\u0435\u0442\u043e\u0434 <code>width<\/code>, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0441\u0442\u0440\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u0442\u043e\u043a\u0435\u043d\u0430. \u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u0442\u044f\u043d\u0443\u0442\u044c \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430<\/p>\n<pre><code class=\"typescript\">export class Span {   constructor(     private readonly src: string,     readonly start: number,     readonly end: number,   ) {}    get width() {     return this.end - this.start   }    get line() {     return (this.src.slice(0, this.start).match(\/\\n\/g) || '').length   }    get column() {     const lines = this.src.slice(0, this.start).split('\\n')     if(lines.length === 1) return this.start     return this.start - lines.slice(0, lines.length - 1).join('\\n').length - 1   } }<\/code><\/pre>\n<p>\u041d\u0443 \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c <code>Token<\/code>. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0442\u043e\u043a\u0435\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441, \u0430 \u0442\u043e\u0447\u043d\u0435\u0435 \u0435\u0433\u043e \u0438\u043c\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u044d\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b \u0437\u0432\u0451\u0437\u0434\u043e\u0447\u043a\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>token instanceof Asterisk <\/code><\/p>\n<pre><code class=\"typescript\">export class Token {   constructor(readonly value: string, readonly span: Span) {} }  \/\/ \u0422\u0438\u043f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0437\u0436\u0435 export type TokenKind = typeof Token<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 <code>tokenize<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u044b, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f \u0434\u043b\u0438\u043d\u0443 \u0442\u043e\u043a\u0435\u043d\u0430. \u0415\u0441\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0451\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e <strong>-1<\/strong>, \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u043e\u043a\u0435\u043d \u043d\u0430\u0439\u0442\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c. \u041c\u044b \u043d\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e <code>Token<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0431\u0435\u0437 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u0438\u043d\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443<\/p>\n<pre><code class=\"typescript\">static tokenize(src: string): number {   throw new AbstractToken \/\/ Abstract token can't be used }<\/code><\/pre>\n<p>\u0418\u0441\u043a\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u044b \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u044d\u0442\u043e \u043d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u043e. \u0410 \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0449\u0435 \u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u044b \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u0438\u043b\u0434\u0435\u0440. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0431\u0438\u0442\u044c \u0441 \u0442\u043e\u043b\u043a\u0443, \u043d\u043e \u043f\u043e \u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430 \u043d\u0430\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0442\u043e\u043a\u0435\u043d\u0430.<\/p>\n<pre><code class=\"typescript\">\/\/ \u041f\u0430\u0447\u043a\u0430 \u0442\u0438\u043f\u043e\u0432 type GroupString = string | RegExp type GroupValue = GroupString | (() => GroupString) type ConditionFn = () => boolean type Subscriber = (result: number) => void  interface Condition {   not?: boolean   fn: ConditionFn }  interface Group {   value: GroupValue   main?: boolean   escape?: boolean }  \/\/ \"\u041c\u0430\u043a\u0440\u043e\u0441\" \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0438\u0434\u043e\u0432 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 export const kind = (name: string) => {   const Class = namedClass(class extends Token {     \/\/ \u0413\u0440\u0443\u043f\u043f\u044b \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438, \u043f\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0430\u0441\u0442\u0438 \u043e\u0434\u043d\u043e\u0433\u043e     \/\/ \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f     private static readonly _groups: Group[] = []     \/\/ \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u043f\u0440\u0438 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0442\u043e\u043a\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f     private static readonly _conditions: Condition[] = []     \/\/ \u041f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0438. \u041e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u044b \u0435\u0441\u043b\u0438 \u0442\u043e\u043a\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0439\u0434\u0435\u043d     private static readonly _subscribers: Subscriber[] = []      \/\/ Regex \u0433\u0440\u0443\u043f\u043f\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0430     \/\/ resolveGroup \u0432\u0435\u0440\u043d\u0451\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u0443\u044e \u0433\u0440\u0443\u043f\u043f\u0443,     \/\/ \u0435\u0441\u043b\u0438 \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c     private static resolveGroup(group: GroupValue) {       return typeof group === 'function' ? group() : group     }      \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0443(\u044b)     static group(...parts: GroupValue[]): typeof Class {       Class._groups.push(...parts.map(value => ({ value })))       return Class     }      \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0433\u0440\u0443\u043f\u043f\u0443,     \/\/ \u0442\u0443, \u0434\u043b\u0438\u043d\u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043b\u0435\u043a\u0441\u0435\u0440     static main(part: GroupValue): typeof Class {       Class._groups.push({ value: part, main: true })       return Class     }      \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u044e\u0449\u0435\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435(\u044f)     static allow(...conditions: ConditionFn[]): typeof Class {       Class._conditions.push(...conditions.map(fn => ({ fn })))       return Class     }      \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u044e\u0449\u0435\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435(\u044f)     static disallow(...conditions: ConditionFn[]): typeof Class {       Class._conditions.push(...conditions.map(fn => ({ fn, not: true })))       return Class     }      \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0443 \u0434\u043b\u044f \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     static plain(text: GroupValue): typeof Class {       Class._groups.push({ value: text, escape: true, main: true })       return Class     }      \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0430     static on(...subscriber: Subscriber[]): typeof Class {       Class._subscribers.push(...subscriber)       return Class     }      \/\/ \u041e\u043f\u043e\u0432\u0435\u0449\u0430\u0435\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432 \u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438     private static emit(value: number) {       Class._subscribers.forEach(s => s(value))     }      \/\/ \u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435     \/\/ \u043f\u0440\u0438 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439     private static compile(doMatch = true): RegExp | undefined {       \/\/ \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0443\u0441\u043b\u043e\u0432\u0438\u0439       for (const condition of this._conditions) {         \/\/ \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442         let result = condition.fn()         \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u043d\u0430 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u044b\u0439, \u0435\u0441\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u0438 \u0447\u0435\u0440\u0435\u0437         \/\/ disallow         if (condition.not) result = !result         if (!result) {           doMatch = false           return         }       }       \/\/ \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435       return RegExp(`^${this._groups.map(g => {         \/\/ \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0443         const group = Class.resolveGroup(g.value)         \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0430\u0437\u043d\u044b\u0435 \u043a\u0435\u0439\u0441\u044b \u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e         \/\/ \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0433\u0440\u0443\u043f\u043f\u044b         const value = typeof group === 'object' ? group.source : g.escape ? escapeRegex(group) : group         \/\/ \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0443         return `(${value})`       }).join('')}`)     }      \/\/ \u041f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u0435\u043c 1, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u0435\u0442\u043e\u0434 match \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442     \/\/ \u0432\u0441\u0451 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435, \u0430 \u043f\u043e\u0442\u043e\u043c \u0433\u0440\u0443\u043f\u043f\u044b.     \/\/ \u0418 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043a\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u043e, \u0435\u0441\u043b\u0438 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u043d\u0435\u0442,     \/\/ \u0442\u043e \u0431\u0435\u0440\u0451\u043c \u0432\u0441\u0451, \u0442\u043a -1 + 1 = 0, \u0430 0 \u044d\u0442\u043e \u0432\u0441\u0451 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435     private static getMainIndex() {       return Class._groups.findIndex(g => g.main === true) + 1     }      \/\/ \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438     static tokenize(src: string) {       \/\/ \u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435\u0442, \u0442\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d       const regex = Class.compile()       if (!regex) return -1       \/\/ \u043c\u0430\u0442\u0447\u0438\u043c \u0441\u0442\u0440\u043e\u043a\u0443       const matches = src.match(regex)       if (!matches) return -1       \/\/ \u0411\u0435\u0440\u0451\u043c \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0433\u0440\u0443\u043f\u043f\u0443       const result: number = matches[Class.getMainIndex()].length       \/\/ \u041e\u043f\u043e\u0432\u0435\u0449\u0430\u0435\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432 \u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u043d\u0430\u0445\u043e\u0434\u043a\u0435       if (result >= 0) Class.emit(result)       \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0434\u043b\u0438\u043d\u0443 \u0442\u043e\u043a\u0435\u043d\u0430       return result     }   }, name)   return Class } <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0432\u0438\u0434\u043e\u0432 \u0442\u043e\u043a\u0435\u043d\u043e\u0432. \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0447\u0435\u0433\u043e-\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e. \u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435.  <\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a\u0438\u0435 \u0432\u0438\u0434\u044b \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u0442\u0443\u0442 \u043d\u0430\u0439\u0442\u0438: \u0427\u0438\u0441\u043b\u043e, \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u041a\u0440\u0443\u0433\u043b\u0430\u044f \u0421\u043a\u043e\u0431\u043a\u0430, \u0417\u0430\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u041a\u0440\u0443\u0433\u043b\u0430\u044f \u0421\u043a\u043e\u0431\u043a\u0430, \u0417\u0432\u0451\u0437\u0434\u043e\u0447\u043a\u0430, \u0421\u043b\u044d\u0448 \u0438 \u041f\u0440\u043e\u0431\u0435\u043b(\u0434\u0430, \u043c\u044b \u0435\u0433\u043e \u0442\u043e\u0436\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u043c)<\/p>\n<pre><code class=\"typescript\">\/\/ scripts\/1.ts const src = `(2 * 3) \/ 6`  const Number = kind('Number').main(\/\\d+\/) const Asterisk = kind('Asterisk').plain('*') const Slash = kind('Slash').plain('\/') const OpenParen = kind('OpenParen').plain('(') const CloseParen = kind('CloseParen').plain(')') const Whitespace = kind('Whitespace').main(\/[^\\S\\r\\n]+\/)<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043a\u043b\u0430\u0441\u0441\u0443 \u043b\u0435\u043a\u0441\u0435\u0440\u0430. \u042f \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441.<\/p>\n<pre><code class=\"typescript\">export class Lexer {   \/\/ \u0414\u043b\u0438\u043d\u0430 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430   private index = 0    constructor(     \/\/ \u0411\u0435\u0440\u0451\u043c \u043d\u0430 \u0432\u0445\u043e\u0434 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a     private src: string,     \/\/ \u0412\u0438\u0434\u044b(kinds) \u0442\u043e\u043a\u0435\u043d\u043e\u0432     private readonly kinds: TokenKind[],   ) {}    next() { \/* ... *\/}    \/\/ \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440   [Symbol.iterator]() {     return {       next: () => {         return { done: this.done, value: this.next() }       },     }   }    \/\/ \u0412\u0435\u0440\u043d\u0443\u0442\u044c true \u0435\u0441\u043b\u0438 \u0432\u0441\u0451 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438   get done() {     return this.index === this.src.length   } }<\/code><\/pre>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>next<\/code>. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u0432\u0438\u0434\u044b \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0438 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u043d\u0438\u0445 \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430, \u0435\u0441\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 <code>tokenize<\/code> \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0438\u0434\u0430 \u0442\u043e\u043a\u0435\u043d\u0430 \u043d\u0435 \u0432\u0435\u0440\u043d\u0451\u0442 \u0447\u0438\u0441\u043b\u043e \u0431\u043e\u043b\u044c\u0448\u0435 <strong>-1<\/strong>, \u0442\u043e \u043a\u0438\u0434\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443: <em>&#171;\u041d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d&#187; <\/em>\u0438\u043d\u0430\u0447\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0442\u043e\u043a\u0435\u043d\u0430.<\/p>\n<pre><code class=\"typescript\">next() {   \/\/ \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u0440\u043e\u0445\u043e\u0434 \u043f\u043e \u0432\u0441\u0435\u043c \u0432\u0438\u0434\u0430\u043c \u0442\u043e\u043a\u0435\u043d\u043e\u0432   for (const kind of this.kinds) {     \/\/ \u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 this.index     const result = kind.tokenize?.(this.src.slice(this.index)) ?? -1\\     \/\/ \u0415\u0441\u043b\u0438 \u043d\u0435 \u043d\u0430\u0448\u043b\u0438, \u0442\u043e \u0438\u0434\u0451\u043c \u0434\u0430\u043b\u044c\u0448\u0435     if (result === -1) continue     \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0442\u043e\u043a\u0435\u043d\u0430 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c this.index     return new kind(this.src.slice(this.index, this.index + result), new Span(this.src, this.index, this.index += result))   }   \/\/ \u0415\u0441\u043b\u0438 \u043d\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043d\u0435 \u0434\u0430\u043b \u043e \u0441\u0435\u0431\u0435 \u0437\u043d\u0430\u0442\u044c,   \/\/ \u0442\u043e \u043c\u044b \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u043d\u0430 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0443\u044e \u0438\u043b\u0438 \u043d\u0435\u0432\u0435\u0440\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b   throw new UnexpectedToken }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0432\u0441\u0435\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432.<\/p>\n<pre><code class=\"typescript\">export const tokenize = (lexer: Lexer) => {   const tokens: Token[] = []   while (!lexer.done) tokens.push(lexer.next())   return tokens }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u044b \u0432 <strong>\u043d\u0443\u0436\u043d\u043e\u043c<\/strong> \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/p>\n<pre><code class=\"typescript\">const kinds = [Number, Asterisk, Slash, OpenParen, CloseParen, Whitespace]  const result = tokenize(new Lexer(src, kinds))  \/\/ (0:0;1)  [OpenParen: (] \/\/ (0:1;1)  [Number: 2]    \/\/ (0:2;1)  [Whitespace: \u2022] \/\/ (0:3;1)  [Asterisk: *] \/\/ (0:4;1)  [Whitespace: \u2022] \/\/ (0:5;1)  [Number: 3] \/\/ (0:6;1)  [CloseParen: )] \/\/ (0:7;1)  [Whitespace: \u2022] \/\/ (0:8;1)  [Slash: \/] \/\/ (0:9;1)  [Whitespace: \u2022] \/\/ (0:10;1) [Number: 6]<\/code><\/pre>\n<h4>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/h4>\n<p><code>console.time<\/code> \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 <strong>0.3ms <\/strong>\u0434\u043b\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u0448\u0435, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0442\u0430\u0440\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u043a\u043e\u043b\u043e <strong>2.75ms<\/strong>. \u041d\u0435 \u0437\u043d\u0430\u044e \u0445\u043e\u0440\u043e\u0448\u043e \u044d\u0442\u043e \u0438\u043b\u0438 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c; \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043d\u0430 <strong>rust<\/strong> \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u0442\u043e\u043a\u0435\u043d\u044b. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u044f \u0440\u0430\u0437\u0431\u0435\u0440\u0443\u0441\u044c \u043c\u044b \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043f\u0430\u0440\u0441\u0435\u0440\u0430.<\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e \u0442\u0430\u043a\u0436\u0435, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u0434 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0438\u0437 <a href=\"https:\/\/github.com\/LIMPIX31\/lize\/tree\/HabrLexer\" rel=\"noopener noreferrer nofollow\">github <\/a>\u0441\u043e \u0432\u0441\u0435\u043c \u043a\u043e\u0434\u043e\u043c \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u0442\u0443\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d. \u042f \u043f\u043e\u043d\u0438\u043c\u0430\u044e, \u0447\u0442\u043e \u043b\u0435\u043a\u0441\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u043a, \u043d\u043e \u044d\u0442\u043e \u0432\u044b \u0438 \u0442\u0430\u043a \u043d\u0430\u0439\u0434\u0451\u0442\u0435 \u0432 \u0433\u0443\u0433\u043b\u0435, \u044f \u0436\u0435 \u0441\u0442\u0440\u0435\u043c\u043b\u044e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u044b\u043c, \u044f \u043f\u043e\u043d\u0438\u043c\u0430\u044e, \u0447\u0442\u043e \u043d\u0435 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u0435\u043d \u0442\u0443\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439, \u0432\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0434\u0430\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<\/p>\n<h4>\u0411\u043e\u043d\u0443\u0441<\/h4>\n<p>\u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443<\/p>\n<pre><code class=\"javascript\">const src = \"`I'm ${8 * 2}!`\"<\/code><\/pre>\n<pre><code class=\"typescript\">\/\/ \u0412\u0438\u0434\u044b \u0442\u043e\u043a\u0435\u043d\u043e\u0432. \u041c\u044b \u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \/\/ \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u043e\u0438\u0441\u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u0437 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043b\u0435\u043a\u0441\u0435\u0440\u0430 const Plain = kind('Plain').main(\/.+?\/).group(\/\\${|}|`\/) const Asterisk = kind('Asterisk').plain('*') const Number = kind('Number').main(\/\\d+\/) const Whitespace = kind('Whitespace').main(\/[^\\S\\r\\n]+\/) const Backtick = kind('Backtick').plain('`') const OpenDollarBrace = kind('OpenDollarBrace').main(\/\\${\/) const CloseBrace = kind('CloseBrace').main(\/}\/)<\/code><\/pre>\n<pre><code class=\"typescript\">\/\/ \u0420\u0430\u0441\u0448\u0438\u044f\u0440\u0435\u043c \u043b\u0435\u043a\u0441\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 class CustomLexer extends Lexer {   private template = false    constructor(src: string) {     \/\/ \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043f\u043e\u0438\u0441\u043a\u0430.      \/\/ \u041e\u0431\u044b\u0447\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442, \u0438\u0449\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438     Plain.allow(() => this.template)     \/\/ \u0421\u0438\u043c\u0432\u043e\u043b \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 (`) \u0435\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c, \u0442\u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435     Backtick.on(() => this.template = !this.template)     \/\/ \u041d\u0430\u0447\u0430\u043b\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0438\u0449\u0435\u043c \u0435\u0441\u043b\u0438 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438,     \/\/ \u0435\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c, \u0412\u042b\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0440\u0435\u0436\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438     OpenDollarBrace       .allow(() => this.template)       .on(() => this.template = false)     \/\/ \u041a\u043e\u043d\u0435\u0446 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0438\u0449\u0435\u043c \u0435\u0441\u043b\u0438 \u041d\u0415 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438     \/\/ \u0435\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c, \u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0440\u0435\u0436\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438     CloseBrace       .disallow(() => this.template)       .on(() => this.template = true)     \/\/ \u0422\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439 \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u0430\u0436\u0435\u043d     \/\/ Plain \u0431\u0435\u0440\u0451\u0442 \u043b\u044e\u0431\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438 \u0435\u0441\u043b\u0438 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435,      \/\/ \u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \"\u0441\u044a\u0435\u0441\u0442\" \u043d\u0430\u0447\u0430\u043b\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f     super(src, [Backtick, OpenDollarBrace, CloseBrace, Asterisk, Number, Whitespace, Plain])   } }<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/p>\n<pre><code class=\"typescript\">const result = tokenize(new CustomLexer(src))  \/\/ (0:0;1)  [Backtick: `] \/\/ (0:1;4)  [Plain: I'm\u2022] \/\/ (0:5;2)  [OpenDollarBrace: ${] \/\/ (0:7;1)  [Number: 8] \/\/ (0:8;1)  [Whitespace: \u2022] \/\/ (0:9;1)  [Asterisk: *] \/\/ (0:10;1) [Whitespace: \u2022] \/\/ (0:11;1) [Number: 2] \/\/ (0:12;1) [CloseBrace: }] \/\/ (0:13;1) [Plain: !] \/\/ (0:14;1) [Backtick: `]<\/code><\/pre>\n<p>\u0410 \u0447\u0451 \u0442\u0430\u043c \u0441 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0435\u0439?<\/p>\n<pre><code class=\"typescript\">const recursive = \"`Hey ${`I'm recursive ${2 * 3}`}`\"<\/code><\/pre>\n<p>\u042f \u043f\u0440\u044f\u043c \u043f\u043e\u0442\u0435\u043b \u043a\u043e\u0433\u0434\u0430 \u0441\u043c\u043e\u0442\u0440\u0435\u043b \u043d\u0430 \u0442\u0430\u043a\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u043d\u043e \u043b\u0435\u043a\u0441\u0435\u0440 \u0441\u0434\u0435\u043b\u0430\u043b \u0441\u0432\u043e\u0451 \u0434\u0435\u043b\u043e<\/p>\n<pre><code>(0:0;1)  [Backtick: `] (0:1;4)  [Plain: Hey\u2022] (0:5;2)  [OpenDollarBrace: ${] (0:7;1)  [Backtick: `] (0:8;14) [Plain: I'm\u2022recursive\u2022] (0:22;2) [OpenDollarBrace: ${] (0:24;1) [Number: 2] (0:25;1) [Whitespace: \u2022] (0:26;1) [Asterisk: *] (0:27;1) [Whitespace: \u2022] (0:28;1) [Number: 3] (0:29;1) [CloseBrace: }] (0:30;1) [Backtick: `] (0:31;1) [CloseBrace: }] (0:32;1) [Backtick: `]<\/code><\/pre>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0447\u0442\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0412\u0421\u0401, \u041f\u0420\u042f\u041c \u0412\u0421\u0401. \u041e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e. \u0411\u0443\u0434\u0443 \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0434 \u043e\u0446\u0435\u043d\u043a\u0435 \u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044e.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \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\/post\/698990\/\"> https:\/\/habr.com\/ru\/post\/698990\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0445\u0430\u0431\u0440\u0435. \u041f\u043e\u043f\u0440\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0435\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0442\u0430\u043a.<\/p>\n<p><strong>UPD: <\/strong>\u0411\u044b\u043b\u0430 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043d\u0430 \u043f\u043e\u043a\u0430 \u043b\u0435\u0436\u0430\u043b\u0430 \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435<br \/><strong>UPD<\/strong>: \u0418 \u0435\u0449\u0451 \u0440\u0430\u0437\u043e\u043a<\/p>\n<h2>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h2>\n<p>\u0418\u0434\u0435\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u042f\u041f \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0430\u0432\u043d\u043e, \u043d\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u043b\u043e \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044e. \u041e\u0442\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u043e \u0442\u043e, \u0447\u0442\u043e \u043a\u0440\u0443\u043f\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0433\u043e\u0434\u0430\u043c\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u0441\u0432\u043e\u0438 \u044f\u0437\u044b\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b, \u0430 \u0442\u0443\u0442 \u044f \u0445\u043e\u0447\u0443 \u043e\u0431\u043e\u0439\u0442\u0438 \u0438\u0445 \u0432\u0441\u0435\u0445 \u0440\u0430\u0437\u043e\u043c \u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u042f\u041f. \u041d\u043e \u0441 \u0447\u0435\u0433\u043e&#8212;\u0442\u043e \u0432\u0441\u0451 \u0442\u0430\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c. \u0425\u043e\u0442\u044f \u0431\u044b \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440 \u0443\u0436\u0435 \u0431\u044b \u0431\u044b\u043b \u043f\u043e\u0431\u0435\u0434\u043e\u0439. \u0414\u0430\u043b\u0435\u0435 \u044f \u0431\u0443\u0434\u0443 \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u044f\u0437\u044b\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f &#8212; <strong>Lize<\/strong>(\u0447\u0438\u0442\u0430\u0439 <em>&#171;\u041b\u0430\u0439\u0437&#187;<\/em>).<\/p>\n<p><strong>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/strong>: \u042f \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u044e \u043f\u0440\u043e \u0442\u043e \u043a\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u042f\u041f, \u044f \u0431\u0443\u0434\u0443 \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u0432\u0441\u0451 \u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e<\/p>\n<h2>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c?<\/h2>\n<p>\u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438\u0437 Lize \u0432 Typescript, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 &#8230; Typescript. \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0431\u0443\u0434\u0443\u0449\u0435\u0433\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430, \u0442\u043e \u043f\u043e\u043a\u0430 \u044d\u0442\u043e \u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u043d\u0438\u0439. \u0412 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u044f \u0431\u0443\u0434\u0443 \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u043d\u0430 <a href=\"https:\/\/github.com\/LIMPIX31\/lize\/tree\/HabrLexer\" rel=\"noopener noreferrer nofollow\">github<\/a>.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u0436\u0435 \u0433\u0443\u0433\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043b\u043e \u043c\u043d\u0435 \u0437\u043d\u0430\u043d\u0438\u0435 \u043e \u0442\u0430\u043a\u0438\u0445 \u0432\u0435\u0449\u0430\u0445 \u043a\u0430\u043a <strong>\u041b\u0435\u043a\u0441\u0435\u0440, \u041f\u0430\u0440\u0441\u0435\u0440, AST (\u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0435 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e)<\/strong>. \u041d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u044e \u043f\u0440\u043e \u0434\u0432\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445, \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043a\u0430 \u043f\u0440\u043e \u043d\u0438\u0445 \u0438 \u043d\u0430\u0447\u043d\u0451\u043c \u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043b\u0435\u043a\u0441\u0435\u0440?<\/h2>\n<p><strong>\u041b\u0435\u043a\u0441\u0435\u0440 <\/strong>&#8212; \u043e\u043d \u0436\u0435 \u0441\u043a\u0430\u043d\u0435\u0440, \u043e\u043d \u0436\u0435 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440. \u041f\u0435\u0440\u0432\u044b\u0439 \u044d\u0442\u0430\u043f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0437\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u044f\u0437\u044b\u043a\u0435 (<strong>Lize<\/strong>) \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u0439\u043c\u0451\u0442 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 (\u043d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043e\u0431\u043e\u0439\u0434\u0451\u043c\u0441\u044f \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u044f\u0446\u0438\u0435\u0439\/\u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u042f\u041f \u0432 TypeScript)<\/p>\n<p>\u0412 \u043c\u043e\u0435\u0439 \u0433\u043e\u043b\u043e\u0432\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a\u0430\u044f \u0432\u0435\u0449\u044c \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \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 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 <strong>id<\/strong> \u0438 <strong>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/strong>.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0435\u0433\u043e \u0442\u0430\u043a:<code>[\u0438\u043c\u044f: \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435] <\/code>\u0438\u043b\u0438 \u0442\u0430\u043a:<code>(\u0441\u0442\u0440\u043e\u043a\u0430:\u0441\u0442\u043e\u043b\u0431\u0435\u0446;\u0448\u0438\u0440\u0438\u043d\u0430) [\u0438\u043c\u044f: \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435]<\/code>.<\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0443\u0442\u043e\u0447\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b \u0437\u0432\u0451\u0437\u0434\u043e\u0447\u043a\u0438 \u0438\u043b\u0438 \u0441\u043b\u044d\u0448 \u043d\u0438 \u0432 \u043a\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u0437\u043d\u0430\u043a\u043e\u043c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u042d\u0442\u0430\u043f \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a \u043d\u0430 \u0442\u043e\u043a\u0435\u043d\u044b, \u0430 \u043f\u043e\u0442\u043e\u043c \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c, \u044d\u0442\u043e \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<pre><code class=\"javascript\">\/\/ \u274c \u041d\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e tokenize(`4 * 3 \/ 2`) \/\/ [number: 4], [multiply], [number: 3], [divide], [number: 2] \/\/ \u2705 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e tokenize(`4 * 3 \/ 2`) \/\/ [number: 4], [asterisk], [number: 3], [slash], [number: 2]<\/code><\/pre>\n<p>\u042f \u043b\u044e\u0431\u043b\u044e \u043f\u0438\u0441\u0430\u0442\u044c \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0451 <s>\u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c<\/s> \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u0435\u0435. \u0422\u0430\u043a \u0447\u0442\u043e \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u044b\u043c \u0438\u043b\u0438 \u0441\u0442\u0440\u0430\u0448\u043d\u044b\u043c, \u043d\u043e \u043c\u043d\u0435 \u043e\u0442 \u043d\u0435\u0433\u043e \u043d\u0430 \u0434\u0443\u0448\u0435 \u043b\u0435\u0433\u0447\u0435.<\/p>\n<h2>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/h2>\n<p>\u041c\u044b \u0436\u0435 \u043b\u044e\u0431\u0438\u043c \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0448 \u043b\u044e\u0431\u0438\u043c\u044b\u0439 \u042f\u041f \u0442\u044b\u043a\u0430\u0435\u0442 \u043d\u0430\u043c \u043d\u043e\u0441\u043e\u043c \u0442\u0443\u0434\u0430 \u0433\u0434\u0435 \u043c\u044b \u043e\u0431\u043b\u0430\u0436\u0430\u043b\u0438\u0441\u044c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u0440\u0430\u0437 \u0438 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>error<\/code> \u044d\u0442\u043e \u043c\u0430\u0433\u0438\u044f JS \u0438 TS, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443. \u042f \u043e\u043f\u0443\u0441\u0442\u0438\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u0434\u0430\u0431\u044b \u043d\u0435 \u043d\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e, \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/LIMPIX31\/lize\/blob\/HabrLexer\/packages\/common\/utils\/error.ts#L4-L10\" rel=\"noopener noreferrer nofollow\">github<\/a>.<\/p>\n<pre><code class=\"typescript\">\/\/ \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043e\u0448\u0438\u0431\u043e\u043a export namespace LexerErrors {   export const SampleError =        error('SampleError', 'Sample error message')   export const ErrorWithArgument =        error&lt;[string]>('ErrorWithArgument', 'Argument: {}')   export const UnexpectedCharacter =        error&lt;[line: number, column: number]>('UnexpectedCharacter', 'Unexpected character at {}:{}') }  \/\/ \u041f\u0440\u0438\u043c\u0435\u0440 throw new SampleError throw new ErrorWithArgument('hey') throw new UnexpectedCharacter(1, 2)<\/code><\/pre>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043b\u0435\u043a\u0441\u0435\u0440\u0430<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0442\u043e\u043a\u0435\u043d\u0430 \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0423 \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u044f\/\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0435\u0433\u043e \u043e\u043f\u043e\u0437\u043d\u0430\u0442\u044c, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0430, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0447\u0438\u0441\u043b\u043e \u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0438 \u0435\u0433\u043e \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 <code>Span<\/code>, \u0423 \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u0440\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u044d\u0442\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043d\u0430\u0447\u0430\u043b\u043e \u0442\u043e\u043a\u0435\u043d\u0430 \u0438 \u0435\u0433\u043e \u043a\u043e\u043d\u0435\u0446, \u043c\u0435\u0442\u043e\u0434 <code>width<\/code>, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0441\u0442\u0440\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u0442\u043e\u043a\u0435\u043d\u0430. \u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u0442\u044f\u043d\u0443\u0442\u044c \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430<\/p>\n<pre><code class=\"typescript\">export class Span {   constructor(     private readonly src: string,     readonly start: number,     readonly end: number,   ) {}    get width() {     return this.end - this.start   }    get line() {     return (this.src.slice(0, this.start).match(\/\\n\/g) || '').length   }    get column() {     const lines = this.src.slice(0, this.start).split('\\n')     if(lines.length === 1) return this.start     return this.start - lines.slice(0, lines.length - 1).join('\\n').length - 1   } }<\/code><\/pre>\n<p>\u041d\u0443 \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c <code>Token<\/code>. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0442\u043e\u043a\u0435\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441, \u0430 \u0442\u043e\u0447\u043d\u0435\u0435 \u0435\u0433\u043e \u0438\u043c\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u044d\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b \u0437\u0432\u0451\u0437\u0434\u043e\u0447\u043a\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>token instanceof Asterisk <\/code><\/p>\n<pre><code class=\"typescript\">export class Token {   constructor(readonly value: string, readonly span: Span) {} }  \/\/ \u0422\u0438\u043f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0437\u0436\u0435 export type TokenKind = typeof Token<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 <code>tokenize<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u044b, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f \u0434\u043b\u0438\u043d\u0443 \u0442\u043e\u043a\u0435\u043d\u0430. \u0415\u0441\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0451\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e <strong>-1<\/strong>, \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u043e\u043a\u0435\u043d \u043d\u0430\u0439\u0442\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c. \u041c\u044b \u043d\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e <code>Token<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0431\u0435\u0437 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u0438\u043d\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443<\/p>\n<pre><code class=\"typescript\">static tokenize(src: string): number {   throw new AbstractToken \/\/ Abstract token can't be used }<\/code><\/pre>\n<p>\u0418\u0441\u043a\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u044b \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u044d\u0442\u043e \u043d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u043e. \u0410 \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0449\u0435 \u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u044b \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u0438\u043b\u0434\u0435\u0440. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0431\u0438\u0442\u044c \u0441 \u0442\u043e\u043b\u043a\u0443, \u043d\u043e \u043f\u043e \u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430 \u043d\u0430\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0442\u043e\u043a\u0435\u043d\u0430.<\/p>\n<pre><code class=\"typescript\">\/\/ \u041f\u0430\u0447\u043a\u0430 \u0442\u0438\u043f\u043e\u0432 type GroupString = string | RegExp type GroupValue = GroupString | (() => GroupString) type ConditionFn = () => boolean type Subscriber = (result: number) => void  interface Condition {   not?: boolean   fn: ConditionFn }  interface Group {   value: GroupValue   main?: boolean   escape?: boolean }  \/\/ \"\u041c\u0430\u043a\u0440\u043e\u0441\" \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0438\u0434\u043e\u0432 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 export const kind = (name: string) => {   const Class = namedClass(class extends Token {     \/\/ \u0413\u0440\u0443\u043f\u043f\u044b \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438, \u043f\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0430\u0441\u0442\u0438 \u043e\u0434\u043d\u043e\u0433\u043e     \/\/ \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f     private static readonly _groups: Group[] = []     \/\/ \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u043f\u0440\u0438 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0442\u043e\u043a\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f     private static readonly _conditions: Condition[] = []     \/\/ \u041f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0438. \u041e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u044b \u0435\u0441\u043b\u0438 \u0442\u043e\u043a\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0439\u0434\u0435\u043d     private static readonly _subscribers: Subscriber[] = []      \/\/ Regex \u0433\u0440\u0443\u043f\u043f\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0430     \/\/ resolveGroup \u0432\u0435\u0440\u043d\u0451\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u0443\u044e \u0433\u0440\u0443\u043f\u043f\u0443,     \/\/ \u0435\u0441\u043b\u0438 \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c     private static resolveGroup(group: GroupValue) {       return typeof group === 'function' ? group() : group     }      \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0443(\u044b)     static group(...parts: GroupValue[]): typeof Class {       Class._groups.push(...parts.map(value => ({ value })))       return Class     }      \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0433\u0440\u0443\u043f\u043f\u0443,     \/\/ \u0442\u0443, \u0434\u043b\u0438\u043d\u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043b\u0435\u043a\u0441\u0435\u0440     static main(part: GroupValue): typeof Class {       Class._groups.push({ value: part, main: true })       return Class     }      \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u044e\u0449\u0435\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435(\u044f)     static allow(...conditions: ConditionFn[]): typeof Class {       Class._conditions.push(...conditions.map(fn => ({ fn })))       return Class     }      \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u044e\u0449\u0435\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435(\u044f)     static disallow(...conditions: ConditionFn[]): typeof Class {       Class._conditions.push(...conditions.map(fn => ({ fn, not: true })))       return Class     }      \/\/ \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0443 \u0434\u043b\u044f \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     static plain(text: GroupValue): typeof Class {       Class._groups.push({ value: text, escape: true, main: true })       return Class     }      \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0430     static on(...subscriber: Subscriber[]): typeof Class {       Class._subscribers.push(...subscriber)       return Class     }      \/\/ \u041e\u043f\u043e\u0432\u0435\u0449\u0430\u0435\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432 \u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438     private static emit(value: number) {       Class._subscribers.forEach(s => s(value))     }      \/\/ \u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435     \/\/ \u043f\u0440\u0438 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439     private static compile(doMatch = true): RegExp | undefined {       \/\/ \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0443\u0441\u043b\u043e\u0432\u0438\u0439       for (const condition of this._conditions) {         \/\/ \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442         let result = condition.fn()         \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u043d\u0430 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u044b\u0439, \u0435\u0441\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u0438 \u0447\u0435\u0440\u0435\u0437         \/\/ disallow         if (condition.not) result = !result         if (!result) {           doMatch = false           return         }       }       \/\/ \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435       return RegExp(`^${this._groups.map(g => {         \/\/ \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0443         const group = Class.resolveGroup(g.value)         \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0430\u0437\u043d\u044b\u0435 \u043a\u0435\u0439\u0441\u044b \u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e         \/\/ \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0433\u0440\u0443\u043f\u043f\u044b         const value = typeof group === 'object' ? group.source : g.escape ? escapeRegex(group) : group         \/\/ \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0443         return `(${value})`       }).join('')}`)     }      \/\/ \u041f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u0435\u043c 1, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u0435\u0442\u043e\u0434 match \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442     \/\/ \u0432\u0441\u0451 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435, \u0430 \u043f\u043e\u0442\u043e\u043c \u0433\u0440\u0443\u043f\u043f\u044b.     \/\/ \u0418 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043a\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u043e, \u0435\u0441\u043b\u0438 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u043d\u0435\u0442,     \/\/ \u0442\u043e \u0431\u0435\u0440\u0451\u043c \u0432\u0441\u0451, \u0442\u043a -1 + 1 = 0, \u0430 0 \u044d\u0442\u043e \u0432\u0441\u0451 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435     private static getMainIndex() {       return Class._groups.findIndex(g => g.main === true) + 1     }      \/\/ \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0446\u0438\u0438     static tokenize(src: string) {       \/\/ \u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435\u0442, \u0442\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d       const regex = Class.compile()       if (!regex) return -1       \/\/ \u043c\u0430\u0442\u0447\u0438\u043c \u0441\u0442\u0440\u043e\u043a\u0443       const matches = src.match(regex)       if (!matches) return -1       \/\/ \u0411\u0435\u0440\u0451\u043c \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0433\u0440\u0443\u043f\u043f\u0443       const result: number = matches[Class.getMainIndex()].length       \/\/ \u041e\u043f\u043e\u0432\u0435\u0449\u0430\u0435\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432 \u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u043d\u0430\u0445\u043e\u0434\u043a\u0435       if (result >= 0) Class.emit(result)       \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0434\u043b\u0438\u043d\u0443 \u0442\u043e\u043a\u0435\u043d\u0430       return result     }   }, name)   return Class } <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0432\u0438\u0434\u043e\u0432 \u0442\u043e\u043a\u0435\u043d\u043e\u0432. \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0447\u0435\u0433\u043e-\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e. \u0422\u043e\u043a\u0435\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435.  <\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a\u0438\u0435 \u0432\u0438\u0434\u044b \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u0442\u0443\u0442 \u043d\u0430\u0439\u0442\u0438: \u0427\u0438\u0441\u043b\u043e, \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u041a\u0440\u0443\u0433\u043b\u0430\u044f \u0421\u043a\u043e\u0431\u043a\u0430, \u0417\u0430\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u041a\u0440\u0443\u0433\u043b\u0430\u044f \u0421\u043a\u043e\u0431\u043a\u0430, \u0417\u0432\u0451\u0437\u0434\u043e\u0447\u043a\u0430, \u0421\u043b\u044d\u0448 \u0438 \u041f\u0440\u043e\u0431\u0435\u043b(\u0434\u0430, \u043c\u044b \u0435\u0433\u043e \u0442\u043e\u0436\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u043c)<\/p>\n<pre><code class=\"typescript\">\/\/ scripts\/1.ts const src = `(2 * 3) \/ 6`  const Number = kind('Number').main(\/\\d+\/) const Asterisk = kind('Asterisk').plain('*') const Slash = kind('Slash').plain('\/') const OpenParen = kind('OpenParen').plain('(') const CloseParen = kind('CloseParen').plain(')') const Whitespace = kind('Whitespace').main(\/[^\\S\\r\\n]+\/)<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043a\u043b\u0430\u0441\u0441\u0443 \u043b\u0435\u043a\u0441\u0435\u0440\u0430. \u042f \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441.<\/p>\n<pre><code class=\"typescript\">export class Lexer {   \/\/ \u0414\u043b\u0438\u043d\u0430<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-341158","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341158","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=341158"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341158\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=341158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=341158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=341158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}