NAME ^

PCT::Grammar - base grammar with useful rules

SYNOPSIS ^

    grammar MyGrammar is PCT::Grammar;

    rule abc { [ word | <panic: word not found> ] }

    rule quote {
        [ \' <string_literal: '> \'
        | \" <string_literal: "> \"
        ]
    }

DESCRIPTION ^

This file implements PCT::Grammar, which is a basic grammar object with a few useful methods for parsing thrown in.

Methods ^

panic(match [, message, ...] )

Throws an exception at the current point of the match, with message as part of the exception payload. The message doesn't end with a newline, then the line number and offset of the match are also included.

item()

Here we overload the item() method from PGE::Match to throw an exception if a result object hasn't been set.

ww()

Special-purpose rule to return true if we're in the middle of a word -- i.e., if the previous and next character are both "word characters". This is roughly equivalent to <?after \w><?before \w> except it's much quicker. In particular, <!ww> can be used by :sigspace rules to enforce whitespace between lexical words.


parrot