[plt-scheme] Parentheses and color

From: hendrik at topoi.pooq.com (hendrik at topoi.pooq.com)
Date: Wed Jul 4 10:07:54 EDT 2007

On Wed, Jul 04, 2007 at 08:24:07AM +0200, Jos Koot wrote:
> Hi
> I never count parentheses, but frequently watch the highlighting of 
> subexpressions. DrScheme realy makes it easy. When typing a sequence of 
> closing parentheses I simply check that the start of the highlighting 
> correctly skips back one level of indentation for each closing parenthesis. 
> The same method can be used to quickly spot a missing closing parenthesis. 
> The method works perfect even if the parentheses would not be visible.
> Jos koot

Invisible parentheses.  Interesting.  C++ can also be quite readable 
without curly brackets.  (we,,. almost without).  Here's a fragment 
(it relies on another program that parses arbitrary text based 
*only* on indentation, giving a tree structure of lines) from 
a program that puts the brackets back in:

typedef char Char; // we use strdup, so small charset
typedef unsigned int nat;

struct Line
  int indent;
  struct Line * mother;
  struct Line * sister;
  struct Line * daughters;
  nat length;
  nat lineno;
  Char * contents;

Line * readlines();

#include <stdio.h>
#include "readindentx.hh"

bool line_directives = true;
int outlineno = 0;

void nl(int count)
  int i = count;
  while(i > 1)
    printf("    ");
  if(count > 0) printf("  ");

void print(Line * line, int nest)

  if(line_directives && line->lineno != outlineno)
    if(line->lineno == outlineno + 1)
      printf("\n#line %d", line->lineno);

    outlineno = line->lineno;
  if(line->contents && line->length != 0)
    printf("%s", line->contents);
  if(line->daughters != NULL)
    if(nest >= 0)
      if(nest > 0) printf("  ");
    for(Line * d = line->daughters; d != NULL; d = d->sister)
      print(d, nest + 1);
    if(nest >= 0)
      if(nest > 0) printf("  ");

void print(Line * line)
  print(line, -1);

int main()
  Line * l = readlines();
  return 0;

-- hendrik

Posted on the users mailing list.