[system] / trunk / pg / macros / parserAutoStrings.pl Repository:
ViewVC logotype

View of /trunk/pg/macros/parserAutoStrings.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6058 - (download) (as text) (annotate)
Thu Jun 25 23:28:44 2009 UTC (10 years, 7 months ago) by gage
File size: 2530 byte(s)
syncing pg HEAD with pg2.4.7 on 6/25/2009

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    3 # Copyright  2000-2007 The WeBWorK Project, http://openwebwork.sf.net/
    4 # $CVSHeader$
    5 #
    6 # This program is free software; you can redistribute it and/or modify it under
    7 # the terms of either: (a) the GNU General Public License as published by the
    8 # Free Software Foundation; either version 2, or (at your option) any later
    9 # version, or (b) the "Artistic License" which comes with this package.
   10 #
   11 # This program is distributed in the hope that it will be useful, but WITHOUT
   12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   13 # FOR A PARTICULAR PURPOSE.  See either the GNU General Public License or the
   14 # Artistic License for more details.
   15 ################################################################################
   16 
   17 =head1 NAME
   18 
   19 parserAutoStrings.pl - Force String() to accept any string.
   20 
   21 =head1 DESCRIPTION
   22 
   23 This file allows you to force String() to accept ANY string as a
   24 legal value.  (It will add the string to the context if it isn't
   25 already defined.)
   26 
   27 To accomplish this, put the lines
   28 
   29   loadMacros("parserAutoStrings.pl");
   30   AutoStrings();
   31 
   32 at the beginning of your problem file.  (You can also pass AutoStrings
   33 a context pointer if you wish to alter context other than the current
   34 one.)
   35 
   36 There is also a routine to help make strings easier to predefine.
   37 For example:
   38 
   39   loadMacros("parserAutoStrings.pl");
   40   DefineStrings("string1","string2");
   41 
   42 would define two new strings (string1 and string2).  You can pass
   43 a context reference as the first argument to add strings to that
   44 context rather than the active one.
   45 
   46 =cut
   47 
   48 sub _parserAutoStrings_init {}
   49 
   50 ######################################################################
   51 
   52 sub AutoStrings {(shift || Value->context)->{value}{"String()"} = "parser::AutoStrings"};
   53 
   54 sub DefineStrings {
   55   my $context = (Value::isContext($_[0]) ? shift : Value->context);
   56   foreach my $x (@_)
   57     {$context->strings->add($x=>{}) unless defined $context->{strings}{$x}}
   58 }
   59 
   60 ######################################################################
   61 
   62 package parser::AutoStrings;
   63 our @ISA = ("Value::String");
   64 
   65 sub new {
   66   my $self = shift; my $class = ref($self) || $self;
   67   my $context = (Value::isContext($_[0]) ? shift : $self->context);
   68   my $x = join('',@_);
   69   $context->strings->add($x=>{}) unless defined $context->{strings}{$x};
   70   $self->SUPER::new($x);
   71 }
   72 
   73 ######################################################################
   74 
   75 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9