recognize the and/not/or keywords and operator names
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7745 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
8f8f465f3e
commit
dbc13bb676
2 changed files with 46 additions and 6 deletions
|
|
@ -32,8 +32,8 @@ see bottom for a set of possible tests
|
|||
%rename(LessThanEqual) operator <=;
|
||||
%rename(GreaterThan) operator >;
|
||||
%rename(GreaterThanEqual) operator >=;
|
||||
%rename(And) operator &&;
|
||||
%rename(Or) operator ||;
|
||||
%rename(And) operator and;
|
||||
%rename(Or) operator or;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
|
|
@ -45,6 +45,10 @@ public:
|
|||
{}
|
||||
Op(const Op& o):i(o.i)
|
||||
{}
|
||||
|
||||
friend Op operator and(const Op& a,const Op& b){return Op(a.i&&b.i);}
|
||||
friend Op operator or(const Op& a,const Op& b){return Op(a.i||b.i);}
|
||||
|
||||
Op &operator=(const Op& o) {
|
||||
i=o.i;
|
||||
return *this;
|
||||
|
|
@ -63,12 +67,10 @@ public:
|
|||
friend Op operator/(const Op& a,const Op& b){return Op(a.i/b.i);}
|
||||
friend Op operator%(const Op& a,const Op& b){return Op(a.i%b.i);}
|
||||
|
||||
friend Op operator&&(const Op& a,const Op& b){return Op(a.i&&b.i);}
|
||||
friend Op operator||(const Op& a,const Op& b){return Op(a.i||b.i);}
|
||||
|
||||
// unary operators
|
||||
Op operator-() const {return Op(-i);}
|
||||
bool operator!() const {return !(i);}
|
||||
bool operator !() const {return !(i);}
|
||||
|
||||
// overloading the [] operator
|
||||
// need 2 versions: get & set
|
||||
|
|
|
|||
|
|
@ -1021,6 +1021,31 @@ void scanner_next_token(int tok) {
|
|||
* Gets the lexene and returns tokens.
|
||||
*************************************************************/
|
||||
|
||||
static int search_name(char c, const char* ostr)
|
||||
{
|
||||
int count = 0;
|
||||
int find = 0;
|
||||
|
||||
while (ostr[count]) {
|
||||
if (c == ostr[count]) {
|
||||
c = nextchar();
|
||||
++count;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ostr[count]) {
|
||||
if (isalnum(c) || c == '_') {
|
||||
find = 0;
|
||||
} else {
|
||||
find = c;
|
||||
}
|
||||
}
|
||||
if (count) retract(count);
|
||||
return find;
|
||||
}
|
||||
|
||||
|
||||
int yylex(void) {
|
||||
|
||||
int l;
|
||||
|
|
@ -1131,6 +1156,9 @@ int yylex(void) {
|
|||
/* C++ keywords */
|
||||
|
||||
if (cparse_cplusplus) {
|
||||
if (strcmp(yytext,"and") == 0) return(LAND);
|
||||
if (strcmp(yytext,"or") == 0) return(LOR);
|
||||
if (strcmp(yytext,"not") == 0) return(LNOT);
|
||||
if (strcmp(yytext,"class") == 0) return(CLASS);
|
||||
if (strcmp(yytext,"private") == 0) return(PRIVATE);
|
||||
if (strcmp(yytext,"public") == 0) return(PUBLIC);
|
||||
|
|
@ -1151,7 +1179,17 @@ int yylex(void) {
|
|||
}
|
||||
count++;
|
||||
if (!isspace(c)) {
|
||||
if ((!state) && (isalpha(c))) isconversion = 1;
|
||||
if ((!state) && (isalpha(c))) {
|
||||
/* we look for the and/not/or operators */
|
||||
if (search_name(c, "and") ||
|
||||
search_name(c, "not") ||
|
||||
search_name(c, "or")) {
|
||||
isconversion = 0;
|
||||
} else {
|
||||
isconversion = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!state && !sticky) Putc(' ',s);
|
||||
Putc(c,s);
|
||||
sticky = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue