source: text-formbuilder/trunk/lib/Text/FormBuilder/grammar @ 13

Last change on this file since 13 was 11, checked in by peter, 20 years ago

added a !head directive for section headers in forms
removed generated Parser.pm file from version control

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