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' var_name (static_list | dynamic_list) |
---|
17 | { $lists{$item{var_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 | description_def: '!description' <perl_codeblock> |
---|
32 | { warn "[Text::FormBuilder] Description redefined at input text line $thisline\n" if defined $description; |
---|
33 | |
---|
34 | $description = $item[2]; |
---|
35 | $description =~ s/^{\s*|\s*}$//g; |
---|
36 | } |
---|
37 | |
---|
38 | line: <skip:'[ \t]*'> ( title | author | pattern_def | heading | unknown_directive | field | comment | blank ) "\n" |
---|
39 | |
---|
40 | title: '!title' /.*/ |
---|
41 | { warn "[Text::Formbuilder] Title redefined at input text line $thisline\n" if defined $title; |
---|
42 | $title = $item[2] } |
---|
43 | |
---|
44 | author: '!author' /.*/ |
---|
45 | { $author = $item[2] } |
---|
46 | |
---|
47 | pattern_def: '!pattern' var_name pattern |
---|
48 | { $patterns{$item{var_name}} = $item{pattern} } |
---|
49 | |
---|
50 | pattern: /.*/ |
---|
51 | |
---|
52 | heading: '!head' /.*/ |
---|
53 | { warn "[Text::FormBuilder] Header before field " . scalar(@fields) . " redefined at input text line $thisline\n" if defined $headings[@fields]; |
---|
54 | $headings[@fields] = $item[2] } |
---|
55 | |
---|
56 | field: name field_size(?) label(?) hint(?) type(?) default(?) option_list(?) validate(?) |
---|
57 | { |
---|
58 | my $field = { |
---|
59 | name => $item{name}, |
---|
60 | label => $item{'label(?)'}[0], |
---|
61 | comment => $item{'hint(?)'}[0], |
---|
62 | type => $item{'type(?)'}[0], |
---|
63 | value => $item{'default(?)'}[0], |
---|
64 | list => $list_var, |
---|
65 | validate => $item{'validate(?)'}[0], |
---|
66 | }; |
---|
67 | |
---|
68 | $$field{options} = [ @options ] if @options; |
---|
69 | |
---|
70 | $$field{rows} = $rows if defined $rows; |
---|
71 | $$field{cols} = $cols if defined $cols; |
---|
72 | $$field{size} = $size if defined $size; |
---|
73 | |
---|
74 | push @fields, $field; |
---|
75 | |
---|
76 | $type = undef; |
---|
77 | $list_var = undef; |
---|
78 | $size = undef; |
---|
79 | $rows = undef; |
---|
80 | $cols = undef; |
---|
81 | @options = (); |
---|
82 | |
---|
83 | } |
---|
84 | |
---|
85 | name: identifier |
---|
86 | |
---|
87 | var_name: /[A-Z_]+/ |
---|
88 | |
---|
89 | field_size: '[' ( row_col | size ) ']' |
---|
90 | |
---|
91 | size: /\d+/ |
---|
92 | { $size = $item[1] } |
---|
93 | |
---|
94 | row_col: /\d+/ /,\s*/ /\d+/ |
---|
95 | { $rows = $item[1]; $cols = $item[3] } |
---|
96 | |
---|
97 | label: '|' /[^:\[\{\/]+/i |
---|
98 | |
---|
99 | hint: '[' /[^\]]+/ ']' { $item[2] } |
---|
100 | |
---|
101 | type: ':' /textarea|text|password|file|checkbox|radio|select|hidden|static/ |
---|
102 | |
---|
103 | default: '=' /[^\@\{\s]+/ |
---|
104 | |
---|
105 | option_list: options | list_var |
---|
106 | |
---|
107 | options: '{' option(s /,\s*/) '}' |
---|
108 | |
---|
109 | list_var: /@[A-Z_]+/ { $list_var = $item[1] } |
---|
110 | |
---|
111 | option: value display_text(?) |
---|
112 | { push @options, { $item{value} => $item{'display_text(?)'}[0] } } |
---|
113 | |
---|
114 | value: identifier |
---|
115 | |
---|
116 | display_text: '[' /[^\]]+/i ']' { $item[2] } |
---|
117 | |
---|
118 | validate: '//' value |
---|
119 | |
---|
120 | comment: '#' /.*/ |
---|
121 | blank: |
---|
122 | |
---|
123 | identifier: /\w+/ |
---|
124 | |
---|
125 | # skip unknown directives with a warning |
---|
126 | unknown_directive: /\!\S*/ /.*/ |
---|
127 | { warn "[Text::Formbuilder] Skipping unknown directive '$item[1]' at input text line $thisline\n"; } |
---|