line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Flowchart::Script::Lexer; |
2
|
1
|
|
|
1
|
|
11
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
4
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
69
|
|
4
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
5
|
|
|
|
|
|
|
our @EXPORT = qw(Feed Lexer); |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
2036
|
use Lex; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our %patt = ( |
9
|
|
|
|
|
|
|
D => '[0-9]', |
10
|
|
|
|
|
|
|
L => '[a-zA-Z_]', |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @tokens = |
15
|
|
|
|
|
|
|
( |
16
|
|
|
|
|
|
|
'COMMENT' => qr'/\*.+?\*/'so, |
17
|
|
|
|
|
|
|
'IDENTIFIER' => qr"$patt{L}($patt{D}|$patt{L})*"o, |
18
|
|
|
|
|
|
|
'STRING_LITERAL' => $patt{L}.'?(\'|\")(\\.|[^\\"])*\1', |
19
|
|
|
|
|
|
|
'CONSTANT' => qr"$patt{D}+"o, sub { "'$_[1]'" }, |
20
|
|
|
|
|
|
|
'LEFTP' => '\(', |
21
|
|
|
|
|
|
|
'RIGHTP' => '\)', |
22
|
|
|
|
|
|
|
'LEFTSB' => '\[', |
23
|
|
|
|
|
|
|
'RIGHTSB' => '\]', |
24
|
|
|
|
|
|
|
'RELATE_OP' => '\->', |
25
|
|
|
|
|
|
|
'COLON' => '[:]', |
26
|
|
|
|
|
|
|
'COMMA' => qr'(,|=>)'o, |
27
|
|
|
|
|
|
|
'ASSIGN' => '[=]', |
28
|
|
|
|
|
|
|
'EOS' => '[;]', |
29
|
|
|
|
|
|
|
'NEWLINE' => '[\n]', |
30
|
|
|
|
|
|
|
'TAB' => '[\t]', |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
'ERROR' => '.+', sub { die "Unknown lexicon ( $_[1] ) encountered\n" } |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $lexer = Lex->new(@tokens); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub Feed{ |
38
|
|
|
|
|
|
|
my $src = shift; |
39
|
|
|
|
|
|
|
my $code; |
40
|
|
|
|
|
|
|
if($src && -f $src){ |
41
|
|
|
|
|
|
|
local $/; |
42
|
|
|
|
|
|
|
open _, $src or die $!; |
43
|
|
|
|
|
|
|
$code=<_>; |
44
|
|
|
|
|
|
|
close _; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif($src){ |
47
|
|
|
|
|
|
|
$code = $src; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else{ |
50
|
|
|
|
|
|
|
local $/; |
51
|
|
|
|
|
|
|
print ">> Enter your source code from STDIN\n\n"; |
52
|
|
|
|
|
|
|
$code = ; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
$lexer->from($code); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub Lexer{ |
58
|
|
|
|
|
|
|
TOKEN: |
59
|
|
|
|
|
|
|
my $token = $lexer->nextToken; |
60
|
|
|
|
|
|
|
if (not $lexer->eof) { |
61
|
|
|
|
|
|
|
goto TOKEN if $token->name eq __PACKAGE__.'::NEWLINE'; |
62
|
|
|
|
|
|
|
goto TOKEN if $token->name eq __PACKAGE__.'::TAB'; |
63
|
|
|
|
|
|
|
goto TOKEN if $token->name eq __PACKAGE__.'::COMMENT'; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my ($type, $value) = ($token->name(), $token->get()); |
66
|
|
|
|
|
|
|
$type=~s/^.+::(.+)/$1/o; |
67
|
|
|
|
|
|
|
goto TOKEN if $type eq 'COMMENT'; |
68
|
|
|
|
|
|
|
$value =~ s/\n//go; |
69
|
|
|
|
|
|
|
return ($type, $value); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
return ('', undef); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |