forked from iloveponies/120-hour-epic-sax-marathon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate-examples.pl
executable file
·55 lines (45 loc) · 1.04 KB
/
evaluate-examples.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env perl
use v5.14;
use strict;
use warnings;
use utf8::all;
use autodie;
# Main
parse();
# Subroutines
sub parse {
my @blocks;
my $current_block = "";
my $state = "out";
while (my $line = <>) {
if ($state eq "out") {
if ($line eq "~~~ {.clojure}\n") {
$state = "in";
push @blocks, $current_block . $line;
$current_block = "";
}
else {
$current_block .= $line;
}
}
elsif ($state eq "in") {
if ($line eq "~~~\n") {
$state = "out";
push @blocks, evaluate($current_block);
$current_block = $line;
}
elsif ($line eq "~~~ {.clojure}\n") {
die "syntax error;"
}
else {
$current_block .= $line;
}
}
}
push @blocks, $current_block;
say join "", @blocks;
}
sub evaluate {
my ($block) = @_;
return "EVALUATED LOL\n";
}