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