Chatbot::Alpha::Syntax - Syntax checking for Chatbot::Alpha replies.
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");
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.
Creates a new Chatbot::Alpha::Syntax object. You can pass in any defaults here.
Define a syntax type, either 'strict' or 'loose'. Defaults to strict. See below for definitions on the various syntax types.
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.
Denies a list of COMMANDS. These are the Alpha commands (+, -, @, &, etc). Syntax errors will arrise when these commands are found in the Alpha document.
Adds COMMANDS to the allow list.
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 mostly only refer to the +TRIGGER command, as that's the part of your code that's put through a regexp.
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.
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.
Here is the proper syntax of each Alpha command.
See SYNTAX TYPES.
No syntax rules have been applied to these. Just make sure your regexp triggers are friendly.
A value of any length must be given. A response of all spaces is bad.
Two arguments must be given, separated by spaces: the label type, and its one-word value.
One argument given.
Follows the same rules as +TRIGGER
Follows the same rules as -RESPONSE
Must follow this syntax exactly:
* ___=___::___ ^var ^val ^response
Must have a length to it.
No bugs known at the moment.
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.
- 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.
Chatbot::Alpha
Casey Kirsle, http://www.cuvou.com/
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
To install Chatbot::Alpha, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Chatbot::Alpha
CPAN shell
perl -MCPAN -e shell install Chatbot::Alpha
For more information on module installation, please visit the detailed CPAN module installation guide.