{"id":22,"date":"2008-06-13T15:02:27","date_gmt":"2008-06-13T12:02:27","guid":{"rendered":"http:\/\/brownian.org.ua\/?page_id=22"},"modified":"2008-06-23T17:37:05","modified_gmt":"2008-06-23T14:37:05","slug":"lang_ukskanuvannialang_uklang_enscanninglang_en","status":"publish","type":"page","link":"https:\/\/brownian.org.ua\/?page_id=22","title":{"rendered":"\u0421\u043a\u0430\u043d\u0443\u0432\u0430\u043d\u043d\u044f"},"content":{"rendered":"<h3>\u0421\u043a\u0430\u043d\u0435\u0440<\/h3>\n<p>\u041c\u0438 &#171;\u0447\u0438\u0442\u0430\u0442\u0438\u043c\u0435\u043c\u043e&#187; \u0437\u0430\u043f\u0440\u043e\u043f\u043e\u043d\u043e\u0432\u0430\u043d\u0438\u0439 \u043a\u043e\u043d\u0444\u0456\u0433\u0443\u0440\u0430\u0446\u0456\u0439\u043d\u0438\u0439 \u0444\u0430\u0439\u043b \u0442\u0430\u043a\u0438\u043c \u0447\u0438\u043d\u043e\u043c:<\/p>\n<ul>\n<li> \u041a\u043e\u043d\u0444\u0456\u0433\u0443\u0440\u0430\u0446\u0456\u0439\u043d\u0438\u0439 \u0444\u0430\u0439\u043b \u043c\u0456\u0441\u0442\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0438 (&#171;classes&#187;)<\/li>\n<li> \u041a\u043e\u0436\u0435\u043d \u043a\u043b\u0430\u0441 \u043f\u043e\u0447\u0438\u043d\u0430\u0454\u0442\u044c\u0441\u044f <em>&#171;\u0435\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c&#187; \u0442\u0438\u043f\u0443 &#171;class&#187;<\/em>\u2026<\/li>\n<li> \u2026 \u0442\u0430 \u043c\u0456\u0441\u0442\u0438\u0442\u044c \u0456\u0434\u0435\u043d\u0442\u0438\u0444\u0456\u043a\u0430\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0443 (\u0442\u0438\u043f\u0443 &#171;classid&#187;) \u0442\u0430 &#171;\u0431\u043b\u043e\u043a&#187; (&#171;block&#187;)<\/li>\n<li> \u0411\u043b\u043e\u043a \u043c\u0456\u0441\u0442\u0438\u0442\u044c \u0456\u043d\u0448\u0456 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0443.<\/li>\n<\/ul>\n<p>\u0412\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u044e\u0447\u0438 <a href=\"http:\/\/pages.cpsc.ucalgary.ca\/%7Eaycock\/spark\/\" target=\"_blank\" title=\"SPARK homepage\">SPARK<\/a> \u043c\u0438 \u0441\u0442\u0432\u043e\u0440\u0438\u043c\u043e \u043a\u043b\u0430\u0441, \u044f\u043a\u0438\u0439 \u043d\u0430\u0441\u043b\u0456\u0434\u0443\u0454 we will <code>spark.GenericScanner<\/code> \u043a\u043b\u0430\u0441 \u0442\u0430 \u0432\u0438\u0437\u043d\u0430\u0447\u0438\u043c\u043e \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u0456 \u0432\u0438\u0440\u0430\u0437\u0438 \u0434\u043b\u044f \u0440\u043e\u0437\u043f\u0456\u0437\u043d\u0430\u0432\u0430\u043d\u043d\u044f \u0435\u043b\u0435\u043c\u0435\u043d\u0442\u0456\u0432 \u0443 \u0440\u044f\u0434\u043a\u0430\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0456\u0457 Python (docstrings) \u0432\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u043d\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0456\u0432. \u0422\u0430\u043a\u0438\u043c \u0447\u0438\u043d\u043e\u043c \u0434\u043b\u044f \u043a\u043e\u0436\u043d\u043e\u0433\u043e &#171;\u0435\u043b\u0435\u043c\u0435\u043d\u0442\u0430&#187;, \u0449\u043e \u0432\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u0430\u0454 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u043c\u0443 \u0432\u0438\u0440\u0430\u0437\u0443 &#8222;<code>[a-zA-Z_]+[0-9]*<\/code>&#8216;, \u0431\u0443\u0434\u0435 \u0432\u0438\u043a\u043b\u0438\u043a\u0430\u043d\u043e <code>t_string<\/code> \u0456 \u0442.\u0434, \u0456 \u0442.\u043f:<\/p>\n<pre lang=\"PYTHON\">\r\n#!\/usr\/bin\/env python\r\n\r\nimport spark\r\nimport token\r\n\r\nclass SimpleScanner(spark.GenericScanner):\r\ndef __init__(self):\r\n    spark.GenericScanner.__init__(self)\r\n    self.keywords = [\r\n        '<strong>class<\/strong>',\r\n        'rate',\r\n        'ceil',\r\n        'descr',\r\n        'root',\r\n        'parent',\r\n    ]\r\n\r\ndef tokenize(self, input):\r\n    self.rv = []\r\n    spark.GenericScanner.tokenize(self, input)\r\n    return self.rv\r\n\r\ndef t_whitespace(self, s):\r\n    r'\\s+'\r\n    pass\r\n\r\ndef t_comment(self, s):\r\n    r'\\<em>#.*'<\/em>\r\n    pass\r\n\r\ndef t_semicol(self, s):\r\n    r';'\r\n    self.rv.append(token.Token(type=s, attr=s))\r\n\r\ndef t_openblock(self, s):\r\n    r'{'\r\n    self.rv.append(token.Token(type=s, attr=s))\r\n\r\ndef t_closeblock(self, s):\r\n    r'}'\r\n    self.rv.append(token.Token(type=s, attr=s))\r\n\r\ndef t_equal(self, s):\r\n    r'='\r\n    self.rv.append(token.Token(type=s, attr=s))\r\n\r\ndef t_number(self, s):\r\n    r'[0-9]+'\r\n    self.rv.append(token.Token(type='number', attr=s))\r\n\r\ndef t_classid(self,s):\r\n    r'[0-9]+:[0-9]+'\r\n    self.rv.append(token.Token(type='classid', attr=s))\r\n\r\ndef t_keyword(self, s):\r\n    # r' class | irate | iceil | descr '\r\n    self.rv.append(token.Token(type=s, attr=s))\r\n\r\ndef t_string(self, s):\r\n    r'[a-zA-Z_]+[0-9]*'\r\n    if s in self.keywords:\r\n        self.t_keyword(s)\r\n    else:\r\n        self.rv.append(token.Token(type='string', attr=s))\r\n<\/pre>\n<p>\u0429\u043e \u0436 \u043d\u0430\u043c \u0434\u0430\u0454 \u0434\u043b\u044f \u0440\u043e\u0437\u0432&#8217;\u044f\u0437\u0430\u043d\u043d\u044f \u043d\u0430\u0448\u043e\u0457 \u0437\u0430\u0434\u0430\u0447\u0456 \u0442\u0430\u043a\u0438\u0439 \u0432\u0456\u0434\u043d\u043e\u0441\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0438\u0439 \u043a\u043b\u0430\u0441? \u0421\u043f\u0440\u043e\u0431\u0443\u0454\u043c\u043e \u0442\u0430\u043a\u0435:<\/p>\n<pre lang=\"PYTHON\">\r\n#!\/usr\/bin\/env python\r\n\r\nimport spark\r\nimport scanner\r\n\r\ndef scan(f):\r\n    input = f.read()\r\n    scnr = scanner.SimpleScanner()\r\n    return scnr.tokenize(input)\r\n\r\nf = open('test.confg')\r\n\r\nscanned = scan(f)\r\n\r\nprint scanned\r\n<\/pre>\n<p>`<code>print scanned<\/code>&#8216; \u043d\u0430\u0434\u0440\u0443\u043a\u0443\u0454 \u043f\u043e\u0441\u043b\u0456\u0434\u043e\u0432\u043d\u0456\u0441\u0442\u044c \u0435\u043b\u0435\u043c\u0435\u043d\u0442\u0456\u0432 (\u044f \u0440\u043e\u0437\u0431\u0438\u0432 \u0440\u044f\u0434\u043e\u043a \u043d\u0430 \u043a\u043e\u0440\u043e\u0442\u0448\u0456):<\/p>\n<pre lang=\"OUTPUT\">\r\n[class, 1:5, root, {, rate, =, 10240, ceil, =, 20480, },\r\n class, 1:50, parent, 1:5, {, ceil, =, 2048, rate, =, 1024, descr, =, My_favorite_client, },\r\n class, 1:53, parent, 1:50, {, descr, =, My_other_client, ceil, =, 2048, rate, =, 1024, }\r\n]\r\n<\/pre>\n<p>\u041d\u0435 \u0442\u0430\u043a \u0456 \u043f\u043e\u0433\u0430\u043d\u043e: \u043d\u0430\u0448 \u043a\u043e\u043d\u0444\u0456\u0433\u0443\u0440\u0430\u0446\u0456\u0439\u043d\u0438\u0439 \u0444\u0430\u0439\u043b \u0440\u043e\u0437\u0456\u0431\u0440\u0430\u043d\u043e \u043d\u0430 \u0435\u043b\u0435\u043c\u0435\u043d\u0442\u0438!<\/p>\n<p>\u0427\u0443\u0434\u043e\u0432\u043e, \u0434\u0430\u043b\u0456:<\/p>\n<pre lang=\"PYTHON\">\r\n>>> print '\\n'.join(['Token \"%s\" of type \"%s\"' % (x.attr, x.type) for x in scanned])\r\nToken \"class\" of type \"class\"\r\nToken \"1:5\" of type \"classid\"\r\nToken \"root\" of type \"root\"\r\nToken \"{\" of type \"{\"\r\nToken \"rate\" of type \"rate\"\r\nToken \"=\" of type \"=\"\r\nToken \"10240\" of type \"number\"\r\nToken \"ceil\" of type \"ceil\"\r\n\r\n<... etc-etc ...>\r\n\r\nToken \"1024\" of type \"number\"\r\nToken \"}\" of type \"}\"\r\n<\/pre>\n<p>\u041e\u0442\u0436\u0435, \u043c\u0438 &#171;\u0437\u0456\u0441\u043a\u0430\u043d\u0443\u0432\u0430\u043b\u0438&#187; \u043d\u0430\u0448\u0443 \u043a\u043e\u043d\u0444\u0456\u0433\u0443\u0440\u0430\u0446\u0456\u044e \u0443\u0441\u043f\u0456\u0448\u043d\u043e&#160;&#8212; \u043c\u0438 \u043c\u0430\u0454\u043c\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0435\u043b\u0435\u043c\u0435\u043d\u0442\u0456\u0432 (list of tokens) \u0437 \u0456\u0445\u043d\u0456\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 (\u043a\u043b\u0430\u0441 <code>token.Token<\/code> \u0432\u0438\u0437\u043d\u0430\u0447\u0430\u0454 \u0442\u0438\u043f\u0438 \u0435\u043b\u0435\u043c\u0435\u043d\u0442\u0456\u0432 \u2014 \u044f \u0439\u043e\u0433\u043e \u043d\u0435 \u043f\u043e\u0434\u0430\u0432, \u0430\u043b\u0435 \u0432\u0456\u043d \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u043d\u043e \u043d\u0435 \u0432\u0456\u0434\u0440\u0456\u0437\u043d\u044f\u0454\u0442\u044c\u0441\u044f \u0432\u0456\u0434 \u043f\u043e\u0434\u0430\u043d\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u043e\u043c <a href=\"http:\/\/pages.cpsc.ucalgary.ca\/%7Eaycock\/spark\/\" target=\"_blank\" title=\"SPARK homepage\">SPARK<\/a>, John Aycock, \u0443 \u0439\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0456\u0457).<\/p>\n<h3>\u0420\u043e\u0431\u0438\u043c\u043e \u043b\u0435\u043a\u0441\u0438\u0447\u043d\u0456 \u043f\u043e\u043c\u0438\u043b\u043a\u0438<\/h3>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c\u043e &#171;roo*&#187; \u0437\u0430\u043c\u0456\u0441\u0442\u044c &#171;root&#187; \u0443 3-\u043c\u0443 \u0440\u044f\u0434\u043a\u0443 \u0456 \u0441\u043f\u0440\u043e\u0431\u0443\u0454\u043c\u043e \u0449\u0435 \u0440\u0430\u0437. \u041c\u0430\u0442\u0438\u043c\u0435\u043c\u043e:<\/p>\n<pre lang=\"ERROR\">\r\nSpecification error: unmatched input\r\n<\/pre>\n<p>\u0411\u0430\u0447\u0438\u043c\u043e, \u0449\u043e <a href=\"http:\/\/pages.cpsc.ucalgary.ca\/%7Eaycock\/spark\/\" target=\"_blank\" title=\"SPARK homepage\">SPARK<\/a> \u043d\u0435 \u043f\u0438\u0448\u0435 \u043d\u043e\u043c\u0435\u0440\u0438 \u0440\u044f\u0434\u043a\u0456\u0432, \u0434\u0435 \u0431\u0443\u043b\u043e &#171;\u0437\u0456\u0441\u043a\u0430\u043d\u043e\u0432\u0430\u043d\u043e&#187; \u043f\u043e\u043c\u0438\u043b\u043a\u0443. \u0427\u0438\u0442\u0430\u0439\u0442\u0435 \u043f\u0456\u0434\u0440\u0443\u0447\u043d\u0438\u043a <a href=\"http:\/\/pages.cpsc.ucalgary.ca\/%7Eaycock\/spark\/\" target=\"_blank\" title=\"SPARK homepage\">SPARK<\/a>, \u0442\u0430\u043c \u0439\u0434\u0435\u0441\u0442\u044c\u044f \u043f\u0440\u043e \u0442\u0435, \u044f\u043a \u0446\u0435 &#171;\u0432\u0438\u043f\u0440\u0430\u0432\u0438\u0442\u0438&#187;.<\/p>\n<p>\u0410\u043b\u0435 \u0449\u043e \u0441\u0442\u0430\u043d\u0435\u0442\u044c\u0441\u044f, \u044f\u043a\u0449\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c\u043e \u0442\u0430\u043a\u0435?<\/p>\n<pre lang=\"CONFIG\">\r\nclass 1:50 parent 1:5 {\r\n    ceil = foo moo bar\r\n    rate = 1024\r\n}\r\n<\/pre>\n<p>\u041c\u0438 \u043c\u0430\u0454\u043c\u043e &#171;\u0443\u0441\u043f\u0456\u0448\u043d\u043e&#187; \u0437\u0456\u0441\u043a\u0430\u043d\u043e\u0432\u043d\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0435\u043b\u0435\u043c\u0435\u043d\u0442\u0456\u0432:<\/p>\n<pre lang=\"OUTPUT\">\r\n. . .\r\nToken \"ceil\" of type \"ceil\"\r\nToken \"=\" of type \"=\"\r\nToken \"foo\" of type \"string\"\r\nToken \"moo\" of type \"string\"\r\nToken \"bar\" of type \"string\"\r\n. . .\r\n<\/pre>\n<p>\u041e\u0442\u0436\u0435, \u0437 \u043b\u0435\u043a\u0441\u0438\u0447\u043d\u043e\u0457 \u0442\u043e\u0447\u043a\u0438 \u0437\u043e\u0440\u0443&#160;&#8212; \u0432\u0441\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e. \u0410\u043b\u0435, \u0431\u0435\u0437\u0443\u043c\u043e\u0432\u043d\u043e, \u0446\u0435 \u043f\u043e\u043c\u0438\u043b\u043a\u0430 :-)<\/p>\n<p>\u0410\u043b\u0435 \u0446\u0435 \u0437\u0430\u0434\u0430\u0447\u0430 \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0443\u043f\u043d\u043e\u0433\u043e \u043a\u0440\u043e\u043a\u0443 \u2014 <em><strong><a href=\"?page_id=23\">\u041f\u0430\u0440\u0441\u0438\u043d\u0433<\/a><\/strong>\u0443<\/em>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u043a\u0430\u043d\u0435\u0440 \u041c\u0438 &#171;\u0447\u0438\u0442\u0430\u0442\u0438\u043c\u0435\u043c\u043e&#187; \u0437\u0430\u043f\u0440\u043e\u043f\u043e\u043d\u043e\u0432\u0430\u043d\u0438\u0439 \u043a\u043e\u043d\u0444\u0456\u0433\u0443\u0440\u0430\u0446\u0456\u0439\u043d\u0438\u0439 \u0444\u0430\u0439\u043b \u0442\u0430\u043a\u0438\u043c \u0447\u0438\u043d\u043e\u043c: \u041a\u043e\u043d\u0444\u0456\u0433\u0443\u0440\u0430\u0446\u0456\u0439\u043d\u0438\u0439 \u0444\u0430\u0439\u043b \u043c\u0456\u0441\u0442\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0438 (&#171;classes&#187;) \u041a\u043e\u0436\u0435\u043d \u043a\u043b\u0430\u0441 \u043f\u043e\u0447\u0438\u043d\u0430\u0454\u0442\u044c\u0441\u044f &#171;\u0435\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c&#187; \u0442\u0438\u043f\u0443 &#171;class&#187;\u2026 \u2026 \u0442\u0430 \u043c\u0456\u0441\u0442\u0438\u0442\u044c \u0456\u0434\u0435\u043d\u0442\u0438\u0444\u0456\u043a\u0430\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0443 (\u0442\u0438\u043f\u0443 &#171;classid&#187;) \u0442\u0430 &#171;\u0431\u043b\u043e\u043a&#187; (&#171;block&#187;) \u0411\u043b\u043e\u043a \u043c\u0456\u0441\u0442\u0438\u0442\u044c \u0456\u043d\u0448\u0456 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0443. \u0412\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u044e\u0447\u0438 SPARK \u043c\u0438 \u0441\u0442\u0432\u043e\u0440\u0438\u043c\u043e \u043a\u043b\u0430\u0441, \u044f\u043a\u0438\u0439 \u043d\u0430\u0441\u043b\u0456\u0434\u0443\u0454 we will spark.GenericScanner \u043a\u043b\u0430\u0441 &hellip; <a href=\"https:\/\/brownian.org.ua\/?page_id=22\" class=\"more-link\"><span>Continue reading<span class=\"screen-reader-text\">\u0421\u043a\u0430\u043d\u0443\u0432\u0430\u043d\u043d\u044f<\/span><\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":19,"menu_order":7,"comment_status":"open","ping_status":"open","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/brownian.org.ua\/index.php?rest_route=\/wp\/v2\/pages\/22"}],"collection":[{"href":"https:\/\/brownian.org.ua\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/brownian.org.ua\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/brownian.org.ua\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/brownian.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=22"}],"version-history":[{"count":0,"href":"https:\/\/brownian.org.ua\/index.php?rest_route=\/wp\/v2\/pages\/22\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/brownian.org.ua\/index.php?rest_route=\/wp\/v2\/pages\/19"}],"wp:attachment":[{"href":"https:\/\/brownian.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}