Noah Petherbridge > Chatbot-Alpha-2.05 > Chatbot::Alpha::Syntax

Download:
Chatbot-Alpha-2.05.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.4   Source  

NAME ^

Chatbot::Alpha::Syntax - Syntax checking for Chatbot::Alpha replies.

SYNOPSIS ^

  use Chatbot::Alpha::Syntax;
  
  my $syntax = new Chatbot::Alpha::Syntax;
  
  # Set 'strict' syntax.
  $syntax->syntax ('strict');
  
  # Changed my mind, use 'loose'
  $syntax->syntax ('loose');
  
  # Only allow SOME commands.
  $syntax->deny_type ('allow_some');
  
  # Allow only +'s and -'s.
  $syntax->allow ('+', '-');
  
  # Syntax-check this file.
  $syntax->check ("replies.cba");

DESCRIPTION ^

Chatbot::Alpha::Syntax provides syntax checking for Alpha documents. All syntax errors result in a 'die' so don't expect to run your syntax checking halfway through a large application's process. Doing it in initialization is always fine though.

METHODS ^

new (ARGUMENTS)

Creates a new Chatbot::Alpha::Syntax object. You can pass in any defaults here.

syntax (TYPE)

Define a syntax type, either 'strict' or 'loose'. Defaults to strict. See below for definitions on the various syntax types.

deny_type (DENYTYPE)

Must be 'deny_all', 'deny_some', 'allow_some', or 'allow_all' - defaults to 'allow_all'. If you're going to want to deny/allow certain commands, it's best to use deny_type to set this. The automatic settings of deny() and allow() may not always end up how you want them.

deny (COMMANDS)

Denies a list of COMMANDS. These are the Alpha commands (+, -, @, &, etc). Syntax errors will arrise when these commands are found in the Alpha document.

allow (COMMANDS)

Adds COMMANDS to the allow list.

check (FILE)

Check the syntax of FILE. Will return 0 if the file couldn't be opened, return 1 if everything went well, or die if a syntax error is found.

SYNTAX TYPES ^

Syntax types mostly only refer to the +TRIGGER command, as that's the part of your code that's put through a regexp.

strict

This is the default (and most recommended) syntax type. The rules are as follows:

  - Triggers must be lowercase, numbers and letters only.
  - Spaces are allowed. All other symbols are NOT allowed.

loose

This one is less strict on your trigger syntax. The recommended rules are as follows:

  - Triggers can be capitilized, lowercase, or any combination.
  - Triggers can contain letters or numbers or spaces.
  - Any foreign symbols aren't recommended, however it won't kill you.

The loose syntax check will only 'warn' when one of these isn't true, but it won't hold it against you.

ALPHA SYNTAX ^

Here is the proper syntax of each Alpha command.

+TRIGGER

See SYNTAX TYPES.

~REGEXP

No syntax rules have been applied to these. Just make sure your regexp triggers are friendly.

-RESPONSE

A value of any length must be given. A response of all spaces is bad.

>LABEL

Two arguments must be given, separated by spaces: the label type, and its one-word value.

<LABEL

One argument given.

@REDIRECT

Follows the same rules as +TRIGGER

&HOLDER

Follows the same rules as -RESPONSE

*CONDITION

Must follow this syntax exactly:

  * ___=___::___
    ^var  ^val ^response

#CODE

Must have a length to it.

KNOWN BUGS ^

No bugs known at the moment.

CHANGES ^

  Version 0.2
  - Fixed some bugs, blank lines shouldn't ever be considered commands,
    and incase of unknown command anyway only a warn is used but not a
    die.

  Version 0.1
  - Initial release.

FUTURE PLANS ^

  - Add methods for defining your own syntax, for example if you make
    a custom mod to Chatbot::Alpha to add new commands, the syntax
    checker would know what to do with them.

SEE ALSO ^

Chatbot::Alpha

AUTHOR ^

Casey Kirsle, http://www.cuvou.com/

COPYRIGHT AND LICENSE ^

    Chatbot::Alpha - A simple chatterbot brain.
    Copyright (C) 2005  Casey Kirsle

    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 of the License, or
    (at your option) any later version.

    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, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
syntax highlighting: