Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/corelibs/vos/parsemessage_parser.yy

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2001-2003 Peter Amstutz
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021     Peter Amstutz <amstutz@cs.umass.edu>
00022 */
00023 /* Parse basic messages in an xml-ish format */
00024      
00025 %{
00026 #define yyparse VOS::msgparse
00027 #define yylex msglex
00028 #define yyerror msgerror
00029 #define yylval msglval
00030 #define yychar msgchar
00031 #define yydebug msgdebug
00032 #define yynerrs msgnerrs
00033 
00034 #define YYSTYPE char*
00035 
00036 #include <vos/vosdefs.hh>
00037 #include <vos/parsemessage_parser.h>
00038 #include <vos/messageblock.hh>
00039 #include <vos/message.hh>
00040 
00041 #define YYERROR_VERBOSE
00042 #define YYPARSE_PARAM extra
00043 #define YYLEX_PARAM extra
00044 
00045 #undef __GNUC_MINOR__
00046 %}
00047 
00048 %token TAG
00049 %token SPACE
00050 %token QUOTESTR
00051 %token CDATA
00052 %token MESSAGEBLOCK
00053 %token COMMENT
00054 %pure_parser
00055 %% /* Grammar rules and actions follow */
00056 
00057 start: cspace messageblock  { ((parse_state_t*)extra)->done=1; }
00058      | cspace message { ((parse_state_t*)extra)->done=1; }
00059 ;
00060 
00061 messageblock: '<' MESSAGEBLOCK aspace options ospace '>' cspace messages cspace '<' '/' MESSAGEBLOCK '>'
00062             | '<' MESSAGEBLOCK aspace options ospace '>' cspace '<' '/' MESSAGEBLOCK '>'
00063             | '<' MESSAGEBLOCK '>' cspace messages cspace '<' '/' MESSAGEBLOCK '>'
00064 ;
00065 
00066 options: option
00067      | options aspace option
00068 ;
00069 
00070 option: TAG '=' '"' QUOTESTR '"' {
00071     string astr($1);
00072     if(astr == "name") {
00073         ((parse_state_t*)extra)->m->setName($4);
00074     } else if(astr == "length") {
00075         ((parse_state_t*)extra)->expected_length = abs(atoi($4));
00076     }
00077     free($1);
00078     free($4);
00079 }
00080 ;
00081 
00082 messages: message
00083         | messages cspace message
00084 ;
00085 
00086 message: begintag cspace params cspace endtag
00087        | begintag cspace endtag
00088        | begintagonly
00089 ;
00090 
00091 tagstart: '<' TAG {
00092     pREF(VOS::Message*, m, new VOS::Message(),
00093         ((parse_state_t*)extra)->m->insertMessage(-1, m);
00094         m->setType($2);
00095     );
00096     free($2);   
00097 };
00098 
00099 begintag: tagstart aspace attributes ospace '>'
00100 ;
00101 
00102 begintagonly: tagstart aspace attributes ospace '/' '>'
00103 ;
00104 
00105 endtag:  '<' '/' TAG '>' {
00106     free($3);
00107 }
00108 ;
00109 
00110 attributes: attr
00111      | attributes aspace attr
00112 ;
00113 
00114 attr: TAG '=' '"' QUOTESTR '"' {
00115     string astr($1);
00116     if(astr == "to") {
00117         pREF(VOS::Message*, m, ((parse_state_t*)extra)->m->lastMessage(), m->setTo($4));
00118     } else if(astr == "from") {
00119         pREF(VOS::Message*, m, ((parse_state_t*)extra)->m->lastMessage(), m->setFrom($4));
00120     } else if(astr == "method") {
00121         pREF(VOS::Message*, m, ((parse_state_t*)extra)->m->lastMessage(), m->setMethod($4));
00122     } else if(astr == "nonce") {
00123         pREF(VOS::Message*, m, ((parse_state_t*)extra)->m->lastMessage(), m->setNonce($4));
00124     } else if(astr == "length") {
00125          if(((parse_state_t*)extra)->expected_length == 0) 
00126             ((parse_state_t*)extra)->expected_length = abs(atoi($4));
00127     } else if(astr == "time") {
00128         float x;
00129         sscanf($4, "%f", &x);
00130         pREF(VOS::Message*, m, ((parse_state_t*)extra)->m->lastMessage(), m->setTime(x));
00131     } else if(astr == "depends") {
00132         pREF(VOS::Message*, m, ((parse_state_t*)extra)->m->lastMessage(), m->setDependency($4));
00133     }
00134     free($1);
00135     free($4);
00136 }
00137 ;
00138 
00139 aspace: SPACE | COMMENT aspace | SPACE aspace;
00140 
00141 ospace: | COMMENT ospace | SPACE ospace
00142 ;
00143 
00144 cspace: | COMMENT cspace | CDATA cspace {
00145     free($1);
00146 };
00147 
00148 params: param
00149      | params cspace param
00150 ;
00151 
00152 param: '<' TAG '>' CDATA '<' '/' TAG '>' { 
00153     if(strcmp($2, $7)==0) {
00154         pREF(VOS::Message*, m, ((parse_state_t*)extra)->m->lastMessage(), m->insertField(-1, $2, $4));
00155     }
00156     free($2);
00157     free($4);
00158     free($7);
00159 } | beginquotedparam quotedcdata endquotedparam
00160   | '<' TAG '>' '<' '/' TAG '>' { 
00161     free($2);
00162     free($6);
00163     if(strcmp($2, $6)==0) {
00164         pREF(VOS::Message*, m, ((parse_state_t*)extra)->m->lastMessage(), m->insertField(-1, $2, ""));
00165     }
00166 } | '<' TAG ospace '/' '>' {
00167     pREF(VOS::Message*, m, ((parse_state_t*)extra)->m->lastMessage(), m->insertField(-1, $2, ""));
00168     free($2);
00169 }
00170 ;
00171 
00172 beginquotedparam: '<' TAG aspace TAG '=' '"' QUOTESTR '"' ospace '>' {
00173     string astr($4);
00174 /*  cout << "in beginquotedparm!!!\n"; */
00175     if(astr == "length") {
00176         pREF(VOS::Message*, m, ((parse_state_t*)extra)->m->lastMessage(), 
00177             m->insertField(-1, $2, "");
00178             ((parse_state_t*)extra)->read_quoted = abs(atoi($7));
00179         );
00180     }
00181     free($2);
00182     free($4);
00183     free($7);
00184 }
00185 ;
00186 
00187 quotedcdata: CDATA {
00188     ((parse_state_t*)extra)->read_quoted = 0;
00189 }
00190 ;
00191 
00192 endquotedparam: '<' '/' TAG '>' 
00193 ;

Generated on Tue Aug 12 03:55:41 2003 for Interreality Project - VOS by doxygen 1.3.2