
*(grammar) `default_awiki_grammar'

  document:		outline_parser(essay, section);
     ;
     ; A document is an outline (similar in format to
     ; outline in Emacs, optionally preceeded by a
     ; lead section (an essay).

  section:		section_parser(section_title, section_body);
     ;
     ; A section has just two parts: a title and the body 
     ; of the section.

  section_title:	lines_parser(styled_text);
     ;
     ; A section title is a list of lines of styled
     ; text.   It's considered a list of lines rather
     ; than a "paragraph" because line-breaks in this
     ; list are considered significant.

  section_body:		outline_parser(essay, section);
     ;
     ; The body of an outline resembles a recursive
     ; document.  It, too, has an outline structure 
     ; comprised of a lead essay followed by a section.

  essay:		paragraph_parser(paragraph);
     ;
     ; Essays are the parts of outlines not divided
     ; up into outline-style subsections.   The primary 
     ; bodies of outline nodes, sort-of.
     ; 
     ; By default, subnodes of an essay are parsed as
     ; paragraphs.

  paragraph:		styled_text_parser(plain_text);
      ;
      ; A paragraph is a list of fragments of plain_text
      ; mixed with stylized text and in-line displays.

  plain_text:		--not parsed--;
      ;
      ; Plain text nodes are leaf nodes in the parse tree.
      ; They are not recursively parsed.

  emph_text,
  emph_b_text,
  stress_text,
  stress_b_text,
  styled_text:		styled_text_parser(plain_text,
                                           epmh_text,
                                           epmh_b_text,
                                           stress_text,
                                           stress_b_text,
                                           code_text,
                                           link,
                                           reference,
                                           definition,
                                           image);


   code_text:		--not parsed--;

   link, image:		link_parser(styled_text, url);

   url:			--not parsed--;

   reference,
   definition:		reference_parser(styled_text, refcode);

   refcode:		--not parsed--;

   tty:			--not parsed--;

   title:		dash3_block_parser(main_title, subtitle);

   main_title:		lines_parser(styled_text);

   subtitle:		lines_parser(styled_text);

   abstract:		dash3_2part_first_opt_parser(abstract_title,
						     essay);


   abstract_title:	lines_parser(styled_text);

   quote:		attributed_paragraph_parser(paragraph);

   outline:		outline_parser(essay, section);

   poem:		dash3_2part_second_opt_parser(essay,
                                                      poem_attribution); 

   poem_attribution:	lines_parser(styled_text);

   poem_b:		dash3_2part_second_opt_parser(essay,
                                                      poem_b_attribution); 

   poem_b_attribution:	lines_parser(styled_text);

   cartouche:		paragraph_parser(paragraph);

   cartouche_b:		paragraph_parser(paragraph);

   tty:			paragraph_parser(paragraph);

   tty_b:		paragraph_parser(paragraph);



  


*(parsers) `default_awiki_parsers'

** `outline_parser (lead_type, default_section_type)'

  An outline consists of an optional lead section followed
  by 0 or more outline sections.

  Outline sections are marked by lines with `*' or `+'
  in column 0 and by lines marked with non-empty lists
  of `*' or `+', followed by a `.', as the first non-blank
  characters of a line.

  After the first section marker, successive section markers
  only "count" (only actually divide up the body into
  top-level outline sections) if they are both indented
  the same amount or less than the previous top-level
  section header and if the numbers of '*' and '+' characters
  they contain is less than or equal to the numbers in the
  previous section header.

  [[parser-params

    first_separator_regexp: 
	beginning of /^([*+]+|[[:blank:]]*[*+]+\.)/;

    subsequent_separators_regexp:
	beginning of /^([*+]+|[[:blank:]]*[*+]+\.)/
        with constraints
	   similar_indentation
           same_or_fewer_chars('*')
           same_or_fewer_chars('+');

    lead_section_handling: skip_if_whitespace;

    default_lead_type: lead_type;

    default_subsequent_type: default_section_type;

    subsequent_start_of_type_regexp:
      end of  /[[:blank:]]*[*+]+\.?\(/;

    subsequent_start_of_body_regexp:
       end of /^[[:blank:]]*\n/
  ]]

** `section_parser (title_type, body_type)'

  A section consists of an opening marker (e.g., `*** ' in column 0 or
  `***.' in column 5).

  The opening markers are followed, on the same line and on subsequent
  lines not separated by blank lines, by a *section title*.

  The rest of the input is taken as the section body and 
  is parsed with the `body_type' parameter.

  [[parser-params

    first_separator_regexp: 
	beginning of /^[[:blank:]]*$/

    subsequent_separators_regexp:
	--none--

    lead_section_handling: null_if_whitespace;

    lead_start_of_body_regexp:
        end of /^[[:blank:]][*+]+\.?(\([[:alpha:]][-[:alnum:]]*\))?;

    default_lead_type: title_type;

    default_subsequent_type: body_type;
  ]]


** `lines_parser (line_type)'

  A "lines" region consists of lines in which the newline are
  significant.   Each line should be parsed separately.

  [[parser-params

    first_separator_regexp:
	end of /\n/

    subsequent_separators_regexp:
        end of /\n/

    lead_section_handling: always;

    default_lead_type: line_type;

    default_subsequent_type: line_type;
  ]]


** `paragraph_parser (default_paragraph_type, default_dbar_type, default_display_type)'

  A "paragraph" is a tricky beast.

  If a paragraph begins with a line like:

  [[tty

        ||.some-type blah blah blah
        yadda yadda yadda
        etc. etc.
        ~~

  ]]

  then the paragraph ends with the next similarly indented
  `||' line or line containing just `~~'.   Such a paragraph
  is parsed as `some-type' although that can be ommitted and
  a context-specific default used (the `default_dbar_type').

  If a paragraph looks like:

  [[tty

      [[some-display
         ...
      ]]
  ]]

  then it is parsed as a `some-display' type.  The closing ']]' 
  is optional: indentation alone determines the end of the display
  content.

  Otherwise, a paragraph begins with a non-blank line and is
  terminated by the first blank line.

  We forgoe any lead section.  The `first_separator_regexp' is
  used just to find the first non-blank line.

  [[parser-params

    first_separator_regexp:
      beginning of /^[[:blank:]]*[^[[:space:]]]/;

    subsequent_separators_regexp:
      end of /\n/			; i.e., the next line
        with constraints
          (prev_sep_matches /^[[:blank:]]*\[\[/ and similarly indented)
        or
          (prev_sep_matches /^[[:blank:]]*\|\|/ and
           this_sep_matches /^[[:blank:]]*(\|\||~~)/ and
           similarly indented)
        or
           prev_sep didn't match either of those and
           this_sep_matches /^[[:blank:]]*$/;

     start_type_regexp:
       end of /^[[:blank:]](\|\|\.|\[\[)/;

     start_body_regexp:
       end of /^[[:blank:]]((\|\|\.|\[\[)([[:alpha:]][-[:alnum:]]*)?)?/;


     lead_section_handling: always;

     default-type:
       if (this_sep_matches .... || )
         default_dbar_type
       else if (this_sep_matches .... [[ )
         default_display_type
       else
         default_paragraph_type
         
  ]]





; arch-tag: Tom Lord Fri Dec  3 14:11:13 2004 (awiki/grammar)
