Index: trunk/lib/Text/FormBuilder/grammar
===================================================================
--- trunk/lib/Text/FormBuilder/grammar	(revision 28)
+++ trunk/lib/Text/FormBuilder/grammar	(revision 29)
@@ -2,5 +2,8 @@
     my (
 	$context,      # line or group
-	@lines,        # master data structure
+	@sections,     # master data structure
+	$section_head,
+	$section_id,
+	@lines,        # lines in each section
 	$title,
 	$author,
@@ -23,4 +26,17 @@
 form_spec: (list_def | description_def | group_def | line)(s)
     {
+	# grab the last section, if there is any
+	if (@lines) {
+	    push @sections,
+		{
+		    id   => $section_id,
+		    head => $section_head,
+		    lines => [ @lines ],
+		};
+	}
+	
+	$section_id = $item{identifier};
+	$section_head = $item[3];
+	@lines = ();
 	$return = {
 	    title    => $title,
@@ -29,6 +45,6 @@
 	    lists    => \%lists,
 	    patterns => \%patterns,
-	    lines    => \@lines,
 	    groups   => \%groups,
+	    sections => \@sections,
 	}
     }
@@ -64,5 +80,5 @@
 
 field_line: <skip:'[ \t]*'> ( field | comment | blank ) "\n"
-line: <skip:'[ \t]*'> ( title | author | pattern_def | heading | group_field | unknown_directive | field | comment | blank ) "\n"
+line: <skip:'[ \t]*'> ( title | author | pattern_def | section_head | heading | group_field | unknown_directive | field | comment | blank ) "\n"
 
 title: '!title' /.*/
@@ -82,4 +98,23 @@
 
 pattern: /.*/
+
+section_head: '!section' identifier /.*/
+    {
+	#warn "starting section $item{identifier}\n";
+	#warn "  with heading $item[3]\n" if $item[3];
+	
+	if (@lines) {
+	    push @sections,
+		{
+		    id   => $section_id,
+		    head => $section_head,
+		    lines => [ @lines ],
+		};
+	}
+	
+	$section_id = $item{identifier};
+	$section_head = $item[3];
+	@lines = ();
+    }
 
 heading: '!head' /.*/    { push @lines, [ 'head', $item[2] ] }
