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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6773 - (download) (as text) (annotate)
Fri Apr 1 21:01:31 2011 UTC (8 years, 9 months ago) by gage
File size: 1733 byte(s)
fix one  "non numeric permision level" error  by adding default

add three new specialized macro packages  contextTypeset.pl and its supporting file parserQuotedString.pl
are used for PGML  -- the answerDiscusson.pl is a proof of concept for allowing student written feedback.


    1 package QuotedString;
    2 @ISA = qw(Parser::String);
    3 
    4 sub new {
    5   my $self = shift; my ($equation,$value,$ref) = @_;
    6   my $str = $self->SUPER::new(@_);
    7   unless ($str->{equation}{context}{strings}{$str->{value}}) {
    8     $equation->Error("Missing close quote",$ref) if $str->{value} eq '"';
    9     $str->{value} =~ s/^"(.*)"$/$1/;
   10     $str->{value} =~ s/\\"/"/g;
   11     $str->{isQuoted} = 1;
   12   }
   13   return $str;
   14 }
   15 
   16 sub string {
   17   my $self = shift; my $string = $self->SUPER::string(@_);
   18   if ($self->{isQuoted}) {
   19     $string =~ s/"/\\"/g;
   20     $string = '"'.$string.'"';
   21   }
   22   return $string
   23 }
   24 
   25 sub enable {
   26   my $context = shift;
   27   QuotedString::enableQuotes($context);
   28   QuotedString::enableAdd($context);
   29 }
   30 
   31 sub enableQuotes {
   32   my $context = shift;
   33   $context->{parser}{String} = 'QuotedString';
   34   bless $context->{_strings}, 'QuotedString::Data';
   35   $context->strings->update;
   36 }
   37 
   38 sub enableAdd {
   39   my $context = shift;
   40   $context->operators->set('+' => {class=>"QuotedString::BOP::add"});
   41 }
   42 
   43 package QuotedString::Data;
   44 @ISA = qw(Parser::Context::Strings);
   45 
   46 sub update {
   47   my $self = shift;
   48   $self->SUPER::update;
   49   $self->{patterns}{'"(?:[^\\\\]|\\\\.)*?"|"'} = [10,'str'];
   50   $self->{context}->update;
   51 }
   52 
   53 package QuotedString::BOP::add;
   54 @ISA = qw(Parser::BOP::add);
   55 
   56 sub checkStrings {
   57   my $self = shift;
   58   my $ltype = $self->{lop}->typeRef; my $rtype = $self->{rop}->typeRef;
   59   return 1 if $ltype->{name} eq 'String' && $rtype->{name} eq 'String';
   60   return $self->SUPER::checkStrings(@_);
   61 }
   62 
   63 sub _eval {
   64   my $self = shift;
   65   my $ltype = $self->{lop}->typeRef; my $rtype = $self->{rop}->typeRef;
   66   return Value::String->make($_[0] . $_[1])
   67     if $ltype->{name} eq 'String' && $rtype->{name} eq 'String';
   68   $self->SUPER::_eval(@_);
   69 }
   70 
   71 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9