php - I want to write a specific-purpose parser / lexer, but I feel overwhelmed. Could you help me with this little example? -


so i'm writing php templating engine called slade inspired ruby slim , laravel blade.

and many people recommending me rewrite lexer / parser thing, instead of relying on regexes. googled lexers , parsers , tried learn how work, , while think general idea, still find hard start write one.

so hoping if me on way, showing how 1 example. how lex (is verb?) , parse this:

#wrapper.container.well first-attr="a literal attribute" second-attr=variable.name , here text content of div... 

into these nodes:

[     'tagname' => 'div', // since there no tagname, div assumed     'attributes' => [         'id' => 'wrapper',         'class' => 'container well',         'first-attr' => 'a literal attribute',         'second-attr' => 'the value of variable',     ],     'textcontent' => 'and here text content of div...' ] 

of course don't expect write out function 100% lexes / parses this, i'd see general pseudo code of how go this. me this?


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -