1 | { my ($title, $author, $description, %lists, %patterns, @fields, @headings, $type, @options, $list_var, $size, $rows, $cols); } |
---|
2 | |
---|
3 | form_spec: (list_def | description_def | line)(s) |
---|
4 | { |
---|
5 | $return = { |
---|
6 | title => $title, |
---|
7 | author => $author, |
---|
8 | description => $description, |
---|
9 | lists => \%lists, |
---|
10 | patterns => \%patterns, |
---|
11 | headings => \@headings, |
---|
12 | fields => \@fields, |
---|
13 | } |
---|
14 | } |
---|
15 | |
---|
16 | list_def: '!list' list_name (static_list | dynamic_list) |
---|
17 | { $lists{$item{list_name}} = [ @options ]; @options = () } |
---|
18 | |
---|
19 | static_list: '{' option(s /,\s*/) /,?/ '}' |
---|
20 | |
---|
21 | dynamic_list: '&' <perl_codeblock> |
---|
22 | { |
---|
23 | my @results = (eval $item[2]); |
---|
24 | if (ref $results[0] eq 'HASH') { |
---|
25 | @options = @results; |
---|
26 | } else { |
---|
27 | @options = map { { $_ => $_ } } @results; |
---|
28 | } |
---|
29 | } |
---|
30 | |
---|
31 | list_name: /[A-Z_]+/ |
---|
32 | |
---|
33 | description_def: '!description' <perl_codeblock> |
---|
34 | { warn "[Text::FormBuilder] Description redefined at input text line $thisline\n" if defined $description; |
---|
35 | |
---|
36 | $description = $item[2]; |
---|
37 | $description =~ s/^{\s*|\s*}$//g; |
---|
38 | } |
---|
39 | |
---|
40 | line: <skip:'[ \t]*'> ( title | author | pattern_def | heading | field | comment | blank ) "\n" |
---|
41 | |
---|
42 | title: '!title' /.*/ |
---|
43 | { warn "[Text::Formbuilder] Title redefined at input text line $thisline\n" if defined $title; |
---|
44 | $title = $item[2] } |
---|
45 | |
---|
46 | author: '!author' /.*/ |
---|
47 | { $author = $item[2] } |
---|
48 | |
---|
49 | pattern_def: '!pattern' pattern_name pattern |
---|
50 | { $patterns{$item{pattern_name}} = $item{pattern} } |
---|
51 | |
---|
52 | pattern_name: /[A-Z_]+/ |
---|
53 | pattern: /.*/ |
---|
54 | |
---|
55 | heading: '!head' /.*/ |
---|
56 | { warn "[Text::FormBuilder] Header before field " . scalar(@fields) . " redefined at input text line $thisline\n" if defined $headings[@fields]; |
---|
57 | $headings[@fields] = $item[2] } |
---|
58 | |
---|
59 | field: name field_size(?) label(?) hint(?) type(?) default(?) option_list(?) validate(?) |
---|
60 | { |
---|
61 | my $field = { |
---|
62 | name => $item{name}, |
---|
63 | label => $item{'label(?)'}[0], |
---|
64 | comment => $item{'hint(?)'}[0], |
---|
65 | type => $item{'type(?)'}[0], |
---|
66 | value => $item{'default(?)'}[0], |
---|
67 | list => $list_var, |
---|
68 | validate => $item{'validate(?)'}[0], |
---|
69 | }; |
---|
70 | |
---|
71 | $$field{options} = [ @options ] if @options; |
---|
72 | |
---|
73 | $$field{rows} = $rows if defined $rows; |
---|
74 | $$field{cols} = $cols if defined $cols; |
---|
75 | $$field{size} = $size if defined $size; |
---|
76 | |
---|
77 | push @fields, $field; |
---|
78 | |
---|
79 | $type = undef; |
---|
80 | $list_var = undef; |
---|
81 | $size = undef; |
---|
82 | $rows = undef; |
---|
83 | $cols = undef; |
---|
84 | @options = (); |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | name: identifier |
---|
89 | |
---|
90 | field_size: '[' ( row_col | size ) ']' |
---|
91 | |
---|
92 | size: /\d+/ |
---|
93 | { $size = $item[1] } |
---|
94 | |
---|
95 | row_col: /\d+/ /,\s*/ /\d+/ |
---|
96 | { $rows = $item[1]; $cols = $item[3] } |
---|
97 | |
---|
98 | label: '|' /[^:\[\{\/]+/i |
---|
99 | |
---|
100 | hint: '[' /[^\]]+/ ']' { $item[2] } |
---|
101 | |
---|
102 | type: ':' /textarea|text|password|file|checkbox|radio|select|hidden|static/ |
---|
103 | |
---|
104 | default: '=' /[^\@\{\s]+/ |
---|
105 | |
---|
106 | option_list: options | list_var |
---|
107 | |
---|
108 | options: '{' option(s /,\s*/) '}' |
---|
109 | |
---|
110 | list_var: /@[A-Z_]+/ { $list_var = $item[1] } |
---|
111 | |
---|
112 | option: value display_text(?) |
---|
113 | { push @options, { $item{value} => $item{'display_text(?)'}[0] } } |
---|
114 | |
---|
115 | value: identifier |
---|
116 | |
---|
117 | display_text: '[' /[^\]]+/i ']' { $item[2] } |
---|
118 | |
---|
119 | validate: '//' value |
---|
120 | |
---|
121 | comment: '#' /.*/ |
---|
122 | blank: |
---|
123 | |
---|
124 | identifier: /\w+/ |
---|