KBD

Keith Devens .com

Monday, December 1, 2008 Flag waving
Everybody makes their own fun. If you don't make it yourself, it ain't fun -- it's entertainment. – David Mamet (as relayed by Joss Whedon)
← This is horribleAwesome Matrix Reloaded review →

Daily link icon Sunday, May 11, 2003

My StructuredText parser kicks ass

The StructuredText parser I've been working on over the past few days simply kicks ass. I'm actually pretty proud of the code. I've whipped it out fast and it's designed really well, IMO.

One part of it, though, has been giving me a lot of problems. The inline parser, which parses the structure of an individual line, separate from the main parser which parses main blocks like paragraphs, blockquotes, and lists, has been a lot more difficult to write than the rest of the code.

Hmm... I entered the above into w.bloggar last night and saved it. I had planned on elaborating on why the inline parser has been difficult, and on describing the design of it, but I have no time now.

However, one of the decisions I'm going to have to make is a weird one.... I'm writing the thing in Python, because whenever I try to write anything big or complicated in PHP I wind up cursing PHP out every few minutes. Largely, I think, because I'm never sure that I'm not making copies everywhere because of PHP's broken OO. Whatever the reason, Python is just far more comfortable to work in, and I think my productivity has been much better with it than if I had written my code in PHP.

With that said, I'm only prototyping the code in Python. The "real" implementation is still going to be in PHP, since I want to use the code on my website, and well, my website is written in PHP. However, the Python code is much awesomer than the PHP code will wind up being. To give one example, in Python you get to say nice things like line = line[beginning:end] to suck out part of a line you're interested in. In PHP I'm going to have to say $line = substr($line, $beginning, $length-$end). After looking at that, I'm beginning to think that dollar sign variables aren't so hot.

So this leaves me with the prospect of wanting to maintain both the Python and the PHP versions of the code. The difficulty is exacerbated because the code is much more than just the base parser. It's "pluggable", so you can add new content types (like, in addition to paragraph, blockquote, etc., you can add "code block", "note", "user-entered text", etc.), parser components (for instance, a different list syntax or a different table syntax, and a parser for "note", "code block", etc.), and for each content type, you have to add a "generator" for your destination language, it being HTML, LaTeX, etc. And, realistically, I'd much rather maintain and use the Python version, especially for anything but HTML generation, since it integrates better with my computer than PHP does, rather than my web server, which is what PHP specializes in.

So, I guess I've made my decision. This is why I write things like this out sometimes Smiley I think the primary version will be the Python version, and the PHP version will always be a simple translation of the Python version. I'll make both available for download. At the very least it'll serve as an interesting language comparison Smiley Unfortunately, it's not going to get finished until I get that line parser thing figured out, and that's not going to happen until after finals, and until after my road trip (yeah baby) after that.

← This is horribleAwesome Matrix Reloaded review →

Comments XML gif

P. Lioi (http://novaroot.com) wrote:

I think there's an extension to php that lets you store python code in a php string (ie read from your .py file) and execute it in a php script, FYI.

∴ P. Lioi | 11-May-2003 7:27pm est | http://novaroot.com | #2056

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

December 2008
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 5 posts

Recent comments XML

new⇒Free image hosting sites

Well, TinyPic has this in its​FAQ:

> Images and videos is in​your accoun...

Keith: Dec 1, 1:13am

Join a NameValueCollection into a querystring in C#

Well with a lamba expression, this​is what I came up​with:

?!code:csharp...

Gustaf Lindqvist: Nov 30, 4:38pm

Why no generic OrderedDictionary?

Check​http://www.codeproject.com/KB/recip​es/GenericOrderedDictionary.aspx?d...

Gabrielk: Nov 27, 6:57am

WhatIsMyIP.com

http://www.thesysteminfo.com is​another good alternate to​whatismp.com... I...

Kripz: Nov 26, 8:51pm

Girls, please don't get breast implants

Actually I think it's sweet when a​man loves a woman whether she's big​or n...

218.186.12.228: Nov 26, 9:40am

Generated in about 0.219s.

(Used 8 db queries)

mobile phone