📄 soapcpp2_lex.l
字号:
/*soapcpp2_lex.lFlex/Lex tokenizer.gSOAP XML Web services toolsCopyright (C) 2000-2007, Robert van Engelen, Genivia Inc. All Rights Reserved.This part of the software is released under one of the following licenses:GPL, the gSOAP public license, or Genivia's license for commercial use.--------------------------------------------------------------------------------gSOAP public license.The contents of this file are subject to the gSOAP Public License Version 1.3(the "License"); you may not use this file except in compliance with theLicense. You may obtain a copy of the License athttp://www.cs.fsu.edu/~engelen/soaplicense.htmlSoftware distributed under the License is distributed on an "AS IS" basis,WITHOUT WARRANTY OF ANY KIND, either express or implied. See the Licensefor the specific language governing rights and limitations under the License.The Initial Developer of the Original Code is Robert A. van Engelen.Copyright (C) 2000-2007 Robert A. van Engelen, Genivia inc. All Rights Reserved.--------------------------------------------------------------------------------GPL license.This program is free software; you can redistribute it and/or modify it underthe terms of the GNU General Public License as published by the Free SoftwareFoundation; either version 2 of the License, or (at your option) any laterversion.This program is distributed in the hope that it will be useful, but WITHOUT ANYWARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR APARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along withthis program; if not, write to the Free Software Foundation, Inc., 59 TemplePlace, Suite 330, Boston, MA 02111-1307 USAAuthor contact information:engelen@genivia.com / engelen@acm.org--------------------------------------------------------------------------------A commercial use license is available from Genivia, Inc., contact@genivia.com--------------------------------------------------------------------------------*/%{#include "soapcpp2.h"#ifdef HAVE_CONFIG_H#include "soapcpp2_yacc.h"#else#include "soapcpp2_yacc.tab.h"#endif#ifdef WITH_BISONYYSTYPE yylval;#undef YY_INPUT#define YY_INPUT(buf, result, max_size) \ { \ int c = getc(yyin); \ result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \ }#endif#ifndef WITH_LEX#define MAX_IMPORT_DEPTH 16static struct importlist { struct importlist *next; char name[1]; } *importlist = NULL;static char fnstk[MAX_IMPORT_DEPTH][1024];static int lnstk[MAX_IMPORT_DEPTH];static char *imstk[MAX_IMPORT_DEPTH];static YY_BUFFER_STATE instk[MAX_IMPORT_DEPTH];#endifint imports = 0;char *imported = NULL;static Token install_id();static Token install_int();static Token install_hex();static Token install_num();static Token install_chr();static Token install_str();static Token install_pragma();static void directive(), option();static Token error_chr();static Token error_str();static int convchar(int*);static int hexchar(int*);static int octchar(int*);static void module(const char *name, const char *fullname);static void import(const char *file);static int magic(const char *name);%}ws [ \t\v\n\f\r\x1A\xA0]digit [0-9]alpha [a-zA-Z_]id {alpha}({alpha}|{digit}|::|:{alpha})*int {digit}+hex 0[xX][0-9a-fA-F]+num {int}(\.{int}([Ee][+-]?{int})?|(\.{int})?[Ee][+-]?{int})chr '(\\'|[^'\n])*'str \"(\\\"|\\\n|[^"])*\"module #module{ws}+.*\nimport #import{ws}+.*\n%x MLCOMMENT%%{ws} { /* skip white space */ }"/*" { BEGIN(MLCOMMENT); }<MLCOMMENT>.|\n { }<MLCOMMENT>"*/" { BEGIN(INITIAL); }<MLCOMMENT><<EOF>> { execerror("Unclosed multiline comment at the end of file"); }"//gsoapopt".*\n { option(); }"//gsoap".*\n { directive(); }"//".*\n { /* skip single line comment */ }"+=" { return PA; }"-=" { return NA; }"*=" { return TA; }"/=" { return DA; }"%=" { return MA; }"&=" { return AA; }"^=" { return XA; }"|=" { return OA; }"<<=" { return LA; }">>=" { return RA; }"||" { return OR; }"&&" { return AN; }"==" { return EQ; }"!=" { return NE; }"<=" { return LE; }">=" { return GE; }"<<" { return LS; }">>" { return RS; }"++" { return PP; }"--" { return NN; }"->" { return AR; }[;,:=|^&<>+\-*/%!?~(){}\[\].@] { return yytext[0]; }{id} { return install_id(); }{int} { return install_int(); }{hex} { return install_hex(); }{num} { return install_num(); }{chr} { return install_chr(); }{str} { return install_str(); }{module} { char *s, *t, buf[1024]; s = strchr(yytext, '"'); strcpy(buf, s+1); s = strchr(buf, '"'); *s = '\0'; t = strchr(s+1, '"'); if (t) { t++; s = strchr(t+1, '"'); *s = '\0'; } module(buf, t); }{import} { char *s, buf[1024]; s = strchr(yytext, '"'); strcpy(buf, s+1); s = strchr(buf, '"'); *s = '\0'; import(buf); }#.*\n { return install_pragma(); }'[^'\n]*/\n { return error_chr(); }\"[^"\n]*/\n { return error_str(); }. { lexerror("Skipping unknown symbol"); }<<EOF>> { /* when Lex complains: remove this line and below */#ifndef WITH_LEX if (--imports < 0) yyterminate(); else { yy_delete_buffer(YY_CURRENT_BUFFER); yy_switch_to_buffer(instk[imports]); strcpy(filename, fnstk[imports]); yylineno = lnstk[imports]; imported = imstk[imports]; }#endif }%%/* install_id - lookup identifier in symbol table. If found, return token and symbol table entry. If not found, create entry in symbol table and return ID token.*/ static Tokeninstall_id(){ Symbol *p = lookup(yytext); if (!p) p = install(yytext, ID); yylval.sym = p; return p->token;}/* install_int - convert digits to integer and return LNG token.*/static Tokeninstall_int(){ sscanf(yytext, SOAP_ULONG_FORMAT, &yylval.i); return LNG;}/* install_hex - convert hexadecimal digits to integer and return LNG*/static Tokeninstall_hex(){ sscanf(yytext, SOAP_XLONG_FORMAT, &yylval.i); return LNG;}/* install_num - convert digits to floating point number and return DBL*/static Tokeninstall_num(){ sscanf(yytext, "%lf", &yylval.r); return DBL;}/* install_chr - convert character constant and return CHR.*/static Tokeninstall_chr(){ int i = 2; if (yytext[1] == '\\') yylval.c = convchar(&i); else yylval.c = yytext[i-1]; if (yytext[i] != '\'') lexerror("Illegal character constant"); return CHR;}/* install_str - convert and store string in memory. Return STR.*/static Tokeninstall_str(){ int i, j = 0; yylval.s = emalloc(yyleng-1); /* yyleng = length(yytext) */ for (i = 1; i < yyleng-1; i++) if (yytext[i] == '\\') { if (yytext[++i] != '\n') { yylval.s[j++] = convchar(&i); i--; } } else yylval.s[j++] = yytext[i]; yylval.s[j] = '\0'; return STR;}/* install_pragma - store pragma in string. Return PRAGMA.*/static Tokeninstall_pragma(){ yylval.s = emalloc(yyleng); /* yyleng = length(yytext) */ strncpy(yylval.s, yytext, strlen(yytext)-1); yylval.s[strlen(yytext)-1] = '\0'; return PRAGMA;}static void directive(){ int i, j, k; char *s; Service *sp; Method *m; Data *d; int service; for (i = 7; yytext[i]; i++) if (yytext[i] > 32) break; for (j = i; yytext[j]; j++) if (yytext[j] <= 32) break; if (i == j) return; s = (char*)emalloc(j-i+1); for (k = 0; k < j-i; k++) { s[k] = yytext[k+i]; if (s[k] == '_') s[k] = '-'; } s[k] = '\0'; for (sp = services; sp; sp = sp->next) if (!strcmp(sp->ns, s)) break; if (!sp) { sp = (Service*)emalloc(sizeof(Service)); sp->next = services; sp->ns = s; sp->name = NULL; sp->porttype = NULL; sp->portname = NULL; sp->binding = NULL; sp->definitions = NULL; sp->transport = NULL; sp->URL = NULL; sp->URI = NULL; sp->WSDL = NULL; sp->style = NULL; sp->encoding = NULL; sp->elementForm = NULL; sp->attributeForm = NULL; sp->executable = NULL; sp->import = NULL; sp->documentation = NULL; sp->list = NULL; sp->data = NULL; services = sp; } for (i = j; yytext[i]; i++) if (yytext[i] > 32) break; if (!strncmp(yytext+i, "service", 7) || !strncmp(yytext+i, "schema", 6)) { service = strncmp(yytext+i, "schema", 6); for (i += 7; yytext[i]; i++) if (yytext[i] > 32) break; for (j = i; yytext[j]; j++) if (yytext[j] <= 32) break; for (; yytext[j]; j++) if (yytext[j] > 32) break; for (k = j; yytext[k]; k++) if (yytext[k] <= 32) break; /* if (j == k) return; */ s = (char*)emalloc(k-j+1); strncpy(s, yytext+j, k-j); s[k-j] = '\0'; if (!strncmp(yytext+i, "name:", 5)) { sp->name = s; for (j = k; yytext[j]; j++) if (yytext[j] > 32) break; for (k = j; yytext[k]; k++) if (yytext[k] == 10 || yytext[k] == 13) break; if (j == k) return; s = (char*)emalloc(k-j+1); strncpy(s, yytext+j, k-j); s[k-j] = '\0'; sp->documentation = s; } else if (!strncmp(yytext+i, "type:", 5)) sp->porttype = s; else if (!strncmp(yytext+i, "portType:", 9)) sp->porttype = s; else if (!strncmp(yytext+i, "portName:", 9)) sp->portname = s; else if (!strncmp(yytext+i, "binding:", 8)) sp->binding = s; else if (!strncmp(yytext+i, "definitions:", 12)) sp->definitions = s; else if (!strncmp(yytext+i, "documentation:", 14)) { for (k = j; yytext[k]; k++) if (yytext[k] == 10 || yytext[k] == 13) break; if (j == k) return; s = (char*)emalloc(k-j+1); strncpy(s, yytext+j, k-j); s[k-j] = '\0'; sp->documentation = s; } else if (!strncmp(yytext+i, "transport:", 10)) sp->transport = s; else if (!strncmp(yytext+i, "location:", 9) || !strncmp(yytext+i, "port:", 5)) { sp->URL = s; if (!service) sp->import = s; } else if (!strncmp(yytext+i, "executable:", 11)) sp->executable = s; else if (!strncmp(yytext+i, "namespace:", 10)) { if (service) { if (!sp->URI) sp->URI = s; sp->WSDL = s; } else if (!strcmp(sp->ns, "SOAP-ENV")) sp->URI = envURI = s; else if (!strcmp(sp->ns, "SOAP-ENC")) sp->URI = encURI = s; else sp->URI = s; } else if (!strncmp(yytext+i, "form:", 5)) { sp->elementForm = s; sp->attributeForm = s; } else if (!strncmp(yytext+i, "elementForm:", 12)) sp->elementForm = s; else if (!strncmp(yytext+i, "attributeForm:", 14)) sp->attributeForm = s; else if (!strncmp(yytext+i, "import:", 7)) { if (!sp->URI) sp->URI = s; sp->import = s; } else if (!strncmp(yytext+i, "encoding:", 9)) { if (!strcmp(s, "encoded")) sp->encoding = ""; else sp->encoding = s; } else if (!strncmp(yytext+i, "style:", 6)) sp->style = s; else if (!strncmp(yytext+i, "method-style:", 13)) { m = (Method*)emalloc(sizeof(Method)); m->name = s; m->mess = STYLE; m->part = NULL; m->next = sp->list; sp->list = m; for (j = k; yytext[j]; j++) if (yytext[j] > 32) break; for (k = j; yytext[k]; k++) if (yytext[k] == 10 || yytext[k] == 13) break; if (j == k) return; s = (char*)emalloc(k-j+1); strncpy(s, yytext+j, k-j); s[k-j] = '\0'; m->part = s; } else if (!strncmp(yytext+i, "method-encoding:", 16)) { m = (Method*)emalloc(sizeof(Method)); m->name = s; m->mess = ENCODING; m->part = NULL; m->next = sp->list; sp->list = m; for (j = k; yytext[j]; j++) if (yytext[j] > 32) break; for (k = j; yytext[k]; k++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -