{
    "mode": "perldoc",
    "parameter": "TAP::Parser::Grammar",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/TAP%3A%3AParser%3A%3AGrammar/json",
    "generated": "2026-06-03T03:46:17Z",
    "synopsis": "use TAP::Parser::Grammar;\nmy $grammar = $self->makegrammar({\niterator => $tapparseriterator,\nparser   => $tapparser,\nversion  => 12,\n});\nmy $result = $grammar->tokenize;",
    "sections": {
        "NAME": {
            "content": "TAP::Parser::Grammar - A grammar for the Test Anything Protocol.\n",
            "subsections": []
        },
        "VERSION": {
            "content": "Version 3.43\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use TAP::Parser::Grammar;\nmy $grammar = $self->makegrammar({\niterator => $tapparseriterator,\nparser   => $tapparser,\nversion  => 12,\n});\n\nmy $result = $grammar->tokenize;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"TAP::Parser::Grammar\" tokenizes lines from a TAP::Parser::Iterator and constructs\nTAP::Parser::Result subclasses to represent the tokens.\n\nDo not attempt to use this class directly. It won't make sense. It's mainly here to ensure that\nwe will be able to have pluggable grammars when TAP is expanded at some future date (plus, this\nstuff was really cluttering the parser).\n",
            "subsections": []
        },
        "METHODS": {
            "content": "",
            "subsections": [
                {
                    "name": "Class Methods",
                    "content": "\"new\"\nmy $grammar = TAP::Parser::Grammar->new({\niterator => $iterator,\nparser   => $parser,\nversion  => $version,\n});\n\nReturns TAP::Parser grammar object that will parse the TAP stream from the specified iterator.\nBoth \"iterator\" and \"parser\" are required arguments. If \"version\" is not set it defaults to 12\n(see \"setversion\" for more details).\n"
                },
                {
                    "name": "Instance Methods",
                    "content": "\"setversion\"\n$grammar->setversion(13);\n\nTell the grammar which TAP syntax version to support. The lowest supported version is 12.\nAlthough 'TAP version' isn't valid version 12 syntax it is accepted so that higher version\nnumbers may be parsed.\n\n\"tokenize\"\nmy $token = $grammar->tokenize;\n\nThis method will return a TAP::Parser::Result object representing the current line of TAP.\n\n\"tokentypes\"\nmy @types = $grammar->tokentypes;\n\nReturns the different types of tokens which this grammar can parse.\n\n\"syntaxfor\"\nmy $syntax = $grammar->syntaxfor($tokentype);\n\nReturns a pre-compiled regular expression which will match a chunk of TAP corresponding to the\ntoken type. For example (not that you should really pay attention to this,\n\"$grammar->syntaxfor('comment')\" will return \"qr/^#(.*)/\".\n\n\"handlerfor\"\nmy $handler = $grammar->handlerfor($tokentype);\n\nReturns a code reference which, when passed an appropriate line of TAP, returns the lexed token\ncorresponding to that line. As a result, the basic TAP parsing loop looks similar to the\nfollowing:\n\nmy @tokens;\nmy $grammar = TAP::Grammar->new;\nLINE: while ( defined( my $line = $parser->nextchunkoftap ) ) {\nfor my $type ( $grammar->tokentypes ) {\nmy $syntax  = $grammar->syntaxfor($type);\nif ( $line =~ $syntax ) {\nmy $handler = $grammar->handlerfor($type);\npush @tokens => $grammar->$handler($line);\nnext LINE;\n}\n}\npush @tokens => $grammar->makeunknowntoken($line);\n}\n"
                }
            ]
        },
        "TAP GRAMMAR": {
            "content": "NOTE: This grammar is slightly out of date. There's still some discussion about it and a new one\nwill be provided when we have things better defined.\n\nThe TAP::Parser does not use a formal grammar because TAP is essentially a stream-based\nprotocol. In fact, it's quite legal to have an infinite stream. For the same reason that we\ndon't apply regexes to streams, we're not using a formal grammar here. Instead, we parse the TAP\nin lines.\n\nFor purposes for forward compatibility, any result which does not match the following grammar is\ncurrently referred to as TAP::Parser::Result::Unknown. It is *not* a parse error.\n\nA formal grammar would look similar to the following:\n\n(*\nFor the time being, I'm cheating on the EBNF by allowing\ncertain terms to be defined by POSIX character classes by\nusing the following syntax:\n\ndigit ::= [:digit:]\n\nAs far as I am aware, that's not valid EBNF.  Sue me.  I\ndidn't know how to write \"char\" otherwise (Unicode issues).\nSuggestions welcome.\n*)\n\ntap            ::= version? { comment | unknown } leadingplan lines\n|\nlines trailingplan {comment}\n\nversion        ::= 'TAP version ' positiveInteger {positiveInteger} \"\\n\"\n\nleadingplan   ::= plan skipdirective? \"\\n\"\n\ntrailingplan  ::= plan \"\\n\"\n\nplan           ::= '1..' nonNegativeInteger\n\nlines          ::= line {line}\n\nline           ::= (comment | test | unknown | bailout ) \"\\n\"\n\ntest           ::= status positiveInteger? description? directive?\n\nstatus         ::= 'not '? 'ok '\n\ndescription    ::= (character - (digit | '#')) {character - '#'}\n\ndirective      ::= tododirective | skipdirective\n\ntododirective ::= hashmark 'TODO' ' ' {character}\n\nskipdirective ::= hashmark 'SKIP' ' ' {character}\n\ncomment        ::= hashmark {character}\n\nhashmark      ::= '#' {' '}\n\nbailout        ::= 'Bail out!' {character}\n\nunknown        ::= { (character - \"\\n\") }\n\n(* POSIX character classes and other terminals *)\n\ndigit              ::= [:digit:]\ncharacter          ::= ([:print:] - \"\\n\")\npositiveInteger    ::= ( digit - '0' ) {digit}\nnonNegativeInteger ::= digit {digit}\n",
            "subsections": []
        },
        "SUBCLASSING": {
            "content": "Please see \"SUBCLASSING\" in TAP::Parser for a subclassing overview.\n\nIf you *really* want to subclass TAP::Parser's grammar the best thing to do is read through the\ncode. There's no easy way of summarizing it here.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "TAP::Object, TAP::Parser, TAP::Parser::Iterator, TAP::Parser::Result,\n",
            "subsections": []
        }
    },
    "summary": "TAP::Parser::Grammar - A grammar for the Test Anything Protocol.",
    "flags": [],
    "examples": [],
    "see_also": []
}