# Copyright (C) 2008, The Perl Foundation.
# $Id: /mirror/trunk/languages/perl6/src/utils/perl6doc/grammar.pg 32030 2008-10-17T01:55:12.195327Z particle  $

=begin Introduction

This is the rules portion of the grammar for the Rakudo document reader.
This grammar is based on the STD.pm grammar available from
L<http://svn.pugscode.org/pugs/src/perl6/STD.pm>.

=end   Introduction

grammar Perl6doc::Grammar is PCT::Grammar;

token TOP { [ .*? <pod_comment> ]* {*} }


token unsp {
    \\ <.before [\s|'#']>
    [ \v | \h+ ]*
}

####  pod  ####

## The <pod_comment> token is used to match perl 6 pod comments.
## It's currently incomplete, but so is the spec.

token pod_comment {
    $<block>=[
    | <pod_delimited_block>
    | <pod_paragraph_block>
    | <pod_abbreviated_block>
    ] \n {*}
}

token pod_delimited_block {
    ^^ '=' <.unsp>? 'begin' <.ws> <block_type> <pod_numbered>? <pod_option>* \n
    $<body>=(.*?):!
    ^^ '=' <.unsp>? 'end'   <.ws> $<block_type> \N*
    {*}
}

token pod_numbered { <.ws> '#' <.ws> }

token pod_option {
    [ \n '=' ]? <.ws>
    $<option>=[ ':' [
      | [ nested | numbered | term | formatted | like | allow ] >>
      | <ident>
      ]
    ]
}

token pod_paragraph_block {
    ^^ '=for' <.ws> <block_type> <pod_option>* \n
    $<body>=(.*?):!
    <.before \n ^^ [ '=' | \h* $$ ]>
    {*}
}

token pod_abbreviated_block {
    ^^ '=' <block_type> <.ws>
    $<body>=(.*?):!
    <.before \n ^^ [ '=' | \h* $$ ]>
}

token block_type { <ident> }

