{
    "componentChunkName": "component---src-templates-doc-page-js",
    "path": "/docs/en/JS_API/variables/parseTree/",
    "result": {"data":{"site":{"siteMetadata":{"title":"Gatsby-doc-engine"}},"markdownRemark":{"id":"138fa19e-8e38-52e2-ab99-e24447a91092","excerpt":"This object contains the result of parsing the request in accordance with existing named patterns, as well as return values of converters.  is a hierarchical…","html":"<h1><code class=\"language-text\">$parseTree</code></h1>\n<hr>\n<p>This object contains the result of parsing the request in accordance with existing named patterns, as well as return values of converters.</p>\n<p><code class=\"language-text\">$parseTree</code> is a hierarchical structure, with each level of embedding corresponding to its token, beginning from the root one.</p>\n<p>A single level of <code class=\"language-text\">$parseTree</code> looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$parseTree: {\n  tag:\n  pattern:\n  text:\n  words:\n  value:\n  TokenByName: &lt;$parseTree> // embedded tokens\n        ...\n    }</code></pre></div>\n<p>Here:</p>\n<ul>\n<li><code class=\"language-text\">tag</code> — is the name of the token as it appears in <code class=\"language-text\">$parseTree</code>;</li>\n<li><code class=\"language-text\">pattern</code> — is the name of the named pattern which has matched some text in the request;</li>\n<li><code class=\"language-text\">text</code> —  is the <code class=\"language-text\">string</code> representation of the request;</li>\n<li><code class=\"language-text\">words</code> — is an array of tokens;</li>\n<li><code class=\"language-text\">value</code> — is an attribute present when using mappings, converters, and named entities;</li>\n<li><code class=\"language-text\">TokenByName</code> — is a named pattern.</li>\n</ul>\n</br>\n<h4>How to use</h4>\n<ul>\n<li>Let us construct a parse tree for the following phrase: <code class=\"language-text\">What is the weather like in St Petersburg</code>?</li>\n</ul>\n<p>The following named patterns will be used:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$Question = (what|which)\n$Weather = (weather|forecast)\n$City = ([St] Petersburg|Moscow)\nq: * [$Question] * $Weather * $City *</code></pre></div>\n<p>Then the parse tree will look as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$parseTree: {\n    \"tag\": \"root\",\n    \"pattern\": \"root\",\n    \"text\": \"What is the weather like in St Petersburg\",\n    \"words\": [\n        \"what\",\n        \"is\",\n        \"the\",\n        \"weather\",\n        \"like\",\n        \"in\",\n        \"st\",\n        \"petersburg\"\n    ],\n    \"Question\": [\n        {\n            \"tag\": \"Question\",\n            \"pattern\": \"Question\",\n            \"text\": \"What\",\n            \"words\": [\n                \"what\"\n            ]\n        }\n    ],\n    \"Weather\": [\n        {\n            \"tag\": \"Weather\",\n            \"pattern\": \"Weather\",\n            \"text\": \"weather\",\n            \"words\": [\n                \"weather\"\n            ]\n        }\n    ],\n    \"City\": [\n        {\n            \"tag\": \"City\",\n            \"pattern\": \"City\",\n            \"text\": \"St Petersburg\",\n            \"words\": [\n                \"st\",\n                \"petersburg\"\n            ]\n        }\n    ],\n    \"_Question\": \"What\",\n    \"_Weather\": \"weather\",\n    \"_City\": \"St Petersburg\"\n}</code></pre></div>\n</br>\n<ul>\n<li>Now let us construct a parse tree for the phrase <code class=\"language-text\">two plus two</code>.</li>\n</ul>\n<p>The phrase is fragmented in accordance with existing named patterns. Since the structure is recursive, the fragments may be embedded to an arbitrary level, as in the following example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$Digit = $regexp&lt;\\d+>\n$Numeral = (one:1|two:2)\n$Number = ($Digit|$Numeral)\n$Operation = (plus:+|minus:-)\nq: * $Number::Number1 $Operation $Number::Number2 *</code></pre></div>\n<p>The parse tree will look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$parseTree: {\n    \"tag\": \"root\",\n    \"pattern\": \"root\",\n    \"text\": \"two plus two\",\n    \"words\": [\n        \"two\",\n        \"plus\",\n        \"two\"\n    ],\n    \"Number1\": [\n        {\n            \"tag\": \"Number1\",\n            \"pattern\": \"Number\",\n            \"text\": \"two\",\n            \"words\": [\n                \"two\"\n            ],\n            \"Numeral\": [\n                {\n                    \"tag\": \"Numeral\",\n                    \"pattern\": \"Numeral\",\n                    \"text\": \"two\",\n                    \"words\": [\n                        \"two\"\n                    ],\n                    \"value\": \"2\"\n                }\n            ]\n        }\n    ],\n    \"Operation\": [\n    {\n        \"tag\": \"Operation\",\n        \"pattern\": \"Operation\",\n        \"text\": \"plus\",\n        \"words\": [\n            \"plus\"\n        ],\n        \"value\": \"+\"\n    }\n    ],\n    \"Number2\": [\n        {\n            \"tag\": \"Number2\",\n            \"pattern\": \"Number\",\n            \"text\": \"two\",\n            \"words\": [\n                \"two\"\n            ],\n            \"Numeral\": [\n                {\n                    \"tag\": \"Numeral\",\n                    \"pattern\": \"Numeral\",\n                    \"text\": \"two\",\n                    \"words\": [\n                        \"two\"\n                    ],\n                    \"value\": \"2\"\n                }\n            ]\n        }\n    ],\n    \"_Number1\": \"2\",\n    \"_Operation\": \"+\",\n    \"_Number2\": \"2\"\n}</code></pre></div>\n<p class='warn'><a href=/1.10.3/docs/en/Patterns/about_patterns  >Learn more about patterns</a>.</p>","frontmatter":{"title":"","description":null},"headings":[{"value":"<code class=\"language-text\">$parseTree</code>"}]}},"pageContext":{"slug":"/docs/en/JS_API/variables/parseTree/","previous":{"fields":{"slug":"/docs/en/JS_API/variables/response/"},"frontmatter":{"title":"","description":null}},"next":{"fields":{"slug":"/docs/en/JS_API/variables/request/"},"frontmatter":{"title":"","description":null}}}},
    "staticQueryHashes": ["1209419333"]}