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

Last change on this file since 9 was 1, checked in by peter, 20 years ago

initial import

File size: 2.2 KB
RevLine 
[1]1{ my ($title, $author, %lists, %patterns, @fields, $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            fields   => \@fields,
11        }
12    }
13
14list_def: '!list' list_name '{' option(s /,\s*/) /,?/ '}'
15    { $lists{$item{list_name}} = [ @options ]; @options = () }
16
17list_name: /[A-Z_]+/
18
19line: <skip:'[ \t]*'> ( title | author | pattern_def | field | comment | blank ) "\n"
20
21title: '!title' /.*/
22    { warn "[Text::Formbuilder] Title redefined at input text line $thisline\n" if defined $title;
23    $title = $item[2] }
24
25author: '!author' /.*/
26    { $author = $item[2] }
27
28pattern_def: '!pattern' pattern_name pattern
29    { $patterns{$item{pattern_name}} = $item{pattern} }
30
31pattern_name: /[A-Z_]+/
32pattern: /.*/
33
34field: 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   
63name: identifier
64
65field_size: '[' ( row_col | size ) ']'
66
67size: /\d+/
68    { $size = $item[1] }
69
70row_col: /\d+/ /,\s*/ /\d+/
71    { $rows = $item[1]; $cols = $item[3] }
72
73label: '|' /[^:\[\{\/]+/i
74
75hint: '[' /[^\]]+/ ']'    { $item[2] }
76
77type: ':' /textarea|text|password|file|checkbox|radio|select|hidden|static/
78
79default: '=' /[^\@\{\s]+/
80
81option_list: options | list_var
82   
83options: '{' option(s /,\s*/) '}'
84
85list_var: /@[A-Z_]+/ { $list_var = $item[1] }
86
87option: value display_text(?)
88    { push @options, { $item{value} => $item{'display_text(?)'}[0] } }
89
90value: identifier
91
92display_text: '[' /[^\]]+/i ']'    { $item[2] }
93
94validate: '//' value
95
96comment: '#' /.*/
97blank:
98
99identifier: /\w+/
Note: See TracBrowser for help on using the repository browser.