adl / hoaf

Hanoi Omega-Automata Format
13 stars 2 forks source link

Automata extraction from README.md (issue #33) #34

Closed kleinj closed 10 years ago

adl commented 10 years ago

How about this? This does not require any change to README.md.

#!/bin/perl -w
use strict;
my %seenfiles;
undef $/;
$_ = <>;

while (m{!\[automaton\]\(figures/(?<filename>[^)]*)\.svg\)\s*\n    (?<body>HOA:.*?--END--)}msg)
{
  my $name = $1;
  my $body = $2;
  $body =~ s/^    //mg;

  # Sort out repeated uses of same filename by appending a number.
  $name = "$name." . ++$seenfiles{$name} if exists $seenfiles{$name};
  $seenfiles{$name} = 1;

  $name = "examples/$name.hoa";

  print "writing $name\n";
  open(OUT, '>', $name) or die("cannot open $name: $!");
  print OUT "$body\n";
  close(OUT);
}

Regarding the generated files, do you really want them in the repository, are was this just to illustrate the script? So far I have only put source files on master. The generated files (html, svg, etc.) are however stored on the gh-pages branch that is served as the web pages. Maybe we should just have them there? In the top-level Makefile, the webpack target is responsible for building a tarball that contains the web site, and the gh-pages target installs the contents of this tarball on the gh-pages branch.

kleinj commented 10 years ago

Yes, that's fine as well :) And sure, it probably makes sense to keep the generated files as a separate branch.

adl commented 10 years ago

I've arranged for the examples to be extracted from README.md (unmodified), and listed on a dedicated page along with the figures and a zip file.