]> mj.ucw.cz Git - temple.git/commitdiff
Testing.
authorMartin Mares <mj@ucw.cz>
Wed, 22 Sep 2004 19:16:36 +0000 (19:16 +0000)
committerMartin Mares <mj@ucw.cz>
Wed, 22 Sep 2004 19:16:36 +0000 (19:16 +0000)
temple
test [new file with mode: 0644]
test2 [new file with mode: 0644]
test3 [new file with mode: 0644]

diff --git a/temple b/temple
index 8257f4cd6213cb9e8ed7e14c74db50a77cd7daaa..e8d2072d49d730ad9652fa45cb3f1ece7a191d78 100755 (executable)
--- 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 (file)
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", <<EOF
+a
+b
+c
+EOF
+)
+
+@# We are done:
+Finis.
diff --git a/test2 b/test2
new file mode 100644 (file)
index 0000000..3cbff6b
--- /dev/null
+++ b/test2
@@ -0,0 +1 @@
+$c is <@$c>@
diff --git a/test3 b/test3
new file mode 100644 (file)
index 0000000..a41bf38
--- /dev/null
+++ b/test3
@@ -0,0 +1,2 @@
+print "oook!\n";
+1;