Text::Query::Parse - Base class for query parsers


Text-Query documentation Contained in the Text-Query distribution.

Index


Code Index:

NAME

Top

Text::Query::Parse - Base class for query parsers

SYNOPSIS

Top

    package Text::Query::ParseThisSyntax;

    use Text::Query::Parse;

    use vars qw(@ISA);

    @ISA = qw(Text::Query::Parse);




DESCRIPTION

Top

This module provides a virtual base class for query parsers.

It defines the prepare method that is called by the Text::Query object to compile the query string.

MEMBERS

Top

-build Pointer to a Text::Query::Build object.
scope Scope stack. Defines the context in which the query must be solved.
token The current token. Destroyed by prepare.
tokens A reference to the list of all the tokens. Filled by parse_tokens. Destroyed by prepare.
parseopts A reference to a hash table containing all the parameters given to the prepare function.
-verbose Integer indicating the desired verbose level.

METHODS

Top

prepare (QSTRING [OPTIONS])

Compiles the query expression in QSTRING to internal form and sets any options. First calls build_init to reset the builder and destroy the token and tokens members. Then calls parse_tokens to fill the tokens member. Then calls expression to use the tokens from tokens. The expression is expected to call the build_* functions to build the compiled expression. At last calls build_final_expression with the result of expression.

A derived parser must redefine this function to define default values for specific options.

expression ()

Must be redefined by derived package. Returns the internal form of the question built from build_* functions using the tokens.

parse_tokens (QSTRING)

Must be redefined by derived package. Parses the QSTRING scalar and fills the tokens member with lexical units.

build_*

Shortcuts to the corresponding function of the Text::Query::Build object found in the -build member.

OPTIONS

Top

These are the options of the prepare method and the constructor.

-quotes defaults to \'\"

Defines the quote characters.

-case defaults to 0

If true, do case-sensitive match.

-litspace defaults to 0

If true, match spaces (except between operators) in QSTRING literally. If false, match spaces as \s+.

-regexp defaults to 0

If true, treat patterns in QSTRING as regular expressions rather than literal text.

-whole defaults to 0

If true, match whole words only, not substrings of words.

SEE ALSO

Top

Text::Query(3)

AUTHORS

Top

Eric Bohlman (ebohlman@netcom.com)

Loic Dachary (loic@senga.org)


Text-Query documentation Contained in the Text-Query distribution.

#
#   Copyright (C) 1999 Eric Bohlman, Loic Dachary
#
#   This program is free software; you can redistribute it and/or modify it
#   under the terms of the GNU General Public License as published by the
#   Free Software Foundation; either version 2, or (at your option) any
#   later version.  You may also use, redistribute and/or modify it
#   under the terms of the Artistic License supplied with your Perl
#   distribution
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
#
# 
# $Header: /usr/local/cvsroot/Text-Query/lib/Text/Query/Parse.pm,v 1.3 1999/06/16 10:32:13 loic Exp $
#
package Text::Query::Parse;

use strict;

use Carp;

sub new {
  my $class=shift;
  my $self={};
  bless $self, $class;

  $self->initialize();

  return $self;
}

sub initialize {
}

sub prepare {
  my $self=shift;
  my $qstring=shift;

  @_ = ( %{$self->{parseopts}}, @_ ) if($self->{parseopts});
  $self->{parseopts} = { -regexp=>0, -litspace=>0, -case=>0, -whole=>0, -quotes=>"\\'\\\"", @_ };
  croak("no builder") if(!$self->{-build});
  $self->{-build}->{parseopts} = $self->{parseopts};

  delete($self->{'token'});
  delete($self->{'tokens'});
  $self->build_init();

  $self->parse_tokens($qstring);

  croak("no token found") if(!@{$self->{'tokens'}});

  return $self->build_final_expression($self->expression());
}

#parsing routines

sub expression($) {
    my($self) = @_;
    
    croak("not implemented");

    return "expression";
}

sub parse_tokens($) {
    my($self, $qstring) = @_;

    croak("not implemented");

    $self->{'tokens'} = [];
}

#
# Access builder functions
#

sub build_init {
    my($self) = @_;

    return $self->{-build}->build_init();
}

sub build_final_expression {
    my($self, $t1) = @_;

    return $self->{-build}->build_final_expression($t1);
}

sub build_expression {
    my($self, $l, $r) = @_;

    return $self->{-build}->build_expression($l, $r);
}

sub build_expression_finish {
    my($self, $l) = @_;

    return $self->{-build}->build_expression_finish($l);
}

sub build_conj {
    my($self, $l, $r, $first) = @_;

    return $self->{-build}->build_conj($l, $r, $first);
}

sub build_near {
    my($self, $l, $r) = @_;

    return $self->{-build}->build_near($l, $r);
}

sub build_concat {
    my($self, $l, $r) = @_;

    return $self->{-build}->build_concat($l, $r);
}

sub build_negation {
    my($self, $t) = @_;

    return $self->{-build}->build_negation($t);
}

sub build_literal {
    my($self, $t) = @_;

    return $self->{-build}->build_literal($t);
}

sub build_scope_start {
    my($self) = @_;

    return $self->{-build}->build_scope_start($self->{scope});
}

sub build_scope_end {
    my($self, $t) = @_;

    return $self->{-build}->build_scope_end($self->{scope}, $t);
}

sub build_mandatory {
    my($self, $t) = @_;

    return $self->{-build}->build_mandatory($t);
}

sub build_forbiden {
    my($self, $t) = @_;

    return $self->{-build}->build_forbiden($t);
}

1;

__END__

# Local Variables: ***
# mode: perl ***
# End: ***