Permalink
Browse files

added mowyw to the repository

git-svn-id: svn+ssh://faui2k3.org/var/lib/svn/moritz/mowyw@258 addfbb1e-f4f9-0310-b6f0-bccd0f9b8dc6
  • Loading branch information...
0 parents commit 52f3521bf7cf2172137d4ab7726b67a32ba25e18 moritz committed Mar 29, 2007
@@ -0,0 +1,5 @@
+mowyw (0.2.0)
+ * Mowyw/Lexer.pm: added a separate lexer
+ * mowyw: (nearly) complete rewrite using a recursive-descending parser
+ * README: added description for [[[verbatim foo]]] (arbitrary
+ stuff)[[[endverbatim foo]]]
@@ -0,0 +1,115 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+package Mowyw::Lexer;
+
+=pod
+=head1 NAME
+
+Mowyw::Lexer - Simple Lexer
+
+=head1 SYNOPSIS
+
+ use Mowyw::Lexer qw(lex);
+ # suppose you want to parse simple math expressions
+ my @input_tokens = (
+ ['Int', qr/(?:-|\+)?\d+/],
+ ['Op', qr/\+|\*|-|\//],
+ ['Brace_Open', qr/\(/],
+ ['Brace_Close', qr/\)/],
+ ['Whitespace', qr/\s/, sub { return undef; }],
+ );
+ my $text = "-12 * (3+4)";
+ foreach (lex($text, \@input_tokens){
+ my ($name, $text) = @$_;
+ print "Found Token $name: $text\n";
+ }
+
+=head1 DESCRIPTION
+
+Mowyw::Lexer is a simple lexer that breaks up a text into tokens, depenending on the input tokens you provide
+
+The only exported method is lex($$), which expects input text as its first argument and a array ref to list of input tokens.
+
+Each input token consists of a token name (which you can choose freely), a regexwhich matches the desired token, and optionally a reference to a functions that takes the matched token text as its argument. The token text is replaced by the return value of that function. If the function returns undef, that token will not be included in the list of output tokens.
+
+lex() returns a list of output tokens, each output token is a reference to a list which contains the token name and the matched text.
+
+If there is unmatched text, it is returned with the token name UNMATCHED.
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2007 by Moritz Lenz, http://moritz.faui2k3.org, moritz@faui2k3.org
+
+This Program and its Documentation is free software. You may distribute it under the same terms as perl itself.
+
+However all code examples are to be public domain, so you can use it in any way you want to.
+
+=cut
+
+require Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = qw(lex);
+
+our %EXPORT_TAGS = (":all" => \@EXPORT);
+
+sub lex($$){
+ my ($text, $tokens) = @_;
+ return () unless ($text);
+ my @res;
+ while (length($text) > 0){
+ my $matched = 0;
+ # try to match at the start of $text
+ foreach (@$tokens){
+ my $re = $_->[1];
+ if ($text =~ m#^$re#s){
+ $matched = 1;
+ my $match = $&;
+ die "Each token has to require at least one character; Rule $_->[0] matched Zero!\n" unless (length($match) > 0);
+ if (my $fun = $_->[2]){
+ $match = &$fun($match);
+ }
+ if (defined $match){
+ push @res, [$_->[0], $&];
+ }
+ $text = $';
+ last;
+ }
+ }
+ unless ($matched){
+ # no token matched, look what the closest token is
+# my $remain = substr $text, 0, 30;
+# die "No Token matched the remaining String which starts as $remain\n";
+ my $next_token;
+ my $min = length($text);
+ foreach(@$tokens){
+ my $re = $_->[1];
+ if ($text =~ m#$re#s){
+ if (length($`) < $min){
+ $min = length($`);
+ $next_token = $_;
+ $matched = 1;
+ }
+ }
+ }
+ if ($matched){
+ my $re = $next_token->[1];
+ $text =~ m#$re#;
+ push @res, ['UNMATCHED', $`];
+ my $match = $&;
+ die "Each token has to require at least one character; Rule $_->[0] matched Zero!\n" unless (length($match) > 0);
+ if (my $fun =$next_token->[2]){
+ $match = &$fun($match);
+ }
+ push @res, [$next_token->[0], $match] if (defined $match);
+ $text = $';
+ } else {
+ push @res, ['UNMATCHED', $text];
+# print "END OF FILE IS UNMATCHED: $text\n";
+ $text = "";
+ }
+ }
+ }
+ return @res;
+}
+1;
190 README
@@ -0,0 +1,190 @@
+mowyw - mowyw writes your websites (or: Moritz writes your websites ;-)
+
+For license of this file see the notice at the end of the file
+
+moc is an offline CMS, that means it process sources files and generates
+output files from them, usually HTML files, but php files and others are
+possible as well (with some limitations though).
+
+SYNTAX CHANGE
+-------------
+Version 0.0.3 and before used only double square brackets
+(like [[include foo]]), but I noticed that double closing square brackets
+are part of a typical CDATA declaration in xml files (and xhtml) like this:
+<style type="text/css">
+/*<![CDATA[*/
+ CSS Declarations
+/*]]>*/
+</style>
+
+Now tripple square brackets (like [[[include foo]]]) are used.
+
+
+SHORT HOWTO:
+-----------
+
+choose an empty directory, and there create the three directories
+includes/
+source/
+online/
+
+The `source/' directory contains the source files that will be processed by
+mowyw. Each file in the `source/' directory is mapped to one file in the
+`online/' directory. You should not write files into the `online/' directory
+since they may be deleted or overwritten, and you should not modify existing
+files in that directory since all changes are lost during the next run.
+All files that might be included by others (including menus) should be in the
+`includes' directory.
+
+Now place a file index.html (or whatever you want it to be called) in the
+'source/' directory.
+
+If all your HTML files have a common header/footer, you may want to place them
+in in the files `includes/header' and `includes/footer'.
+
+For example `inlcudes/header' may contain
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
+<link rel="stylesheet" type="text/css" media="screen, projection" href="style.css" />
+<link rel="stylesheet" type="text/css" media="print" href="print.css" />
+
+and `inlcudes/footer' may contain
+
+ </body>
+</html>
+
+and perhaps an additional footer line to be displayed in all pages.
+
+Now write some content in the file `source/index.html' and then run mowyw.
+You should get an output like that:
+
+Processing File 'source/index.html'... DONE.
+
+Now point your browser at source/index.html and see if it worked.
+Files not ending in .html, .htm, .shtml, .xhtml etc. are not processed, just
+copyied.
+
+
+INCLUDES:
+
+So far mowyw didn't do much work for you, it just added header and footer
+sections to all html files.
+But it can do more for you: includes.
+Just use the line
+
+[[[include foo]]]
+
+in your files, and the line will be replaced with the content of the file
+`includes/foo'. It works pretty much like #inlcude "includes/foo" with a C pre
+processor or <!-- #include virtual="includes/foo"--> with Server Side Includes
+(SSI).
+
+MENUS:
+
+Suppose you want to write a navigation menu in your html files that look like
+this:
+
+menu
+ |
+ +-- foo
+ |
+ +-- bar
+ |
+ +-- baz
+
+and if you click on foo, a sub menu opens:
+
+menu
+ |
+ +-- foo
+ | |
+ | +-foo1
+ | +-foo2
+ | +-foo3
+ |
+ +-- bar
+ |
+ +-- baz
+
+The way you do this with mowyw is simple:
+create a file called `includes/menu-navigation' and fill it with something
+like this:
+
+<div class="menu">
+Navigation:
+<ul>
+ [[[item foo <li><a href="foo.html" {{class="#active"}}>foo</a>
+ {{<ul>
+ <li><a href="foo1">foo1</a></li>
+ <li><a href="foo2">foo2</a></li>
+ </ul>}}</li>]]]
+ [[[item bar <li><a href="bar.html" {{class="#active"}}>bar</a></li>]]]
+ [[[item baz <li><a href="baz.html" {{class="#active"}}>baz</a></li>]]]
+</ul>
+</div>
+
+now in your file foo.html, you use the line
+[[[menu navigation foo]]].
+This line will be replaced by mowyw with:
+
+<div class="menu">
+Navigation:
+<ul>
+ <li><a href="foo.html" class="#active">foo</a>
+ <ul>
+ <li><a href="foo1">foo1</a></li>
+ <li><a href="foo2">foo2</a></li>
+ </ul></li>
+ <li><a href="bar.html" >bar</a></li>
+ <li><a href="baz.html" >baz</a></li>
+</ul>
+</div>
+
+Each menu item looks like this: [[[item label1 some_text]]]. If it is called as
+[[[menu label1]]] it will produce some_text, and all double curly brackets {{ }}
+are simply stripped, but the text between them remains.
+If it is called with a different name, say [[[menu label2]]], the curly brackets
+and the text between them are stripped.
+
+VERBATIM OUTPUT
+
+If your website includes string like [[[ or ]]] etc., you can use the
+verbatim-construct to prevent it from parsing:
+
+[[[verbatim foobarbaz]]]
+Things here inbetween will be printed out exactly as they stand here, you can
+safely write things like
+"in perl6 [...] returns array refs:
+my $a = [2, [4, 5, [8, 9,10]]];"
+note that the ']]]' will not cause any harm.
+[[[endverbatim foobarbaz]]]
+
+the name in the verbatim and in the endverbatim-package have to agree exactly
+and my consist of alphabetic characters and numbers.
+
+
+OMITTING HEADER AND FOOTER
+
+If you include a line like this:
+[[[option no-header]]]
+the header is _not_ prepended as usual.
+You can achieve the following functionality for the footer with the line
+[[[option no-footer]]]
+
+
+LIMITATIONS & BUGS
+ * Currently mowyw is not very flexible in many ways, for example files
+ outside the `include/' directory can't be included.
+
+
+LICENSE:
+ This README file is covered by the GPL (2 or later), however
+ the code examples in this file are public domain, e.g. you may use it
+ however you like.
+ The program mowyw is published under the GPL, for details see the
+ executable
13 TODO
@@ -0,0 +1,13 @@
+TODO:
+ * use configurable prefixes/postfixes 12/2006
+ * Add more magic ;-) 12/2006
+ * more testing 12/2006
+ * print includes pathes in error messages 12/2006
+ * make parser more robust 12/2006
+
+DONE:
+(items formerly on the todo list)
+ * modify parser so that {{ and }} loose their special meaning outside of an
+ [[item]] 12/2006, fixed 12/2006
+ * Implement nested menu items 12/2006, fixed 12/2006
+ * usefull examples 12/2006 fixed 01/2007
@@ -0,0 +1 @@
+[[[include head2]]]
@@ -0,0 +1,6 @@
+<p id="footer">
+Powered by <a href="http://moritz.faui2k3.org/en/mowyw">mowyw</a> | <a href="#">Imprint</a> | Design by Dimiter Petrov
+</p>
+
+</body>
+</html>
@@ -0,0 +1,17 @@
+</head>
+
+<body id="home">
+
+<div id="header">
+ <h1>Mowyw Example</h1>
+ <p>Lore Impsum</p>
+</div>
+<div id="nav-page">
+<h2>Quick access</h2>
+<ul>
+<li><a href="#nav-main">Site navigation</a></li>
+<li><a href="#nav-secondary">Recent articles</a></li>
+</ul>
+</div>
+
+<div id="content-main">
@@ -0,0 +1,8 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
+<link rel="stylesheet" type="text/css" media="screen, projection" href="style.css" />
+<link rel="stylesheet" type="text/css" media="print" href="print.css" />
@@ -0,0 +1,17 @@
+<div id="nav-main">
+<h2>Navigation</h2>
+<ul>
+[[[item home <li><a {{class="active"}} href="index.shtml">Home</a></li>]]]
+[[[item foo <li><a {{class="active"}} href="foo.shtml">foo</a>
+{{
+ <ul>
+ [[[item foo1 <li><a href="foo1.shtml" {{class="active"}}
+ style="margin-left:2em!important">foo1</a></li>]]]
+ [[[item foo2 <li><a href="foo2.shtml" {{class="active"}}
+ style="margin-left:2em!important">foo2</a></li>]]]
+ </ul>
+}}</li>]]]
+[[[item bar <li><a {{class="active"}} href="bar.shtml">bar</a></li>]]]
+</ul>
+</div>
+
@@ -0,0 +1,9 @@
+Options +FollowSymLinks +Includes
+
+AddType 'text/html; charset=ISO-8859-1' shtml
+AddOutputFilter INCLUDES .shtml
+
+DirectoryIndex index.shtml
+
+RewriteEngine On
+#ErrorDocument 404 /404
Oops, something went wrong.

0 comments on commit 52f3521

Please sign in to comment.