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