line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#Copyright 2007-8 Arthur S Goldstein |
2
|
|
|
|
|
|
|
#TESTING PHASE |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Parse::Stallion::CSV; |
5
|
1
|
|
|
1
|
|
24290
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
86
|
|
6
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
8
|
1
|
|
|
1
|
|
966
|
use Parse::Stallion; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
542
|
|
9
|
|
|
|
|
|
|
#use Data::Dumper; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION='0.5'; |
12
|
|
|
|
|
|
|
#Copied somewhat from rfc1480 |
13
|
|
|
|
|
|
|
# see for reference: http://tools.ietf.org/html/rfc4180 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %with_header_csv_rules = ( |
16
|
|
|
|
|
|
|
file => AND( |
17
|
|
|
|
|
|
|
'header', |
18
|
|
|
|
|
|
|
'CRLF', |
19
|
|
|
|
|
|
|
'record', |
20
|
|
|
|
|
|
|
MULTIPLE(AND('CRLF', 'record')), |
21
|
|
|
|
|
|
|
OPTIONAL('CRLF') |
22
|
|
|
|
|
|
|
, |
23
|
|
|
|
|
|
|
EVALUATION(sub { |
24
|
|
|
|
|
|
|
#use Data::Dumper;print STDERR "withhead params are ".Dumper(\@_)."\n"; |
25
|
|
|
|
|
|
|
return {header => $_[0]->{header}, records => $_[0]->{record}}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
)), |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
header => AND('name', MULTIPLE(AND('COMMA', 'name')), |
30
|
|
|
|
|
|
|
EVALUATION(sub {return $_[0]->{name}})) |
31
|
|
|
|
|
|
|
, |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
record => AND('field', MULTIPLE(AND('COMMA', 'field')), |
34
|
|
|
|
|
|
|
EVALUATION(sub { |
35
|
|
|
|
|
|
|
#use Data::Dumper;print STDERR "record params are ".Dumper(\@_)."\n"; |
36
|
|
|
|
|
|
|
return $_[0]->{field}})) |
37
|
|
|
|
|
|
|
, |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
name => AND('field'), |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
field => OR('escaped', 'non_escaped'), |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
escaped => AND('DQUOTE', 'inner_escaped', 'DQUOTE', |
44
|
|
|
|
|
|
|
EVALUATION(sub { |
45
|
|
|
|
|
|
|
#use Data::Dumper;print STDERR "escaped params are ".Dumper(\@_)."\n"; |
46
|
|
|
|
|
|
|
return $_[0]->{inner_escaped}}) |
47
|
|
|
|
|
|
|
), |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
ie_choices=>OR('TEXTDATA','COMMA','CRLF','DDQUOTE'), |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
inner_escaped => |
52
|
|
|
|
|
|
|
MULTIPLE('ie_choices' |
53
|
|
|
|
|
|
|
, |
54
|
|
|
|
|
|
|
EVALUATION(sub { |
55
|
|
|
|
|
|
|
#use Data::Dumper;print STDERR "ie params are ".Dumper(\@_)."\n"; |
56
|
|
|
|
|
|
|
my $param = shift; |
57
|
|
|
|
|
|
|
return join('', @{$param->{'ie_choices'}}); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
)), |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
DDQUOTE => AND('DQUOTE','DQUOTE', |
62
|
|
|
|
|
|
|
EVALUATION(sub {return '"'}) |
63
|
|
|
|
|
|
|
), |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
non_escaped => AND('TEXTDATA'), |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
COMMA => LEAF(qr/\x2C/), |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# CR => LEAF(qr/\x0D/), |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
DQUOTE => LEAF(qr/\x22/), |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# LF => LEAF(qr/\x0A/), |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
#CRLF => AND('CR','LF'), |
76
|
|
|
|
|
|
|
CRLF => LEAF(qr/\n/) |
77
|
|
|
|
|
|
|
# evaluation => |
78
|
|
|
|
|
|
|
# sub { |
79
|
|
|
|
|
|
|
# my $param = shift; |
80
|
|
|
|
|
|
|
## print STDERR "Parsm to crlf are ".Dumper($param)."\n"; |
81
|
|
|
|
|
|
|
# return "\n"; |
82
|
|
|
|
|
|
|
# } |
83
|
|
|
|
|
|
|
, |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
TEXTDATA => LEAF(qr/[\x20-\x21\x23-\x2B\x2D-\x7E]+/) |
86
|
|
|
|
|
|
|
, |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub new { |
91
|
1
|
|
|
1
|
0
|
14
|
my $self = shift; |
92
|
1
|
|
|
|
|
3
|
my $parameters = shift; |
93
|
1
|
|
|
|
|
11
|
return new Parse::Stallion( |
94
|
|
|
|
|
|
|
\%with_header_csv_rules, {start_rule=>'file'}); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |