From: Martin Mares Date: Wed, 22 Sep 2004 19:16:36 +0000 (+0000) Subject: Testing. X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=403340085953889dd44787781b0832fbabdf0524;p=temple.git Testing. --- diff --git a/temple b/temple index 8257f4c..e8d2072 100755 --- a/temple +++ b/temple @@ -85,6 +85,8 @@ sub process_string($) { # @ at end of line is ignored and eats the end of line } elsif ($t =~ /\G\@#[^\n]*\n/cgs) { # a comment, which is ignored + } elsif ($t =~ /\G\@\@/cgs) { + print "\@"; } elsif ($t =~ /\G\@{/cgs) { my $x = get_nested(\$t, "{", "}"); print eval_if_ok($x); @@ -102,7 +104,7 @@ sub process_string($) { } elsif ($t =~ /\G\@(\$\w+)/cgs) { print eval_if_ok($1); } elsif ($t =~ /\G(\@[^\n]*)/cgs) { - die "Unknown directive $1"; + die "Unknown control sequence $1"; } elsif ($t =~ /\G$/cgs) { last; } elsif ($t =~ /\G([^\n]*)/cgs) { diff --git a/test b/test new file mode 100644 index 0000000..c857c41 --- /dev/null +++ b/test @@ -0,0 +1,70 @@ +@# A test program for Temple +@# starts with a couple of comments + +@# The language is very simple -- everything except the "@" character +@# gets passed to the output verbatim: +Verbatim. + +@# The "@" starts a control sequence. Arguments of control sequences +@# are either everything to the end of the current line (as in case +@# of the comment command you are looking at) balanced parenthesized +@# string. +@# + +@# If we want to ignore and end of line character, just prefix it by "@": +This line @ +won't be broken@ +. + +@# If you want to write the "@" character, just write it twice: +@@ + +@# You can embed any perl code in your text: +@[foreach $x (1..10) { print "$x "; } ] + +@# Or if you use @{...}, then the value of the last expression executed +@# gets printed automatically: +@{"1+2+3 = " . (1+2+3)} + +@# You can also interpolate perl variables by using @$variable: +I was run as @$0. + +@# It is possible to call any perl functions (result will be discarded): +@print("One", "Two", "Three\n") + +@# Or do the same with parameters running up to the end of the line: +@print "Four", "Five", "Six\n" + +@# There are also some conditionals (you can use any perl expressions): +@if 1 +@if 0 +one +@elif 0 +two +@elif 1 +three +@fi +@else +four +@fi + +@# Or you can use the parenthesized form: +@if(0)ONE@else()TWO@fi()THREE + +@# To include another file (and possibly change some variables), use: +@include("test2", "a" => "HOWDY", "b" => "HULLO", "c" => "AHOY") +@include "test2", "a" => "howdy", "b" => "hullo", "c" => "ahoy" + +@# And to load a perl file: +@load "test3" + +@# This one is tricky: +@print("z\n", <@ diff --git a/test3 b/test3 new file mode 100644 index 0000000..a41bf38 --- /dev/null +++ b/test3 @@ -0,0 +1,2 @@ +print "oook!\n"; +1;