On Sat, Feb 9, 2013 at 1:43 PM, Alan Manuel Gloria <almkg...@gmail.com> wrote: > - at the start of the read, the "previous line's indent" is considered > as negative. > - A line with the same indent as the previous line inserts a ")". It > also inserts a "(" unless the line starts with "." > - a line with a greater indent than the previous line inserts a "(" > unless the line starts with "." > - a line with a lesser indent than the previous line inserts a ")" for > each indentation level popped, followed by a closing ")" > - "." at the start of the line is removed. >
Scratch that. Here's a better implementation, based on what I see as the core stuff you want. This ruleset bans a more indented line after a "."-initial line. None of your examples shows that case, and I think that the simplistic approach I'm using is hard to hack a decent effect with it. I also ignore ":", because I'm not sure if its effect crosses line boundaries (and if it does, how you're supposed to handle double-width CJK characters.) - the reader has two variables: a stack of indentation levels, and a boolean dot flag. Initially the stack contains a single negative item, and the dot flag is false. - When the current line is more indented than the stack top: - - if the dot flag is set, error!! - - if it starts with ".", just set the dot flag - - otherwise insert a "(" and clear the dot flag and push the new indent on the stack. - When the current line is at the same indent as the stack top: - - if the dot flag is cleared, insert ")". - - if it starts with ".", just set the dot flag - - otherwise insert a "(" and clear the dot flag - Otherwise: - - if the dot flag is cleared, insert ")" - - pop off stack items until we reach an indent with the exact same indent as the current line; emit ")" for each popped item (warning: off-by-one error might be here, so need to actually check by implementing) - - if it starts with "." just set the dot flag - - otherwise insert a "(" and clear the dot flag nb: blank lines might cause (), need to consider those. nb: also, see the warning above, need to actually check it. Hope this helps. If you can get an implementation (even just a simple one that does a text-to-text substitution, and without ":", like the above) show us so we can think about it more. Sincerely, AmkG ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb _______________________________________________ Readable-discuss mailing list Readable-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/readable-discuss