KBD

Keith Devens .com

Friday, December 5, 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)
← activeRendererSomething to think about →

Daily link icon Wednesday, March 5, 2003

StructuredText lists

In my (super-dandy, hyper-extensible, solve-world-hunger and kick-Saddam-in-the-nuts) StructuredText parser (version 2) which I've been working on lately, the last main thing I have to do before I can actually use the darn thing is get the list syntax to work. I've been having problems specifying to the parser exactly how the lists should be parsed, and I realized today that there's a weird case that's been causing my problems. Here's the rundown:

The lists in my previous version of my StructuredText parser looked like this:

* List
** Nested list
*** Another nested list

Not too bad, but it's klunky. It's more natural to me to write the following:

* List
  * Nested list
    * Another nested list

That's two spaces before each nested list starts. I haven't worried about other kinds of lists (like ordered lists) yet.

This is easy to parse in my ST parser. Next, I wanted to be able to have multiple lines in my lists. So that would look like this:

* List
  * This is a
    nested list

No problem. Some various cases are the following:

* List with
  continuing text

No problem. If you happen to mess up and put one space instead of two:

* List with
 continuing text

it would figure out what you meant. If you messed up and didn't put any spaces, the list would end and it would consider that line the start of a paragraph. If you had any amount of spaces before the text began:

* List with
        continuing text

the parser would strip the first two spaces and the line would continue with no problem. So far so good. Even this would work with no problem:

* List with
  Continuing text
  * Sub list
    with continuing text

and so on. The problem arises in two specific cases:

* List
  * Sublist
 oops, not indented right

and

* List
  * sublist
  still not indented right, but where normally
  it would end the list and become the start of
  a paragraph, this time it's in the middle of
  a nested list, so even if I end the sublist,
  I still have to figure out what to do with
  all this text.

This problem really arises as a result of both the new syntax and allowing multiple lines in a list (which I couldn't do before in my old parser). The problem didn't exist in the old parser because every line in a list began with a "list marker" (like *,-, or +), so indentation wasn't important, and multiple lines in a list weren't allowed. I could solve the problem in my current parser, but it would require potentially a lot of lookahead, which I'm not happy about. It's not elegant, and it's slower.

I haven't decided what to do yet, but for now I'm going to see what the reStructuredText people did. I'll bet you they throw parser exceptions (which I don't really want to do).

← activeRendererSomething to think about →

Comments XML gif


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 4 posts

Recent comments XML

Girls, please don't get breast implants

I have 34 A breast but at 22 years​old they seem to be growing again​which ...

76.64.120.153: Dec 3, 10:00am

Perl 6 1.0 in March?

Doh, my mistake. I'm aware of the​relation between Parrot and Rakudo​but I'...

Keith: Dec 2, 1:03am

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

Generated in about 0.183s.

(Used 8 db queries)

mobile phone