From bc2c9de5e0e755612fa07963bdd027a8b2d5823f Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Sun, 4 Feb 2001 03:54:38 +0000 Subject: [PATCH] Minor scanning changes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@1016 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/LParse/cscanner.c | 7 ++++++- Source/LParse/parser.y | 3 ++- Source/Swig/scanner.c | 17 +++++++++++++++++ Source/Swig/swig.h | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Source/LParse/cscanner.c b/Source/LParse/cscanner.c index dc5f9429e..ef5015dcf 100644 --- a/Source/LParse/cscanner.c +++ b/Source/LParse/cscanner.c @@ -67,6 +67,7 @@ static int map[][2] = { { SWIG_TOKEN_DOLLAR, -1}, { SWIG_TOKEN_CODEBLOCK, HBLOCK}, { SWIG_TOKEN_ILLEGAL, SWIG_TOKEN_ILLEGAL}, + { SWIG_TOKEN_RSTRING, SWIG_TOKEN_RSTRING}, { SWIG_TOKEN_LAST, -1}, {0,0}, }; @@ -319,7 +320,7 @@ yylex1(void) { LParse_error(0,0,"Illegal character '%s'\n", text); return yylex1(); } - if ((l1 == STRING) || (l1 == CHARCONST)) { + if ((l1 == STRING) || (l1 == CHARCONST) || (l1 == SWIG_TOKEN_RSTRING)) { yylval.tok.text = NewString(yytext+1); Setfile(yylval.tok.text,yylval.tok.filename); Setline(yylval.tok.text,yylval.tok.line); @@ -328,6 +329,10 @@ yylex1(void) { if ((l1 == HBLOCK) || (l1 == NUM_INT) || (l1 == NUM_FLOAT) || (l1 == NUM_UNSIGNED) || (l1 == NUM_LONG) || (l1 == NUM_ULONG)) { yylval.tok.text = NewString(yytext); } + if (l1 == SWIG_TOKEN_RSTRING) { + return (TYPE_TYPESTRING); + } + if (l1 == ID) { /* Look for keywords now */ if (strcmp(yytext,"int") == 0) return(TYPE_INT); diff --git a/Source/LParse/parser.y b/Source/LParse/parser.y index 5264d2d3d..56b6f3711 100644 --- a/Source/LParse/parser.y +++ b/Source/LParse/parser.y @@ -234,7 +234,7 @@ static int promote(int t1, int t2) { %token OC_INTERFACE OC_END OC_PUBLIC OC_PRIVATE OC_PROTECTED OC_CLASS OC_IMPLEMENT OC_PROTOCOL /* C Types */ -%token TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL +%token TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL TYPE_TYPESTRING /* SWIG directives */ %token ADDMETHODS APPLY CLEAR CONSTANT ECHO EXCEPT SCOPE @@ -1603,6 +1603,7 @@ type : TYPE_INT { $$ = NewString("int"); } | TYPE_FLOAT { $$ = NewString("float"); } | TYPE_DOUBLE { $$ = NewString("double"); } | TYPE_VOID { $$ = NewString("void"); } + | TYPE_TYPESTRING { $$ = $1.text; } | TYPE_SIGNED opt_signed { if ($2) $$ = $2; else { diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index bb2393685..680db572d 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -295,6 +295,11 @@ look(SwigScanner *s) { s->string_start = s->line; state = 9; /* A character constant */ } + else if (c == '`') { + s->string_start = s->line; + state = 900; + } + else if (c == '.') state = 100; /* Maybe a number, maybe just a period */ else if (isdigit(c)) state = 8; /* A numerical value */ else state = 99; /* An error */ @@ -640,6 +645,18 @@ look(SwigScanner *s) { break; /* An illegal character */ + + /* Reverse string */ + case 900: + if ((c = nextchar(s)) == 0) { + /* add_error(0,"Unterminated character constant", string_start); */ + return 0; + } + if (c == '`') { + return(SWIG_TOKEN_RSTRING); + } + break; + default: return SWIG_TOKEN_ILLEGAL; } diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index f1bebc566..3012d2cc4 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -158,6 +158,7 @@ extern void SwigScanner_idstart(SwigScanner *, char *idchar); #define SWIG_TOKEN_AT 45 #define SWIG_TOKEN_DOLLAR 46 #define SWIG_TOKEN_CODEBLOCK 47 +#define SWIG_TOKEN_RSTRING 48 #define SWIG_TOKEN_ILLEGAL 98 #define SWIG_TOKEN_LAST 99