Andrius Merkys
and 1 contributors

NAME

DBIx::MyParsePP::Query - Query produced by DBIx::MyParsePP

SYNOPSIS

        use DBIx::MyParsePP;

        my $parser = DBIx::MyParsePP->new();

        my $query = $parser->parse("SELECT 1");

        if (not defined $query->root()) {
                print "Error at pos ".$query->pos()", line ".$pos->line()."\n";
        } else {
                print "Query was ".$query->toString();
        }

METHODS

getLexer() returns the DBIx::MyParsePP::Lexer object for the string

getRoot() returns a DBIx::MYParsePP::Rule object representing the root of the parse tree

toString() walks the parse tree reconstructs the query using the individual tokens.

tokens() and getTokens() returns a reference to an array containing all tokens parsed as DBIx::MyParsePP::Token objects. If the parsing failed, the list contains all tokens up to the failure point.

ERROR HANDLING

On error, getRoot() will return undef. You can call the following methods to determine the error:

getExpected() returns a list of tokens the parser expected to find, whereas getActual() returns the actual token name that was encountered which caused the error. Please note that getActual() returns a DBIx::MyParsePP::Token object, whereas getExpected() returns a list of strings, containing just the token types.

getLine() returns the line number where the error occured. getPos() returns the character position where the error occured, counting from the beginning of the string, not the begining of the line.

getTokens() can be used to reconstruct the query as it was up to the failure point.

UTILITY FUNCTIONS

getSelectItems(), getFrom(), getWhere(), getGroupBy(), getOrderBy(), getHaving() return the respective parts of the parse tree as a DBIx::MyParsePP::Rule object. Depending on the query, the part of the tree that is being returned may look differently, e.g. getFrom() will return widely different things depending on how many tables are in the FROM clause, whether there are joins or subqueries. You can then use shrink() and extract() on the return value to further narrow down on the part of the query you are interested in.