Parser documentation - Lesson 1
Parser documentation - Lesson 1Skin: StandartGrayGreen Home / Portfolio / Translations / Parser documentation - Lesson 1 Remember ╣а1:
аParser documentation - Lesson 1Published:
аOctober 29, 2002Last change:
аJune 3, 2003 | Lesson 1.аNavigationLet's begin. Well, you want toаmake aаsite. Atаfirst, you have toаrealize, how anаinformation will beаarranged onаtheаsite?. How many categories, subsections etc. will beаthere?. All these questions are taken into consideration onаtheаfirst stageаЧ УSite organization.ФWhat does theаsite navigation look like? There are many requirements toаtheаgood navigation. Itаmust beаclear, easy recognized, persistent, easy toаuse, quickly downloadable, clearly point your location. Atаtheаsame time itаshould beаnoа404аerror onаtheаsite, i.e. all links have toаwork. Ifаyou have experience ofаsite's creating, most likely you had aаproblem with theаmaking ofаgood navigation.You want toаhave aаsolution that always will beаwithin reach and let you automate all this process, don't you? Something, that will give you anаopportunity toаwrite aаcode once and then add sections you want toаtheаsingle place asаmany asаyou wish?Menu's creating that orient aаuser onаtheаsite and doesn't let him getting lostаЧ here isаtheаtask, since weаwould like toаstart describing Parser. Why from that? First ofаall because aаlot ofаtags:<a href="site_page.html">are unmanageable. And ifаyou want toаadd another section? You'll have toаchange every page and due toаpeople's nature toаmake mistakes, very likely that your resource will have Уabsented pagesФ after such Уmodernization.Ф Here isаtheаproblem that can easily beаsolved byаParser.Theаsolution are following. Weаcreate some parser's function that will generate theаnecessary fragment ofаHTML code. Functions are named asаmethods according toаParser's terminology. Weаjust make aаcall УInsert navigation menuФ where this code isаnecessary and theаpage with theаmenu will beаcreated immediately. We'll doаseveral easy steps for it:All information about our links we'll store inаaаsingle file,аЧ it'll allow doаall necessary changes only inаthat file inаtheаfuture. Weаare making theаfile sections.cfg Inаtheаroot catalog ofаtheаfuture site. Theаfile contents theаfollowing information: section_idnameuri1Home/2News/news/3Contacts/contacts/4Prices/price/5Your opinion/gbook/Soаcalled tab-delimited format isаused here. Columns are divided byаtabulator, and rows byаcarriage return. Such formatting will beаcreated automatically while coping this table into aаtext processor but ifаyou create theаtable manually, you have toаtake itаinto account. Tab-delimited format isаalways used for tables.Weаare making theаfile auto.p inаtheаsame catalog (theаlocation ofаsections.cfg).
We'll keep all bricks inаit, from which Parser will construct our site inаtheаfuture. AUTO means, that Parser will always have access toаall these bricks inаnecessary moment, and extension У.p,Ф asаyou probably guessed, this isЕ exactly! Itаis!
Insert theаfollowing code into theаfile auto.p: @navigation[]
$sections[^table::load[sections.cfg]]
<table width="100%" border="1">
<tr>
^sections.menu{
<td align="middle">
<a href="$sections.uri"><nobr>$sections.name</nobr></a>
</td>
}
</tr>
</table>
Data from this file will beаtheаbase ofаour navigation menu.
That's all, preliminary work has been done. Now open page's code, where all this must appear (for example, index.html), and say: УInsert navigation menu.Ф This isаcalled Уmethod callФ inаParser and written this way:^navigation[]It's toаopen theаfile inаaаbrowser yet, which weаinserted method call and look atаcomplete navigation menu. Now weаcan write dear ^navigation[] inаevery place and onаevery page, and Parser will insert our menu there. Aаpage will beаcreated Уonаtheаfly.Ф What weаwanted, was what weаgot.Ifаyou have done so, our congratulationsаЧ you have entered into theаdynamic's sites world. You will use databases for page's constructing and doаmany other things inаsuch easy way very soon.But weаshall not beаglad prematurely. Let's look into, what weаhave done toаget such result. Look atаtheаcode within auto.p. Ifаitаseems, that everything isаquite misunderstood, you needn't getting away. Weаare sure, that inаseveral minutes everything will beаclear. Let's take aаlook atаtheаfirst row:@navigation[]It's much asаrow ^navigation[] that weаinserted into theаpage's text for menu's creating. Difference isаonly inаtheаfirst symbol: ^ and @. But theаmeaning ofаthis statement isаquite differentаЧ weаdefine theаmethod here, that weаshall call later. Theаmeaning ofаsymbol @ atаfirst column ofаtheаrow isаthat weаwant toаdefine some code, that weаuse inаtheаfuture. Next word defines theаname ofаour method: navigation. This isаonly our point how toаname it. It's quite permissibly toаnave names: hey_you_insert_me_quickly. But this program will beаless understandable, though, asаyou wish, you can name itаinаsuch manner.It's vitally important toаhave clear, understandable names. They have toаexactly correspond with theаnamed object will keep and do. Save your and others(who will look into your texts) nerves and time,аЧ treat names with attention. Names may beаinаevery language, theаmain thing toаkeep uniformity: everything inаrussian, everything inаenglish, etc.Goаahead.$sections[^table::load[sections.cfg]]This isаtheаkey row ofаour code. It's rather big, soаlet's spell it.Theаrow begins with aаsymbol $ (dollar) and with theаfollowing name sections. Parser's variables are labeled inаsuch manner. You have toаremember it. Ifаweаsee $var inаaаtextаЧ weаdeal with aаvariable varаЧ aаpiece ofаcake. Aаvariable can have any data: numbers, strings, tables, files, images and even code. Assigning variable parser_home_url byаwww.parser3.ru looks like: $parser_home_url[www.parser3.ru] inаParser. After that weаcan use theаvariable byаname i.e. write $parser_home_url and get value www.parser3.ru.Theаsame thing one again:$var[Е]аЧ assigning aаvalue$varаЧ getting aаvalueFor more information goаtoаsection УVariables.ФHere, variable $sections will store aаtable from theаfile sections.cfg.Parser considers any table asаanаindependent object, with that itаcan handle only some fixed operations, for example, toаadd orаdelete aаrow from it. Since aаvariable can store any data it's necessary toаpoint that theаvalue ofаour variable isаexactly table.Lyrical digression.Anаexample from life. All automobiles can beаdivided for several classes: passenger cars, tracks, tractors and caterpillar technic. Any car isаtheаobject ofаsome ofаthese classes. You can easy determine, what isаtheаclass ofаaаcar, asаall they have general characteristics, like weight, loading etc. Any car can perform actions: toаmove, stand orаbreak. Any ofаcars has its own characteristics. And theаmain thing, that aаcar cannot appear itself, itаmust beаcreated. When aаconstructor invents aаnew car model, heаknows exactly, what isаtheаclass ofаtheаcar heаisаcreating, what properties itаwill have and what itаwill beаable toаdo. Asаwell inаParser: any object takes toаdefinite class, class object isаcreated byаthis class constructor and has characteristics (fields) and methods (actions) that are common for all similar objects.ResultAny Parser's object belongs toаspecific class, characterizes fields and methods ofаvery class. For its appearance, itаmust beаcreated. Theаconstructor ofаthis class doаit. Try toаmake this terminology out, this isаbasis.Looked aside? Let's goаon. Weаassigned theаvariable $sections byаvalue:^table::load[sections.cfg]Literally itаmeans following: weаhave created theаobject ofаclass table using constructor load. Common rule for object creating looks like:^class_name::constructor[constructor_parameters]For more information goаtoаsection УTheаparameters ofаconstructors and methods.ФWeаpassed file name with theаtable and its path asаparameter for theаconstructor.Variable $sections store theаtable with our site's sections now. Parser considers itаasаtheаobject ofаclass table and knows exactly, what kind ofаactions can beаdone with it. Meanwhile weаneed only one method ofаthis classаЧ menu, that looks through all rows ofаtheаtable step byаstep. Asаwell we'll need values from this table's fields. Theаsyntax ofаmethod's call looks like:^object.class_method[parameters]Getting values ofаobject fields (we are dealing with theаcertain table where weаdefined fields after all):$object.field_nameKnowledge, earned above, help toаunderstand theаlast part ofаour code:<table width="100%" border="1">
<tr>
^sections.menu{
<td align="middle">
<a href="$sections.uri"><nobr>$sections.name</nobr></a>
</td>
}
</tr>
</table>Weаcreate HTML-table and put values from fields: uriаЧ address and nameаЧ name ofаour table $sections, into every column. Using method menu weаautomatically look through all rows ofаtheаtable step byаstep. Thus, even ifаweаhave several tens ofаsections, none ofаthem will not beаlost orаpassed. Weаcan easily add sections, delete them and even trade places. Changes are made only within theаfile sections.cfg. Logic will not beаbroken. Everything isаsimple and nice.Let's resume Lesson 1.What have weаdone?:Weаhave written our first Parser's code, namely, learned making navigation menu onаevery page ofаaаsite, relying upon date, within separate file.What have weаlearned?:Weаmade anаacquaintance with conceptual ideas ofаtheаlanguage (class, object, property, method), just asаsome base constructions ofаParser. What must beаremembered:Parser uses object model. Any language object belongs toаsome class, has properties and methods ofаtheаclass. Soаasаtoаcreate anаobject itаshould beаused class constructor.Syntax for working with objects:$variable[value]аЧ assigning aаvalue$variableаЧ getting aаvalue$variable[^class_name::constructor[parameters]]аЧ creating class object class_name and assigning itаtoаaаvariable$variable.field_nameаЧ getting field ofаtheаobject, that are kept inаtheаvariable^variable.method[]аЧ initiating anаaction (class method, theаobject that are kept inаtheаvariable belongs to)What shall weаdoаlater?:Dealing with menu's modernization. Itаisn't upаtoаtheаmark after all: makes unnecessary link onаtheаcurrent section, gives columns with different width. OnаLesson 2аwe'll fix all this bugs and make something else.Content | ╣ 2 >>The latest publications╣ 2аParser documentation - Lesson 2 12.11.2002╣ 1аParser documentation - Lesson 1 29.10.2002LinksParser 3Parser.ruHome / Portfolio / Translations / Parser documentation - Lesson 1 Remember Server InfoAuthorRegistration/settings
ёюфхЁцрэшх | 2 | ┴хёЄЁрэ°хщэюх ёЄЁюшЄхы№ёЄтю ЄЁєсюяЁютюфют сєЁхэшхь
Используются технологии
uCoz