Changeset 21 in text-formbuilder for trunk/lib/Text/FormBuilder/grammar


Ignore:
Timestamp:
11/12/04 16:54:23 (20 years ago)
Author:
peter
Message:

added !group and !field directive to the language to allow for horizontal groups of input fields
moving to a new representation of the parsed formspec based on lines as opposed to fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Text/FormBuilder/grammar

    r16 r21  
    1 { my ($title, $author, $description, %lists, %patterns, @fields, @headings, $type, @options, $list_var, $size, $rows, $cols); } 
     1{  
     2    my ( 
     3        $context,      # line or group 
     4        @lines,        # master data structure 
     5        $title, 
     6        $author, 
     7        $description, 
     8        %lists, 
     9        %patterns, 
     10        @fields, 
     11        @group,        # current group 
     12        %groups,       # stored groups of fields 
     13        @headings, 
     14        $type, 
     15        @options, 
     16        $list_var, 
     17        $size, 
     18        $rows, 
     19        $cols, 
     20    ); 
     21    $context = 'line'; 
     22} 
    223 
    3 form_spec: (list_def | description_def | line)(s)  
     24form_spec: (list_def | description_def | group_def | line)(s)  
    425    { 
    526        $return = { 
     
    1132            headings => \@headings, 
    1233            fields   => \@fields, 
     34            lines    => \@lines, 
     35            groups   => \%groups, 
    1336        } 
    1437    } 
     
    3659    } 
    3760 
    38 line: <skip:'[ \t]*'> ( title | author | pattern_def | heading | unknown_directive | field | comment | blank ) "\n" 
     61group_def: '!group' { $context = 'group' } var_name '{' field_line(s) '}' { $context = 'line' } 
     62    {  
     63        #warn "$item{var_name} group; context $context\n" 
     64        $groups{$item{var_name}} = [ @group ]; 
     65        @group = (); 
     66    } 
     67 
     68field_line: <skip:'[ \t]*'> ( field | comment | blank ) "\n" 
     69line: <skip:'[ \t]*'> ( title | author | pattern_def | heading | group_field | unknown_directive | field | comment | blank ) "\n" 
    3970 
    4071title: '!title' /.*/ 
     
    5182 
    5283heading: '!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] } 
     84    { 
     85        warn "[Text::FormBuilder] Header before field " . scalar(@fields) . " redefined at input text line $thisline\n" if defined $headings[@fields]; 
     86        $headings[@fields] = $item[2]; 
     87        push @lines, [ 'head', $item[2] ]; 
     88    } 
     89 
     90group_field: '!field' group_name name label(?) 
     91    { #warn "[$thisline] $item{group_name}\n";  
     92    push @lines, [ 'group', { name => $item{name}, label => $item{'label(?)'}[0], group => $item{group_name} } ]; 
     93    } 
     94 
     95group_name: /%[A-Z_]+/ 
    5596 
    5697field: name field_size(?) label(?) hint(?) type(?) default(?) option_list(?) validate(?) 
     
    72113        $$field{size} = $size if defined $size; 
    73114         
    74         push @fields, $field; 
     115        #warn "[$thisline] field $item{name}; context $context\n";    
     116        if ($context eq 'group') { 
     117            push @group, $field; 
     118        } else { 
     119            push @fields, $field; 
     120            push @lines, [ 'field', $field ]; 
     121        } 
    75122         
    76123        $type = undef; 
     
    95142    { $rows = $item[1]; $cols = $item[3] } 
    96143 
    97 label: '|' /[^:\[\{\/]+/i 
     144#TODO: zero width labels 
     145label: '|' /[^:\[\{\/\n]*/i { $item[2] } 
    98146 
    99147hint: '[' /[^\]]+/ ']'    { $item[2] } 
Note: See TracChangeset for help on using the changeset viewer.